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


Java HashSet类代码示例

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


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

示例1: parseSpecItem

import io.vavr.collection.HashSet; //导入依赖的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: tailRec

import io.vavr.collection.HashSet; //导入依赖的package包/类
public static  <T,R> HashSet<R> tailRec(T initial, Function<? super T, ? extends HashSet<? extends io.vavr.control.Either<T, R>>> fn) {
    HashSet<io.vavr.control.Either<T, R>> next = HashSet.of(io.vavr.control.Either.left(initial));

    boolean newValue[] = {true};
    for(;;){

        next = next.flatMap(e -> e.fold(s -> {
                    newValue[0]=true;
                    return fn.apply(s); },
                p -> {
                    newValue[0]=false;
                    return HashSet.of(e);
                }));
        if(!newValue[0])
            break;

    }

    return next.filter(io.vavr.control.Either::isRight).map(io.vavr.control.Either::get);
}
 
开发者ID:aol,项目名称:cyclops,代码行数:21,代码来源:HashSets.java

示例3: tailRecEither

import io.vavr.collection.HashSet; //导入依赖的package包/类
public static  <T,R> HashSet<R> tailRecEither(T initial, Function<? super T, ? extends HashSet<? extends Either<T, R>>> fn) {
    HashSet<Either<T, R>> next = HashSet.of(Either.left(initial));

    boolean newValue[] = {true};
    for(;;){

        next = next.flatMap(e -> e.visit(s -> {
                    newValue[0]=true;
                    return fn.apply(s); },
                p -> {
                    newValue[0]=false;
                    return HashSet.of(e);
                }));
        if(!newValue[0])
            break;

    }

    return next.filter(Either::isRight).map(e->e.orElse(null));
}
 
开发者ID:aol,项目名称:cyclops,代码行数:21,代码来源:HashSets.java

示例4: traverse

import io.vavr.collection.HashSet; //导入依赖的package包/类
/**
 * @return Type class for traversables with traverse / sequence operations
 */
public static <C2,T> Traverse<hashSet> traverse(){
    BiFunction<Applicative<C2>,HashSetKind<Higher<C2, T>>,Higher<C2, HashSetKind<T>>> sequenceFn = (ap, set) -> {

        Higher<C2,HashSetKind<T>> identity = ap.unit(widen(HashSet.empty()));

        BiFunction<Higher<C2,HashSetKind<T>>,Higher<C2,T>,Higher<C2,HashSetKind<T>>> combineToSet =   (acc, next) -> ap.apBiFn(ap.unit((a, b) -> concat(a, HashSetKind.just(b))),acc,next);

        BinaryOperator<Higher<C2,HashSetKind<T>>> combineSets = (a, b)-> ap.apBiFn(ap.unit((l1, l2)-> { return concat(l1,l2);}),a,b); ;

        return ReactiveSeq.fromIterable(set).reduce(identity,
                combineToSet,
                combineSets);


    };
    BiFunction<Applicative<C2>,Higher<hashSet,Higher<C2, T>>,Higher<C2, Higher<hashSet,T>>> sequenceNarrow  =
            (a,b) -> HashSetKind.widen2(sequenceFn.apply(a, HashSetKind.narrowK(b)));
    return General.traverse(zippingApplicative(), sequenceNarrow);
}
 
开发者ID:aol,项目名称:cyclops,代码行数:23,代码来源:HashSets.java

示例5: deal

import io.vavr.collection.HashSet; //导入依赖的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

示例6: simpleFormat

import io.vavr.collection.HashSet; //导入依赖的package包/类
@Test
public void simpleFormat() {
    Validation<String, Cron> cronV = Cron.build(
        HashSet.empty(),
        HashSet.of(1,2),
        HashSet.of(1, DayOfMonthSpec.LAST_DAY_OF_MONTH),
        HashSet.of(Month.JANUARY,Month.MARCH),
        HashSet.of(DayOfWeek.MONDAY, DayOfWeek.SUNDAY));
    assertTrue(cronV.isValid());
    assertEquals("* 1,2 L,1 1,3 1,7", cronV.get().toCronString());
}
 
开发者ID:emmanueltouzery,项目名称:crony,代码行数:12,代码来源:FormatTest.java

示例7: parseSimplePattern

import io.vavr.collection.HashSet; //导入依赖的package包/类
@Test
public void parseSimplePattern() {
    Validation<String, Cron> parsed = Cron.parseCronString("0 8 * * 1");
    assertTrueS(() -> parsed.getError(), parsed.isValid());
    assertEquals(HashSet.of(0), parsed.get().minSpec.minutes);
    assertEquals(HashSet.of(8), parsed.get().hourSpec.hours);
    assertEquals(HashSet.empty(), parsed.get().dayOfMonthSpec.monthDays);
    assertEquals(HashSet.empty(), parsed.get().monthSpec.months);
    assertEquals(HashSet.of(DayOfWeek.MONDAY), parsed.get().dayOfWeekSpec.days);
}
 
开发者ID:emmanueltouzery,项目名称:crony,代码行数:11,代码来源:ParseTest.java

示例8: parseMixedPattern

import io.vavr.collection.HashSet; //导入依赖的package包/类
@Test
public void parseMixedPattern() {
    Validation<String, Cron> parsed = Cron.parseCronString("*/15 3,5,8 1,12 6 3-5");
    assertTrueS(() -> parsed.getError(), parsed.isValid());
    assertEquals(HashSet.of(0, 15, 30, 45), parsed.get().minSpec.minutes);
    assertEquals(HashSet.of(3, 5, 8), parsed.get().hourSpec.hours);
    assertEquals(HashSet.of(1, 12), parsed.get().dayOfMonthSpec.monthDays);
    assertEquals(HashSet.of(Month.JUNE), parsed.get().monthSpec.months);
    assertEquals(HashSet.of(DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY, DayOfWeek.FRIDAY),
                 parsed.get().dayOfWeekSpec.days);
}
 
开发者ID:emmanueltouzery,项目名称:crony,代码行数:12,代码来源:ParseTest.java

示例9: parseComplicated

import io.vavr.collection.HashSet; //导入依赖的package包/类
@Test
public void parseComplicated() {
    Validation<String, Cron> parsed = Cron.parseCronString("1,2,3,5,20-25,30-35,59 0-23/2 31,L 12 *");
    assertTrueS(() -> parsed.getError(), parsed.isValid());
    assertEquals(HashSet.of(1,2,3,5,20,21,22,23,24,25,30,31,32,33,34,35,59), parsed.get().minSpec.minutes);
    assertEquals(HashSet.of(0,2,4,6,8,10,12,14,16,18,20,22), parsed.get().hourSpec.hours);
    assertEquals(HashSet.of(31, DayOfMonthSpec.LAST_DAY_OF_MONTH), parsed.get().dayOfMonthSpec.monthDays);
    assertEquals(HashSet.of(Month.DECEMBER), parsed.get().monthSpec.months);
    assertEquals(HashSet.empty(), parsed.get().dayOfWeekSpec.days);
}
 
开发者ID:emmanueltouzery,项目名称:crony,代码行数:11,代码来源:ParseTest.java

示例10: parseMonthDayNames

import io.vavr.collection.HashSet; //导入依赖的package包/类
@Test
public void parseMonthDayNames() {
    Validation<String, Cron> parsed = Cron.parseCronString("0 8 * JaN,3,JUL 1,THU,sUN");
    assertTrueS(() -> parsed.getError(), parsed.isValid());
    assertEquals(HashSet.of(Month.JANUARY,Month.MARCH,Month.JULY), parsed.get().monthSpec.months);
    assertEquals(HashSet.of(DayOfWeek.MONDAY, DayOfWeek.THURSDAY, DayOfWeek.SUNDAY),
                 parsed.get().dayOfWeekSpec.days);
}
 
开发者ID:emmanueltouzery,项目名称:crony,代码行数:9,代码来源:ParseTest.java

示例11: getRights

import io.vavr.collection.HashSet; //导入依赖的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

示例12: apply

import io.vavr.collection.HashSet; //导入依赖的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

示例13: getVisibility

import io.vavr.collection.HashSet; //导入依赖的package包/类
/**
 * Returns the data center names to which the given persistenceId is currently visible
 */
public CompletionStage<Visibility> getVisibility(String persistenceId) {
    return getVisibilityStmt
        .thenCompose(stmt -> session.selectOne(stmt.bind(persistenceId)))
        .thenApply(opt ->
            opt.map(row ->
                new Visibility(HashSet.ofAll(row.getSet("datacenters", String.class)), row.getBool("master"))
            ).getOrElse(Visibility.EMPTY)
        );
}
 
开发者ID:Tradeshift,项目名称:ts-reaktive,代码行数:13,代码来源:VisibilityRepository.java

示例14: valueTypeSpecificBuilding

import io.vavr.collection.HashSet; //导入依赖的package包/类
@Test
public void valueTypeSpecificBuilding() {
    CategoryColumn column = builder().add("foo").add("bar").addAll("foo", "baz", "bar").add("foo").build();
    assertEquals(ID, column.getId());
    assertEquals(6, column.getRowCount());
    assertEquals(HashSet.of("foo", "bar", "baz"), column.getCategories());
    assertEquals("foo", column.getValueAt(0));
    assertEquals("bar", column.getValueAt(1));
}
 
开发者ID:netzwerg,项目名称:paleo,代码行数:10,代码来源:CategoryColumnTest.java

示例15: testExportsRateLimiterMetrics

import io.vavr.collection.HashSet; //导入依赖的package包/类
@Test
public void testExportsRateLimiterMetrics() {
    // Given
    final CollectorRegistry registry = new CollectorRegistry();

    final RateLimiter rateLimiter = RateLimiter.ofDefaults("foo");

    RateLimiterExports.ofIterable("boo_rate_limiter", singletonList(rateLimiter)).register(registry);

    final Supplier<Map<String, Double>> values = () -> HashSet
            .of("available_permissions", "waiting_threads")
            .map(param ->
                    Tuple.of(param, registry.getSampleValue(
                            "boo_rate_limiter",
                            new String[]{"name", "param"},
                            new String[]{"foo", param})))
            .toMap(t -> t);

    // When

    final Map<String, Double> initialValues = values.get();

    // Then

    assertThat(initialValues).isEqualTo(HashMap.of(
            "available_permissions", 50.0,
            "waiting_threads", 0.0
    ));
}
 
开发者ID:resilience4j,项目名称:resilience4j,代码行数:30,代码来源:RateLimiterExportsTest.java


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