当前位置: 首页>>代码示例>>Java>>正文


Java Set类代码示例

本文整理汇总了Java中io.vavr.collection.Set的典型用法代码示例。如果您正苦于以下问题:Java Set类的具体用法?Java Set怎么用?Java Set使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Set类属于io.vavr.collection包,在下文中一共展示了Set类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseSpecItem

import io.vavr.collection.Set; //导入依赖的package包/类
static Validation<String, Set<Integer>> parseSpecItem(
    String value, int maxValue, Map<String, Integer> stringMap) {
    if (value.contains(",")) {
        Set<Validation<String, Set<Integer>>> parsedList = HashSet.of(value.split(","))
            .map(v -> parseSpecItem(v, maxValue, stringMap));
        return Vavr.sequenceS(parsedList)
            .map(s -> s.flatMap(Function1.identity()).toSet());
    } else if (value.equals("*")) {
        return Validation.valid(HashSet.empty());
    } else if (value.contains("/")) {
        return parseSlash(value, maxValue);
    } else if (value.contains("-")) {
        return parseRange(value)
            .map(p -> HashSet.rangeClosed(p._1, p._2));
    } else if (stringMap.containsKey(value)) {
        return Validation.valid(HashSet.of(stringMap.get(value).get()));
    }
    return Vavr.validationParseInt(value).map(HashSet::of);
}
 
开发者ID:emmanueltouzery,项目名称:crony,代码行数:20,代码来源:SpecItemParser.java

示例2: build

import io.vavr.collection.Set; //导入依赖的package包/类
/**
 * Build a {@link MinSpec} from the list of minutes of the hour
 * that it matches.
 * @param minutes Accepted minutes of the hour (0-59), or empty set for 'accept all'
 * @return a new {@link MinSpec} or an error message.
 */
public static Validation<String, MinSpec> build(Set<Integer> minutes) {
    if (minutes.exists(m -> m < 0 || m > 59)) {
        return Validation.invalid("Some minutes are out of range");
    }
    return Validation.valid(new MinSpec(minutes));
}
 
开发者ID:emmanueltouzery,项目名称:crony,代码行数:13,代码来源:MinSpec.java

示例3: execute

import io.vavr.collection.Set; //导入依赖的package包/类
@Override
public RedisToken execute(Database db, Request request) {
  List<SafeString> removed = new LinkedList<>();
  db.merge(safeKey(request.getParam(0)), DatabaseValue.EMPTY_SET,
      (oldValue, newValue) -> {
        Set<SafeString> oldSet = oldValue.getSet();
        SafeString item = getRandomItem(oldSet.toArray());
        removed.add(item);
        return set(oldSet.remove(item));
      });
  if (removed.isEmpty()) {
    return nullString();
  } else {
    return string(removed.get(0));
  }
}
 
开发者ID:tonivade,项目名称:claudb,代码行数:17,代码来源:SetPopCommand.java

示例4: convertValue

import io.vavr.collection.Set; //导入依赖的package包/类
static RedisToken convertValue(DatabaseValue value) {
  if (value != null) {
    switch (value.getType()) {
    case STRING:
        SafeString string = value.getString();
        return RedisToken.string(string);
    case HASH:
        Map<SafeString, SafeString> map = value.getHash();
        return array(keyValueList(map).toJavaList());
    case LIST:
        List<SafeString> list = value.getList();
        return convertArray(list.toJavaList());
    case SET:
        Set<SafeString> set = value.getSet();
        return convertArray(set.toJavaList());
    case ZSET:
        NavigableSet<Entry<Double, SafeString>> zset = value.getSortedSet();
        return convertArray(serialize(zset));
    default:
      break;
    }
  }
  return RedisToken.nullString();
}
 
开发者ID:tonivade,项目名称:claudb,代码行数:25,代码来源:DBResponse.java

示例5: test7

import io.vavr.collection.Set; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void test7() throws IOException {
    Either<List<Integer>, Set<Double>> either = Either.left(List.of(42));
    String json = mapper().writer().writeValueAsString(either);
    Either<List<Integer>, Set<Double>> restored = mapper().readValue(json, new TypeReference<Either<List<Integer>, Set<Double>>>() {});
    Assert.assertEquals(either, restored);
}
 
开发者ID:vavr-io,项目名称:vavr-jackson,代码行数:9,代码来源:EitherTest.java

示例6: apply

import io.vavr.collection.Set; //导入依赖的package包/类
/**
 * Returns a new ACL with the given change applied.
 */
public ACL<R,C> apply(C change) {
    for (UUID target: builder.getTargetId(change)) {
        Map<R,Set<UUID>> entries = this.entries;
        for (R granted: builder.getGranted(change)) {
            entries = entries.put(granted, entries.getOrElse(Tuple.of(granted, HashSet.empty()))._2.add(target));
        }
        for (R revoked: builder.getRevoked(change)) {
            entries = entries.put(revoked, entries.getOrElse(Tuple.of(revoked, HashSet.empty()))._2.remove(target));
        }
        return (entries.eq(this.entries)) ? this : new ACL<>(builder, entries);
    }
    
    return this;
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:18,代码来源:ACL.java

示例7: deal

import io.vavr.collection.Set; //导入依赖的package包/类
public Tuple2<Set<Card>, ? extends List<Card>> deal(List<Card> stack, int count)
{
    Set<Card> hand = HashSet.empty();
    for (int i = 0; i < count; i++)
    {
        Tuple2<Card, ? extends List<Card>> cardTuple2 = stack.pop2();
        stack = cardTuple2._2();
        hand = hand.add(cardTuple2._1());
    }
    return Tuple.of(hand, stack);
}
 
开发者ID:BNYMellon,项目名称:CodeKatas,代码行数:12,代码来源:VavrDeckOfCardsAsSortedSet.java

示例8: dealHands

import io.vavr.collection.Set; //导入依赖的package包/类
public List<Set<Card>> dealHands(
        List<Card> shuffled,
        int hands,
        int cardsPerHand)
{
    // TODO Deal the number of hands with the cardsPerHand into an "immutable" List<Set<Card>>
    // Remember: List above is immutable
    return null;
}
 
开发者ID:BNYMellon,项目名称:CodeKatas,代码行数:10,代码来源:VavrDeckOfCardsAsSortedSet.java

示例9: dealHands

import io.vavr.collection.Set; //导入依赖的package包/类
public List<Set<Card>> dealHands(
        List<Card> shuffled,
        int hands,
        int cardsPerHand)
{
    // Deal the number of hands with the cardsPerHand into an Immutable List<Set<Card>>
    return null;
}
 
开发者ID:BNYMellon,项目名称:CodeKatas,代码行数:9,代码来源:VavrDeckOfCardsAsList.java

示例10: build

import io.vavr.collection.Set; //导入依赖的package包/类
/**
 * Build a {@link HourSpec} from the list of hours of the day
 * that it matches.
 * @param hours Accepted hours of the day (0-23), or empty set for 'accept all'
 * @return a new {@link HourSpec} or an error message.
 */
public static Validation<String, HourSpec> build(Set<Integer> hours) {
    if (hours.exists(m -> m < 0 || m > 23)) {
        return Validation.invalid("Invalid hour");
    }
    return Validation.valid(new HourSpec(hours));
}
 
开发者ID:emmanueltouzery,项目名称:crony,代码行数:13,代码来源:HourSpec.java

示例11: build

import io.vavr.collection.Set; //导入依赖的package包/类
/**
 * Programmatically reate a Cron specification.
 * @param minutes minutes of the hour (0-59)
 * @param hours hours of the day (0-23)
 * @param daysOfMonth the days of the month (1-31). To specify the
 *        last day of the month, use {@link DayOfMonthSpec#LAST_DAY_OF_MONTH}
 * @param months months of the year
 * @param daysOfWeek the days of the week
 * @return a Cron object or an error message
 */
public static Validation<String, Cron> build(
    Set<Integer> minutes, Set<Integer> hours,
    Set<Integer> daysOfMonth, Set<Month> months,
    Set<DayOfWeek> daysOfWeek) {
    return Validation.combine(
        MinSpec.build(minutes),
        HourSpec.build(hours),
        DayOfMonthSpec.build(daysOfMonth),
        MonthSpec.build(months),
        DayOfWeekSpec.build(daysOfWeek))
        .ap(Cron::new).mapError(l -> l.mkString(", "));
}
 
开发者ID:emmanueltouzery,项目名称:crony,代码行数:23,代码来源:Cron.java

示例12: getRights

import io.vavr.collection.Set; //导入依赖的package包/类
/**
 * Returns all rights that a certain user, being a member of certain groups, has.
 * If the user (or one of its groups) has the special "admin" right, this function always returns the complete set of rights.
 * @param user The user to check
 * @param userGroups Groups the user is in (in protobuf format, since that's typically where clustered apps will maintain them)
 * @return all rights that the user, and all of its groups, have
 */
public Set<R> getRights(UUID userId, List<com.tradeshift.reaktive.protobuf.Types.UUID> userGroups) {
    Set<R> set = HashSet.empty();
    for (R right: rightsType.getEnumConstants()) {
        if (isGranted(userId, userGroups, right)) {
            set = set.add(right);
        }
    }
    return set;
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:17,代码来源:GroupedUserACL.java

示例13: demo

import io.vavr.collection.Set; //导入依赖的package包/类
@Test
public void demo() {

    // Type-safe column identifiers
    final StringColumnId NAME = StringColumnId.of("Name");
    final CategoryColumnId COLOR = CategoryColumnId.of("Color");
    final DoubleColumnId SERVING_SIZE = DoubleColumnId.of("Serving Size (g)");

    // Convenient column creation
    StringColumn nameColumn = StringColumn.ofAll(NAME, "Banana", "Blueberry", "Lemon", "Apple");
    CategoryColumn colorColumn = CategoryColumn.ofAll(COLOR, "Yellow", "Blue", "Yellow", "Green");
    DoubleColumn servingSizeColumn = DoubleColumn.ofAll(SERVING_SIZE, 118, 148, 83, 182);

    // Grouping columns into a data frame
    DataFrame dataFrame = DataFrame.ofAll(nameColumn, colorColumn, servingSizeColumn);

    // Typed random access to individual values (based on rowIndex / columnId)
    String lemon = dataFrame.getValueAt(2, NAME);
    double appleServingSize = dataFrame.getValueAt(3, SERVING_SIZE);

    // Typed stream-based access to all values
    DoubleStream servingSizes = servingSizeColumn.valueStream();
    double maxServingSize = servingSizes.summaryStatistics().getMax();

    // Smart column implementations
    Set<String> colors = colorColumn.getCategories();

}
 
开发者ID:netzwerg,项目名称:paleo,代码行数:29,代码来源:ReadmeTest.java

示例14: keySet

import io.vavr.collection.Set; //导入依赖的package包/类
@Override
public Set<DatabaseKey> keySet() {
  HashSet<DatabaseKey> keys = new HashSet<>();
  try (CloseableIterator<DatabaseKey> iterator = cache.keyIterator()) {
    while(iterator.hasNext()) {
      keys.add(iterator.next());
    }
  } catch(IOException e) {
    throw new UncheckedIOException(e);
  }
  return io.vavr.collection.HashSet.ofAll(keys);
}
 
开发者ID:tonivade,项目名称:claudb,代码行数:13,代码来源:OffHeapDatabase.java

示例15: size

import io.vavr.collection.Set; //导入依赖的package包/类
public int size() {
  return Match(value).of(Case($(instanceOf(Set.class)), Set::size),
                         Case($(instanceOf(List.class)), List::size),
                         Case($(instanceOf(Collection.class)), Collection::size),
                         Case($(instanceOf(Map.class)), Map::size),
                         Case($(instanceOf(SafeString.class)), 1),
                         Case($(), other -> 0));
}
 
开发者ID:tonivade,项目名称:claudb,代码行数:9,代码来源:DatabaseValue.java


注:本文中的io.vavr.collection.Set类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。