io.vavr.collection.HashSet.of()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中io.vavr.collection.HashSet.of()方法的一些代码示例,展示了HashSet.of()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashSet.of()方法的具体详情如下:
包路径:io.vavr.collection.HashSet
类名称:HashSet
方法名:of

HashSet.of介绍

[英]Returns a singleton HashSet, i.e. a HashSet of one element.
[中]返回单个哈希集,即一个元素的哈希集。

代码示例

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link HashSet#of(Object)}
 *
 * @param <T>     Component type of element.
 * @param element An element.
 * @return A new {@link HashSet} instance containing the given element
 */
public static <T> Set<T> Set(T element) {
  return HashSet.of(element);
}

代码示例来源:origin: vavr-io/vavr

/**
 * Alias for {@link HashSet#of(Object...)}
 *
 * @param <T>      Component type of elements.
 * @param elements Zero or more elements.
 * @return A new {@link HashSet} instance containing the given elements
 * @throws NullPointerException if {@code elements} is null
 */
@SuppressWarnings("varargs")
@SafeVarargs
public static <T> Set<T> Set(T... elements) {
  return HashSet.of(elements);
}
// -- LinkedSet

代码示例来源:origin: resilience4j/resilience4j

@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
  ));
}

代码示例来源:origin: resilience4j/resilience4j

@Test
public void testExportsCircuitBreakerStates() {
  // Given
  final CollectorRegistry registry = new CollectorRegistry();
  final Bulkhead bulkhead = Bulkhead.ofDefaults("foo");
  BulkheadExports.ofIterable("boo_bulkhead", singletonList(bulkhead)).register(registry);
  final Supplier<Map<String, Double>> values = () -> HashSet
      .of("available_concurrent_calls")
      .map(param ->
          Tuple.of(param, registry.getSampleValue(
              "boo_bulkhead",
              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_concurrent_calls", 25.0));
}

代码示例来源:origin: resilience4j/resilience4j

.of("closed", "open", "half_open")
.map(state ->
  Tuple.of(state, registry.getSampleValue(

代码示例来源:origin: resilience4j/resilience4j

.of("successful", "failed", "not_permitted", "buffered", "buffered_max")
.map(callType ->
    Tuple.of(callType, registry.getSampleValue(

代码示例来源:origin: com.pragmaticobjects.oo.atom/atom-basis

/**
 * Ctor.
 *
 * @param classNames {@link ClassNames} under test
 * @param namesToCheck expected names
 */
public AssertClassNamesContainCertainNames(ClassNames classNames, String... namesToCheck) {
  this(classNames, HashSet.of(namesToCheck));
}

代码示例来源:origin: io.vavr/vavr

/**
 * Alias for {@link HashSet#of(Object)}
 *
 * @param <T>     Component type of element.
 * @param element An element.
 * @return A new {@link HashSet} instance containing the given element
 */
public static <T> Set<T> Set(T element) {
  return HashSet.of(element);
}

代码示例来源:origin: com.pragmaticobjects.oo.atom/atom-basis

/**
 * Ctor.
 *
 * @param packageName Package.
 * @param className Annotation's name.
 * @param retentionPolicy Annotation's retention policy.
 * @param targets Annotation targets.
 */
public JpAnnotation(String packageName, String className, RetentionPolicy retentionPolicy, ElementType... targets) {
  this(packageName, className, retentionPolicy, HashSet.of(targets));
}

代码示例来源:origin: io.vavr/vavr

/**
 * Alias for {@link HashSet#of(Object...)}
 *
 * @param <T>      Component type of elements.
 * @param elements Zero or more elements.
 * @return A new {@link HashSet} instance containing the given elements
 * @throws NullPointerException if {@code elements} is null
 */
@SuppressWarnings("varargs")
@SafeVarargs
public static <T> Set<T> Set(T... elements) {
  return HashSet.of(elements);
}
// -- LinkedSet

代码示例来源:origin: vavr-io/vavr-jackson

@Test
  public void testDefaultDeserialization() throws IOException {
    Assert.assertEquals(mapper().readValue("[1]", Set.class), HashSet.of(1));
  }
}

代码示例来源:origin: vavr-io/vavr-jackson

@SuppressWarnings("unchecked")
@Test
public void test8() throws IOException {
  Either<List<Integer>, Set<Double>> either = Either.right(HashSet.of(42.0));
  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);
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testHashSetOfString() throws Exception {
  String src0 = "A";
  String src1 = "B";
  String src2 = "C";
  HashSet<String> src = HashSet.of(src0, src1, src2);
  String json = MAPPER.writeValueAsString(new ParameterizedHashSetPojo<>(src));
  Assert.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}");
  ParameterizedHashSetPojo<java.lang.String> restored = 
      MAPPER.readValue(json, new TypeReference<ParameterizedHashSetPojo<java.lang.String>>(){});
  Assert.assertEquals(src, restored.getValue());
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testHashSetClass() throws Exception {
  HashSetClass src = new HashSetClass(HashSet.of(new ImplementedClass()));
  String json = MAPPER.writeValueAsString(src);
  HashSetClass restored = MAPPER.readValue(json, HashSetClass.class);
  Assert.assertEquals(restored.value.head().getClass(), ImplementedClass.class);
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testHashSetOfTuple() throws Exception {
  String src00 = "A";
  String src01 = "B";
  Tuple2<String, String> src0 = Tuple.of(src00, src01);
  HashSet<Tuple2<String, String>> src = HashSet.of(src0);
  String json = MAPPER.writeValueAsString(new ParameterizedHashSetPojo<>(src));
  Assert.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}");
  ParameterizedHashSetPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>> restored = 
      MAPPER.readValue(json, new TypeReference<ParameterizedHashSetPojo<io.vavr.Tuple2<java.lang.String, java.lang.String>>>(){});
  Assert.assertEquals(src, restored.getValue());
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testHashSetOfString() throws Exception {
  String src0 = "A";
  String src1 = "B";
  String src2 = "C";
  HashSet<String> src = HashSet.of(src0, src1, src2);
  String json = MAPPER.writeValueAsString(new HashSetOfString().setValue(src));
  Assert.assertEquals(json, "{\"value\":[\"A\",\"B\",\"C\"]}");
  HashSetOfString restored = MAPPER.readValue(json, HashSetOfString.class);
  Assert.assertEquals(src, restored.getValue());
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testHashSetOfTuple() throws Exception {
  String src00 = "A";
  String src01 = "B";
  Tuple2<String, String> src0 = Tuple.of(src00, src01);
  HashSet<Tuple2<String, String>> src = HashSet.of(src0);
  String json = MAPPER.writeValueAsString(new HashSetOfTuple().setValue(src));
  Assert.assertEquals(json, "{\"value\":[[\"A\",\"B\"]]}");
  HashSetOfTuple restored = MAPPER.readValue(json, HashSetOfTuple.class);
  Assert.assertEquals(src, restored.getValue());
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testHashSet() throws Exception {
  HashSet<I> src = HashSet.of(new B());
  String json = MAPPER.writeValueAsString(new HashSetPojo().setValue(src));
  Assert.assertEquals(json, "{\"value\":[{\"type\":\"b\"}]}");
  HashSetPojo pojo = MAPPER.readValue(json, HashSetPojo.class);
  HashSet<I> restored = pojo.getValue();
  Assert.assertEquals(restored.filter(e -> e instanceof B).length(), 1);
}

代码示例来源:origin: vavr-io/vavr-jackson

@Test
public void testHashSet() throws Exception {
  HashSet<A> src = HashSet.of(new B("a", "b"));
  String json = MAPPER.writeValueAsString(new HashSetPojo().setValue(src));
  Assert.assertEquals(json, "{\"value\":[{\"ExtFieldsPojoTest$B\":{\"a\":\"a\",\"b\":\"b\"}}]}");
  HashSetPojo pojo = MAPPER.readValue(json, HashSetPojo.class);
  HashSet<A> restored = pojo.getValue();
  Assert.assertEquals(restored.filter(e -> e instanceof B).length(), 1);
  Assert.assertEquals(restored.head().a, "a");
  Assert.assertEquals(((B) restored.head()).b, "b");
}

代码示例来源:origin: netzwerg/paleo

@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));
}

相关文章