本文整理了Java中io.vavr.collection.HashSet
类的一些代码示例,展示了HashSet
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashSet
类的具体详情如下:
包路径:io.vavr.collection.HashSet
类名称:HashSet
[英]An immutable HashSet implementation.
[中]不可变的哈希集实现。
代码示例来源: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
@Override
public HashSet<T> filter(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
final HashSet<T> filtered = HashSet.ofAll(iterator().filter(predicate));
if (filtered.isEmpty()) {
return empty();
} else if (filtered.length() == length()) {
return this;
} else {
return filtered;
}
}
代码示例来源:origin: vavr-io/vavr
/**
* Returns a singleton {@code HashSet}, i.e. a {@code HashSet} of one element.
*
* @param element An element.
* @param <T> The component type
* @return A new HashSet instance containing the given element
*/
public static <T> HashSet<T> of(T element) {
return HashSet.<T> empty().add(element);
}
代码示例来源:origin: vavr-io/vavr
@Override
public HashSet<T> orElse(Iterable<? extends T> other) {
return isEmpty() ? ofAll(other) : this;
}
代码示例来源:origin: vavr-io/vavr
@Override
public HashSet<T> take(int n) {
if (n >= size() || isEmpty()) {
return this;
} else if (n <= 0) {
return empty();
} else {
return ofAll(() -> iterator().take(n));
}
}
代码示例来源: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: vavr-io/vavr
@Override
public HashSet<T> drop(int n) {
if (n <= 0) {
return this;
} else {
return HashSet.ofAll(iterator().drop(n));
}
}
代码示例来源:origin: vavr-io/vavr
@Override
public <U> HashSet<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
if (isEmpty()) {
return empty();
} else {
final HashArrayMappedTrie<U, U> that = foldLeft(HashArrayMappedTrie.empty(),
(tree, t) -> addAll(tree, mapper.apply(t)));
return new HashSet<>(that);
}
}
代码示例来源:origin: vavr-io/vavr
@Override
public HashSet<T> intersect(Set<? extends T> elements) {
Objects.requireNonNull(elements, "elements is null");
if (isEmpty() || elements.isEmpty()) {
return empty();
} else {
final int size = size();
if (size <= elements.size()) {
return retainAll(elements);
} else {
final HashSet<T> results = HashSet.<T> ofAll(elements).retainAll(this);
return (size == results.size()) ? this : results;
}
}
}
代码示例来源:origin: vavr-io/vavr
/**
* Creates a HashSet that contains the elements of the given {@link java.util.stream.Stream}.
*
* @param javaStream A {@link java.util.stream.Stream}
* @param <T> Component type of the Stream.
* @return A HashSet containing the given elements in the same order.
*/
public static <T> HashSet<T> ofAll(java.util.stream.Stream<? extends T> javaStream) {
Objects.requireNonNull(javaStream, "javaStream is null");
return HashSet.ofAll(Iterator.ofAll(javaStream.iterator()));
}
代码示例来源:origin: vavr-io/vavr
/**
* Alias for {@link HashSet#empty()}
*
* @param <T> Component type of element.
* @return A singleton instance of empty {@link HashSet}
*/
public static <T> Set<T> Set() {
return HashSet.empty();
}
代码示例来源:origin: vavr-io/vavr
@Override
public HashSet<T> dropWhile(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
final HashSet<T> dropped = HashSet.ofAll(iterator().dropWhile(predicate));
return dropped.length() == length() ? this : dropped;
}
代码示例来源: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: com.pragmaticobjects.oo.data/data-core
@Override
public boolean process(java.util.Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
processingEnv.getElementUtils();
for (TypeElement annotation : annotations) {
Manifest manifest = HashSet.of(roundEnv)
.flatMap(env -> env.getElementsAnnotatedWith(annotation))
.map(e -> (PackageElement) e)
.map(e -> new ManifestFromPackageElement(e))
.transform(ms -> new ManifestCombined(ms));
for(Declaration<A> declaration : manifest.declarations(annotationType)) {
task.sourceFiles(declaration, manifest, processingEnv).forEach(SourceFile::generate);
}
}
return false;
}
代码示例来源: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
public BeanObjectOptional(boolean empty) {
if (empty) {
charSeq = CharSeq.empty();
either = Either.left(EITHER_VALUE);
option = Option.none();
map = HashMap.empty();
multimap = HashMultimap.withSeq().empty();
seq = List.empty();
set = HashSet.empty();
} else {
charSeq = CharSeq.of(CHARSEQ_VALUE);
either = Either.right(EITHER_VALUE);
option = Option.of(OPTION_VALUE);
map = HashMap.of("key", MAP_VALUE);
multimap = HashMultimap.withSeq().of("key", MULTIMAP_VALUE);
seq = List.of(SEQ_VALUE);
set = HashSet.of(SET_VALUE);
}
}
}
代码示例来源:origin: vavr-io/vavr
/**
* {@code readResolve} method for the serialization proxy pattern.
* <p>
* Returns a logically equivalent instance of the enclosing class. The presence of this method causes the
* serialization system to translate the serialization proxy back into an instance of the enclosing class
* upon deserialization.
*
* @return A deserialized instance of the enclosing class.
*/
private Object readResolve() {
return tree.isEmpty() ? HashSet.empty() : new HashSet<>(tree);
}
}
代码示例来源: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
/**
* Creates a HashSet of the given elements.
*
* @param elements Set elements
* @param <T> The value type
* @return A new HashSet containing the given entries
*/
@SuppressWarnings("unchecked")
public static <T> HashSet<T> ofAll(Iterable<? extends T> elements) {
Objects.requireNonNull(elements, "elements is null");
if (elements instanceof HashSet) {
return (HashSet<T>) elements;
} else {
final HashArrayMappedTrie<T, T> tree = addAll(HashArrayMappedTrie.empty(), elements);
return tree.isEmpty() ? empty() : new HashSet<>(tree);
}
}
代码示例来源:origin: vavr-io/vavr
@Override
public LinkedHashMap<K, V> removeAll(Iterable<? extends K> keys) {
Objects.requireNonNull(keys, "keys is null");
final HashSet<K> toRemove = HashSet.ofAll(keys);
final Queue<Tuple2<K, V>> newList = list.filter(t -> !toRemove.contains(t._1));
final HashMap<K, V> newMap = map.filter(t -> !toRemove.contains(t._1));
return newList.size() == size() ? this : wrap(newList, newMap);
}
内容来源于网络,如有侵权,请联系作者删除!