T - the element typepublic final class HashSet<T> extends java.lang.Object implements Set<T>, java.io.Serializable
Features:
Performance characteristics:
Implementation details:
This set performs read and write operations of single elements in O(1) time, and in O(1) space.
The CHAMP trie contains nodes that may be shared with other sets.
If a write operation is performed on a node, then this set creates a copy of the node and of all parent nodes up to the root (copy-path-on-write). Since the CHAMP trie has a fixed maximal height, the cost is O(1).
The immutable version of this set extends from the non-public class
ChampBitmapIndexNode. This design safes 16 bytes for every instance,
and reduces the number of redirections for finding an element in the
collection by 1.
References:
Portions of the code in this class have been derived from 'The Capsule Hash Trie Collections Library', and from 'JHotDraw 8'.
| Modifier and Type | Method and Description |
|---|---|
HashSet<T> |
add(T element)
Add the given element to this set, if it is not already contained.
|
HashSet<T> |
addAll(java.lang.Iterable<? extends T> elements)
Adds all of the given elements to this set, if not already contained.
|
<R> HashSet<R> |
collect(PartialFunction<? super T,? extends R> partialFunction)
Collects all elements that are in the domain of the given
partialFunction by mapping the elements to type R. |
static <T> java.util.stream.Collector<T,java.util.ArrayList<T>,HashSet<T>> |
collector()
Returns a
Collector which may be used in conjunction with
Stream.collect(java.util.stream.Collector) to obtain a HashSet. |
boolean |
contains(T element)
Shortcut for
exists(e -> Objects.equals(e, element)), tests if the given element is contained. |
HashSet<T> |
diff(Set<? extends T> elements)
Calculates the difference between this set and another set.
|
HashSet<T> |
distinct()
Returns a new version of this which contains no duplicates.
|
HashSet<T> |
distinctBy(java.util.Comparator<? super T> comparator)
Returns a new version of this which contains no duplicates.
|
<U> HashSet<T> |
distinctBy(java.util.function.Function<? super T,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
HashSet<T> |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
HashSet<T> |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
HashSet<T> |
dropUntil(java.util.function.Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element.
|
HashSet<T> |
dropWhile(java.util.function.Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element.
|
static <T> HashSet<T> |
empty() |
boolean |
equals(java.lang.Object o)
In Vavr there are four basic classes of collections:
Seq (sequential elements)
Set (distinct elements)
Map (indexed elements)
Multimap (indexed collections)
Two collection instances of these classes are equal if and only if both collections
belong to the same basic collection class (Seq, Set, Map or Multimap)
contain the same elements
have the same element order, if the collections are of type Seq
Two Map/Multimap elements, resp.
|
static <T> HashSet<T> |
fill(int n,
java.util.function.Supplier<? extends T> s)
Returns a HashSet containing tuples returned by
n calls to a given Supplier s. |
HashSet<T> |
filter(java.util.function.Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
HashSet<T> |
filterNot(java.util.function.Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which do not satisfy the given predicate.
|
<U> HashSet<U> |
flatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
FlatMaps this Traversable.
|
<U> U |
foldRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> f)
Folds this elements from the right, starting with
zero and successively calling combine. |
<C> Map<C,HashSet<T>> |
groupBy(java.util.function.Function<? super T,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<HashSet<T>> |
grouped(int size)
Groups this
Traversable into fixed size blocks. |
boolean |
hasDefiniteSize()
Checks if this Traversable is known to have a finite size.
|
int |
hashCode()
Returns the hash code of this collection.
|
T |
head()
Returns the first element of a non-empty Traversable.
|
Option<T> |
headOption()
Returns the first element of a non-empty Traversable as
Option. |
HashSet<T> |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
Option<HashSet<T>> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option. |
HashSet<T> |
intersect(Set<? extends T> elements)
Computes the intersection between this set and another set.
|
boolean |
isAsync()
A
HashSet is computed synchronously. |
boolean |
isEmpty()
Checks if this Traversable is empty.
|
boolean |
isLazy()
A
HashSet is computed eagerly. |
boolean |
isTraversableAgain()
Checks if this Traversable can be repeatedly traversed.
|
Iterator<T> |
iterator()
An iterator by means of head() and tail().
|
T |
last()
Dual of Traversable.head(), returning the last element.
|
int |
length()
Computes the number of elements of this Traversable.
|
<U> HashSet<U> |
map(java.util.function.Function<? super T,? extends U> mapper)
Maps the elements of this
Traversable to elements of a new type preserving their order, if any. |
java.lang.String |
mkString(java.lang.CharSequence prefix,
java.lang.CharSequence delimiter,
java.lang.CharSequence suffix)
Joins the string representations of this elements using a specific delimiter, prefix and suffix.
|
static <T> HashSet<T> |
narrow(HashSet<? extends T> hashSet)
Narrows a widened
HashSet<? extends T> to HashSet<T>
by performing a type-safe cast. |
static <T> HashSet<T> |
of(T... elements)
Creates a HashSet of the given elements.
|
static <T> HashSet<T> |
of(T element)
Returns a singleton
HashSet, i.e. |
static HashSet<java.lang.Boolean> |
ofAll(boolean... elements)
Creates a HashSet from boolean values.
|
static HashSet<java.lang.Byte> |
ofAll(byte... elements)
Creates a HashSet from byte values.
|
static HashSet<java.lang.Character> |
ofAll(char... elements)
Creates a HashSet from char values.
|
static HashSet<java.lang.Double> |
ofAll(double... elements)
Creates a HashSet from double values.
|
static HashSet<java.lang.Float> |
ofAll(float... elements)
Creates a HashSet from float values.
|
static HashSet<java.lang.Integer> |
ofAll(int... elements)
Creates a HashSet from int values.
|
static <T> HashSet<T> |
ofAll(java.lang.Iterable<? extends T> elements)
Creates a HashSet of the given elements.
|
static HashSet<java.lang.Long> |
ofAll(long... elements)
Creates a HashSet from long values.
|
static HashSet<java.lang.Short> |
ofAll(short... elements)
Creates a HashSet from short values.
|
static <T> HashSet<T> |
ofAll(java.util.stream.Stream<? extends T> javaStream)
Creates a HashSet that contains the elements of the given
Stream. |
HashSet<T> |
orElse(java.lang.Iterable<? extends T> other)
Returns this
Traversable if it is nonempty, otherwise return the alternative. |
HashSet<T> |
orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Returns this
Traversable if it is nonempty, otherwise return the result of evaluating supplier. |
Tuple2<HashSet<T>,HashSet<T>> |
partition(java.util.function.Predicate<? super T> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct traversables
according to a predicate. |
HashSet<T> |
peek(java.util.function.Consumer<? super T> action)
Performs the given
action on the first element if this is an eager implementation. |
static HashSet<java.lang.Character> |
range(char from,
char toExclusive) |
static HashSet<java.lang.Integer> |
range(int from,
int toExclusive)
Creates a HashSet of int numbers starting from
from, extending to toExclusive - 1. |
static HashSet<java.lang.Long> |
range(long from,
long toExclusive)
Creates a HashSet of long numbers starting from
from, extending to toExclusive - 1. |
static HashSet<java.lang.Character> |
rangeBy(char from,
char toExclusive,
int step) |
static HashSet<java.lang.Double> |
rangeBy(double from,
double toExclusive,
double step) |
static HashSet<java.lang.Integer> |
rangeBy(int from,
int toExclusive,
int step)
Creates a HashSet of int numbers starting from
from, extending to toExclusive - 1,
with step. |
static HashSet<java.lang.Long> |
rangeBy(long from,
long toExclusive,
long step)
Creates a HashSet of long numbers starting from
from, extending to toExclusive - 1,
with step. |
static HashSet<java.lang.Character> |
rangeClosed(char from,
char toInclusive) |
static HashSet<java.lang.Integer> |
rangeClosed(int from,
int toInclusive)
Creates a HashSet of int numbers starting from
from, extending to toInclusive. |
static HashSet<java.lang.Long> |
rangeClosed(long from,
long toInclusive)
Creates a HashSet of long numbers starting from
from, extending to toInclusive. |
static HashSet<java.lang.Character> |
rangeClosedBy(char from,
char toInclusive,
int step) |
static HashSet<java.lang.Double> |
rangeClosedBy(double from,
double toInclusive,
double step) |
static HashSet<java.lang.Integer> |
rangeClosedBy(int from,
int toInclusive,
int step)
Creates a HashSet of int numbers starting from
from, extending to toInclusive,
with step. |
static HashSet<java.lang.Long> |
rangeClosedBy(long from,
long toInclusive,
long step)
Creates a HashSet of long numbers starting from
from, extending to toInclusive,
with step. |
HashSet<T> |
remove(T key)
Removes a specific element from this set, if present.
|
HashSet<T> |
removeAll(java.lang.Iterable<? extends T> elements)
Removes all of the given elements from this set, if present.
|
HashSet<T> |
replace(T currentElement,
T newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
HashSet<T> |
replaceAll(T currentElement,
T newElement)
Replaces all occurrences of the given currentElement with newElement.
|
HashSet<T> |
retainAll(java.lang.Iterable<? extends T> elements)
Keeps all occurrences of the given elements from this.
|
HashSet<T> |
scan(T zero,
java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Computes a prefix scan of the elements of the collection.
|
<U> HashSet<U> |
scanLeft(U zero,
java.util.function.BiFunction<? super U,? super T,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going left to right.
|
<U> HashSet<U> |
scanRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going right to left.
|
Iterator<HashSet<T>> |
slideBy(java.util.function.Function<? super T,?> classifier)
Slides a non-overlapping window of a variable size over this
Traversable. |
Iterator<HashSet<T>> |
sliding(int size)
Slides a window of a specific
size and step size 1 over this Traversable by calling
Traversable.sliding(int, int). |
Iterator<HashSet<T>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Traversable. |
Tuple2<HashSet<T>,HashSet<T>> |
span(java.util.function.Predicate<? super T> predicate)
Returns a tuple where the first element is the longest prefix of elements that satisfy the given
predicate and the second element is the remainder. |
java.util.Spliterator<T> |
spliterator() |
java.lang.String |
stringPrefix()
Returns the name of this Value type, which is used by toString().
|
static <T> HashSet<T> |
tabulate(int n,
java.util.function.Function<? super java.lang.Integer,? extends T> f)
Returns an HashSet containing
n values of a given Function f
over a range of integer values from 0 to n - 1. |
HashSet<T> |
tail()
Drops the first element of a non-empty Traversable.
|
Option<HashSet<T>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option. |
HashSet<T> |
take(int n)
Takes the first n elements of this or all elements, if this length < n.
|
HashSet<T> |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
HashSet<T> |
takeUntil(java.util.function.Predicate<? super T> predicate)
Takes elements until the predicate holds for the current element.
|
HashSet<T> |
takeWhile(java.util.function.Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element.
|
java.util.HashSet<T> |
toJavaSet()
Converts this Vavr
Set to a java.util.Set while preserving characteristics
like insertion order (LinkedHashSet) and sort order (SortedSet). |
java.lang.String |
toString()
Clarifies that values have a proper toString() method implemented.
|
<U> U |
transform(java.util.function.Function<? super HashSet<T>,? extends U> f)
Transforms this
HashSet. |
HashSet<T> |
union(Set<? extends T> elements)
Adds all of the elements of
that set to this set, if not already present. |
<U> HashSet<Tuple2<T,U>> |
zip(java.lang.Iterable<? extends U> that)
Returns a traversable formed from this traversable and another Iterable collection by combining
corresponding elements in pairs.
|
<U> HashSet<Tuple2<T,U>> |
zipAll(java.lang.Iterable<? extends U> that,
T thisElem,
U thatElem)
Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in
pairs.
|
<U,R> HashSet<R> |
zipWith(java.lang.Iterable<? extends U> that,
java.util.function.BiFunction<? super T,? super U,? extends R> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
HashSet<Tuple2<T,java.lang.Integer>> |
zipWithIndex()
Zips this traversable with its indices.
|
<U> HashSet<U> |
zipWithIndex(java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)
Zips this traversable with its indices by applying mapper provided.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitisDistinct, narrowarrangeBy, average, containsAll, count, existsUnique, find, findLast, fold, foldLeft, forEachWithIndex, get, isOrdered, isSequential, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, narrow, nonEmpty, product, reduce, reduceLeft, reduceLeftOption, reduceOption, reduceRight, reduceRightOption, single, singleOption, size, sum, toLinkedMap, toMap, toSortedMap, toSortedMap, unzip, unzip3collect, collect, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, narrow, out, out, stderr, stdout, toArray, toCharSeq, toCompletableFuture, toEither, toEither, toInvalid, toInvalid, toJavaArray, toJavaArray, toJavaArray, toJavaCollection, toJavaList, toJavaList, toJavaMap, toJavaMap, toJavaMap, toJavaOptional, toJavaParallelStream, toJavaSet, toJavaStream, toLeft, toLeft, toLinkedMap, toLinkedMap, toLinkedSet, toList, toMap, toMap, toOption, toPriorityQueue, toPriorityQueue, toQueue, toRight, toRight, toSet, toSortedMap, toSortedMap, toSortedMap, toSortedMap, toSortedSet, toSortedSet, toStream, toTree, toTree, toTry, toTry, toValid, toValid, toValidation, toValidation, toVectorpublic static <T> HashSet<T> empty()
public static <T> java.util.stream.Collector<T,java.util.ArrayList<T>,HashSet<T>> collector()
Collector which may be used in conjunction with
Stream.collect(java.util.stream.Collector) to obtain a HashSet.T - Component type of the HashSet.public static <T> HashSet<T> narrow(HashSet<? extends T> hashSet)
HashSet<? extends T> to HashSet<T>
by performing a type-safe cast. This is eligible because immutable/read-only
collections are covariant.T - Component type of the HashSet.hashSet - A HashSet.hashSet instance as narrowed type HashSet<T>.public static <T> HashSet<T> of(T element)
HashSet, i.e. a HashSet of one element.T - The component typeelement - An element.@SafeVarargs public static <T> HashSet<T> of(T... elements)
HashSet.of(1, 2, 3, 4)T - Component type of the HashSet.elements - Zero or more elements.java.lang.NullPointerException - if elements is nullpublic static <T> HashSet<T> tabulate(int n, java.util.function.Function<? super java.lang.Integer,? extends T> f)
n values of a given Function f
over a range of integer values from 0 to n - 1.T - Component type of the HashSetn - The number of elements in the HashSetf - The Function computing element valuesf(0),f(1), ..., f(n - 1)java.lang.NullPointerException - if f is nullpublic static <T> HashSet<T> fill(int n, java.util.function.Supplier<? extends T> s)
n calls to a given Supplier s.T - Component type of the HashSetn - The number of elements in the HashSets - The Supplier computing element valuesn, where each element contains the result supplied by s.java.lang.NullPointerException - if s is nullpublic static <T> HashSet<T> ofAll(java.lang.Iterable<? extends T> elements)
T - The value typeelements - Set elementspublic static <T> HashSet<T> ofAll(java.util.stream.Stream<? extends T> javaStream)
Stream.T - Component type of the Stream.javaStream - A Streampublic static HashSet<java.lang.Boolean> ofAll(boolean... elements)
elements - boolean valuesjava.lang.NullPointerException - if elements is nullpublic static HashSet<java.lang.Byte> ofAll(byte... elements)
elements - byte valuesjava.lang.NullPointerException - if elements is nullpublic static HashSet<java.lang.Character> ofAll(char... elements)
elements - char valuesjava.lang.NullPointerException - if elements is nullpublic static HashSet<java.lang.Double> ofAll(double... elements)
elements - double valuesjava.lang.NullPointerException - if elements is nullpublic static HashSet<java.lang.Float> ofAll(float... elements)
elements - float valuesjava.lang.NullPointerException - if elements is nullpublic static HashSet<java.lang.Integer> ofAll(int... elements)
elements - int valuesjava.lang.NullPointerException - if elements is nullpublic static HashSet<java.lang.Long> ofAll(long... elements)
elements - long valuesjava.lang.NullPointerException - if elements is nullpublic static HashSet<java.lang.Short> ofAll(short... elements)
elements - short valuesjava.lang.NullPointerException - if elements is nullpublic static HashSet<java.lang.Integer> range(int from, int toExclusive)
from, extending to toExclusive - 1.
Examples:
HashSet.range(0, 0) // = HashSet()
HashSet.range(2, 0) // = HashSet()
HashSet.range(-2, 2) // = HashSet(-2, -1, 0, 1)
from - the first numbertoExclusive - the last number + 1from >= toExclusivepublic static HashSet<java.lang.Character> range(char from, char toExclusive)
public static HashSet<java.lang.Integer> rangeBy(int from, int toExclusive, int step)
from, extending to toExclusive - 1,
with step.
Examples:
HashSet.rangeBy(1, 3, 1) // = HashSet(1, 2)
HashSet.rangeBy(1, 4, 2) // = HashSet(1, 3)
HashSet.rangeBy(4, 1, -2) // = HashSet(4, 2)
HashSet.rangeBy(4, 1, 2) // = HashSet()
from - the first numbertoExclusive - the last number + 1step - the stepfrom >= toInclusive and step > 0 orfrom <= toInclusive and step < 0java.lang.IllegalArgumentException - if step is zeropublic static HashSet<java.lang.Character> rangeBy(char from, char toExclusive, int step)
public static HashSet<java.lang.Double> rangeBy(double from, double toExclusive, double step)
public static HashSet<java.lang.Long> range(long from, long toExclusive)
from, extending to toExclusive - 1.
Examples:
HashSet.range(0L, 0L) // = HashSet()
HashSet.range(2L, 0L) // = HashSet()
HashSet.range(-2L, 2L) // = HashSet(-2L, -1L, 0L, 1L)
from - the first numbertoExclusive - the last number + 1from >= toExclusivepublic static HashSet<java.lang.Long> rangeBy(long from, long toExclusive, long step)
from, extending to toExclusive - 1,
with step.
Examples:
HashSet.rangeBy(1L, 3L, 1L) // = HashSet(1L, 2L)
HashSet.rangeBy(1L, 4L, 2L) // = HashSet(1L, 3L)
HashSet.rangeBy(4L, 1L, -2L) // = HashSet(4L, 2L)
HashSet.rangeBy(4L, 1L, 2L) // = HashSet()
from - the first numbertoExclusive - the last number + 1step - the stepfrom >= toInclusive and step > 0 orfrom <= toInclusive and step < 0java.lang.IllegalArgumentException - if step is zeropublic static HashSet<java.lang.Integer> rangeClosed(int from, int toInclusive)
from, extending to toInclusive.
Examples:
HashSet.rangeClosed(0, 0) // = HashSet(0)
HashSet.rangeClosed(2, 0) // = HashSet()
HashSet.rangeClosed(-2, 2) // = HashSet(-2, -1, 0, 1, 2)
from - the first numbertoInclusive - the last numberfrom > toInclusivepublic static HashSet<java.lang.Character> rangeClosed(char from, char toInclusive)
public static HashSet<java.lang.Integer> rangeClosedBy(int from, int toInclusive, int step)
from, extending to toInclusive,
with step.
Examples:
HashSet.rangeClosedBy(1, 3, 1) // = HashSet(1, 2, 3)
HashSet.rangeClosedBy(1, 4, 2) // = HashSet(1, 3)
HashSet.rangeClosedBy(4, 1, -2) // = HashSet(4, 2)
HashSet.rangeClosedBy(4, 1, 2) // = HashSet()
from - the first numbertoInclusive - the last numberstep - the stepfrom > toInclusive and step > 0 orfrom < toInclusive and step < 0java.lang.IllegalArgumentException - if step is zeropublic static HashSet<java.lang.Character> rangeClosedBy(char from, char toInclusive, int step)
public static HashSet<java.lang.Double> rangeClosedBy(double from, double toInclusive, double step)
public static HashSet<java.lang.Long> rangeClosed(long from, long toInclusive)
from, extending to toInclusive.
Examples:
HashSet.rangeClosed(0L, 0L) // = HashSet(0L)
HashSet.rangeClosed(2L, 0L) // = HashSet()
HashSet.rangeClosed(-2L, 2L) // = HashSet(-2L, -1L, 0L, 1L, 2L)
from - the first numbertoInclusive - the last numberfrom > toInclusivepublic static HashSet<java.lang.Long> rangeClosedBy(long from, long toInclusive, long step)
from, extending to toInclusive,
with step.
Examples:
HashSet.rangeClosedBy(1L, 3L, 1L) // = HashSet(1L, 2L, 3L)
HashSet.rangeClosedBy(1L, 4L, 2L) // = HashSet(1L, 3L)
HashSet.rangeClosedBy(4L, 1L, -2L) // = HashSet(4L, 2L)
HashSet.rangeClosedBy(4L, 1L, 2L) // = HashSet()
from - the first numbertoInclusive - the last numberstep - the stepfrom > toInclusive and step > 0 orfrom < toInclusive and step < 0java.lang.IllegalArgumentException - if step is zeropublic HashSet<T> add(T element)
Setpublic HashSet<T> addAll(java.lang.Iterable<? extends T> elements)
Setpublic <R> HashSet<R> collect(PartialFunction<? super T,? extends R> partialFunction)
TraversablepartialFunction by mapping the elements to type R.
More specifically, for each of this elements in iteration order first it is checked
partialFunction.isDefinedAt(element)
If the elements makes it through that filter, the mapped instance is added to the result collection
R newElement = partialFunction.apply(element)
Note:If this Traversable is ordered (i.e. extends Ordered,
the caller of collect has to ensure that the elements are comparable (i.e. extend Comparable).collect in interface Set<T>collect in interface Traversable<T>R - The new element typepartialFunction - A function that is not necessarily defined of all elements of this traversable.Traversable instance containing elements of type Rpublic boolean contains(T element)
Valueexists(e -> Objects.equals(e, element)), tests if the given element is contained.public HashSet<T> diff(Set<? extends T> elements)
Set
See also Set.removeAll(Iterable).
public HashSet<T> distinct()
Traversableequals.public HashSet<T> distinctBy(java.util.Comparator<? super T> comparator)
Traversablecomparator.distinctBy in interface Set<T>distinctBy in interface Traversable<T>comparator - A comparatorTraversable containing this elements without duplicatespublic <U> HashSet<T> distinctBy(java.util.function.Function<? super T,? extends U> keyExtractor)
Traversableequals.
The elements of the result are determined in the order of their occurrence - first match wins.
distinctBy in interface Set<T>distinctBy in interface Traversable<T>U - key typekeyExtractor - A key extractorTraversable containing this elements without duplicatespublic HashSet<T> drop(int n)
Traversablepublic HashSet<T> dropRight(int n)
Traversablepublic HashSet<T> dropUntil(java.util.function.Predicate<? super T> predicate)
Traversablepublic HashSet<T> dropWhile(java.util.function.Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as dropUntil(predicate.negate()).
It is intended to be used with method references, which cannot be negated directly.
public HashSet<T> filter(java.util.function.Predicate<? super T> predicate)
Traversablepublic HashSet<T> filterNot(java.util.function.Predicate<? super T> predicate)
TraversableThe default implementation is equivalent to
filter(predicate.negate()public <U> HashSet<U> flatMap(java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
Traversablepublic <U> U foldRight(U zero,
java.util.function.BiFunction<? super T,? super U,? extends U> f)
Traversablezero and successively calling combine.
Example:
// = "!cba"
List("a", "b", "c").foldRight("!", (x, xs) -> xs + x)
public <C> Map<C,HashSet<T>> groupBy(java.util.function.Function<? super T,? extends C> classifier)
TraversablegroupBy in interface Set<T>groupBy in interface Traversable<T>C - classified class typeclassifier - A function which classifies elements into classesTraversable.arrangeBy(Function)public Iterator<HashSet<T>> grouped(int size)
TraversableTraversable into fixed size blocks.
Let length be the length of this Iterable. Then grouped is defined as follows:
this.isEmpty(), the resulting Iterator is empty.size <= length, the resulting Iterator will contain length / size blocks of size
size and maybe a non-empty block of size length % size, if there are remaining elements.size > length, the resulting Iterator will contain one block of size length.
[].grouped(1) = []
[].grouped(0) throws
[].grouped(-1) throws
[1,2,3,4].grouped(2) = [[1,2],[3,4]]
[1,2,3,4,5].grouped(2) = [[1,2],[3,4],[5]]
[1,2,3,4].grouped(5) = [[1,2,3,4]]
Please note that grouped(int) is a special case of Traversable.sliding(int, int), i.e.
grouped(size) is the same as sliding(size, size).public boolean hasDefiniteSize()
TraversableThis method should be implemented by classes only, i.e. not by interfaces.
hasDefiniteSize in interface Traversable<T>public T head()
Traversablehead in interface Traversable<T>public Option<T> headOption()
TraversableOption.headOption in interface Traversable<T>Some(element) or None if this is empty.public HashSet<T> init()
Traversablepublic Option<HashSet<T>> initOption()
TraversableOption.initOption in interface Set<T>initOption in interface Traversable<T>Some(traversable) or None if this is empty.public HashSet<T> intersect(Set<? extends T> elements)
Set
See also Set.retainAll(Iterable).
public boolean isAsync()
HashSet is computed synchronously.public boolean isEmpty()
Traversablepublic boolean isLazy()
HashSet is computed eagerly.public boolean isTraversableAgain()
TraversableThis method should be implemented by classes only, i.e. not by interfaces.
isTraversableAgain in interface Traversable<T>public Iterator<T> iterator()
Traversablepublic T last()
Traversablelast in interface Traversable<T>public int length()
Traversable
Same as Traversable.size().
public <U> HashSet<U> map(java.util.function.Function<? super T,? extends U> mapper)
TraversableTraversable to elements of a new type preserving their order, if any.public java.lang.String mkString(java.lang.CharSequence prefix,
java.lang.CharSequence delimiter,
java.lang.CharSequence suffix)
Traversable
Example: List.of("a", "b", "c").mkString("Chars(", ", ", ")") = "Chars(a, b, c)"
mkString in interface Traversable<T>prefix - prefix of the resulting stringdelimiter - A delimiter string put between string representations of elements of thissuffix - suffix of the resulting stringpublic HashSet<T> orElse(java.lang.Iterable<? extends T> other)
TraversableTraversable if it is nonempty, otherwise return the alternative.public HashSet<T> orElse(java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
TraversableTraversable if it is nonempty, otherwise return the result of evaluating supplier.public Tuple2<HashSet<T>,HashSet<T>> partition(java.util.function.Predicate<? super T> predicate)
TraversableTraversable by splitting this elements in two in distinct traversables
according to a predicate.partition in interface Set<T>partition in interface Traversable<T>predicate - A predicate which classifies an element if it is in the first or the second traversable.Traversable contains all elements that satisfy the given predicate, the second Traversable contains all elements that don't. The original order of elements is preserved.public HashSet<T> peek(java.util.function.Consumer<? super T> action)
Valueaction on the first element if this is an eager implementation.
Performs the given action on all elements (the first immediately, successive deferred),
if this is a lazy implementation.public HashSet<T> remove(T key)
Setpublic HashSet<T> removeAll(java.lang.Iterable<? extends T> elements)
Setpublic HashSet<T> replace(T currentElement, T newElement)
Traversablereplace in interface Set<T>replace in interface Traversable<T>currentElement - An element to be substituted.newElement - A replacement for currentElement.public HashSet<T> replaceAll(T currentElement, T newElement)
TraversablereplaceAll in interface Set<T>replaceAll in interface Traversable<T>currentElement - An element to be substituted.newElement - A replacement for currentElement.public HashSet<T> retainAll(java.lang.Iterable<? extends T> elements)
Traversablepublic HashSet<T> scan(T zero, java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Traversablescan in interface Set<T>scan in interface Traversable<T>zero - neutral element for the operator opoperation - the associative operator for the scanpublic <U> HashSet<U> scanLeft(U zero, java.util.function.BiFunction<? super U,? super T,? extends U> operation)
TraversablescanLeft in interface Set<T>scanLeft in interface Traversable<T>U - the type of the elements in the resulting collectionzero - the initial valueoperation - the binary operator applied to the intermediate result and the elementpublic <U> HashSet<U> scanRight(U zero, java.util.function.BiFunction<? super T,? super U,? extends U> operation)
TraversablescanRight in interface Set<T>scanRight in interface Traversable<T>U - the type of the elements in the resulting collectionzero - the initial valueoperation - the binary operator applied to the intermediate result and the elementpublic Iterator<HashSet<T>> slideBy(java.util.function.Function<? super T,?> classifier)
TraversableTraversable.
Each window contains elements with the same class, as determined by classifier. Two consecutive
values in this Traversable will be in the same window only if classifier returns equal
values for them. Otherwise, the values will constitute the last element of the previous window and the
first element of the next window.
Examples:
[].slideBy(Function.identity()) = []
[1,2,3,4,4,5].slideBy(Function.identity()) = [[1],[2],[3],[4,4],[5]]
[1,2,3,10,12,5,7,20,29].slideBy(x -> x/10) = [[1,2,3],[10,12],[5,7],[20,29]]
public Iterator<HashSet<T>> sliding(int size)
Traversablesize and step size 1 over this Traversable by calling
Traversable.sliding(int, int).public Iterator<HashSet<T>> sliding(int size, int step)
Traversablesize and step size over this Traversable.
Examples:
[].sliding(1,1) = []
[1,2,3,4,5].sliding(2,3) = [[1,2],[4,5]]
[1,2,3,4,5].sliding(2,4) = [[1,2],[5]]
[1,2,3,4,5].sliding(2,5) = [[1,2]]
[1,2,3,4].sliding(5,3) = [[1,2,3,4]]
public Tuple2<HashSet<T>,HashSet<T>> span(java.util.function.Predicate<? super T> predicate)
Traversablepredicate and the second element is the remainder.public java.util.Spliterator<T> spliterator()
spliterator in interface Traversable<T>spliterator in interface Value<T>spliterator in interface java.lang.Iterable<T>public HashSet<T> tail()
Traversablepublic Option<HashSet<T>> tailOption()
TraversableOption.tailOption in interface Set<T>tailOption in interface Traversable<T>Some(traversable) or None if this is empty.public HashSet<T> take(int n)
Traversable
The result is equivalent to sublist(0, max(0, min(length(), n))) but does not throw if n < 0 or
n > length().
In the case of n < 0 the empty instance is returned, in the case of n > length() this is returned.
public HashSet<T> takeRight(int n)
Traversable
The result is equivalent to sublist(max(0, min(length(), length() - n)), n), i.e. takeRight will not
throw if n < 0 or n > length().
In the case of n < 0 the empty instance is returned, in the case of n > length() this is returned.
public HashSet<T> takeUntil(java.util.function.Predicate<? super T> predicate)
Traversable
Note: This is essentially the same as takeWhile(predicate.negate()). It is intended to be used with
method references, which cannot be negated directly.
public HashSet<T> takeWhile(java.util.function.Predicate<? super T> predicate)
Traversablepublic <U> U transform(java.util.function.Function<? super HashSet<T>,? extends U> f)
HashSet.U - Type of transformation resultf - A transformationUjava.lang.NullPointerException - if f is nullpublic java.util.HashSet<T> toJavaSet()
SetSet to a java.util.Set while preserving characteristics
like insertion order (LinkedHashSet) and sort order (SortedSet).public HashSet<T> union(Set<? extends T> elements)
Setthat set to this set, if not already present.
See also Set.addAll(Iterable).
public <U> HashSet<Tuple2<T,U>> zip(java.lang.Iterable<? extends U> that)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zip in interface Set<T>zip in interface Traversable<T>U - The type of the second half of the returned pairs.that - The Iterable providing the second half of each result pair.that iterable.public <U,R> HashSet<R> zipWith(java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super T,? super U,? extends R> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWith in interface Set<T>zipWith in interface Traversable<T>U - The type of the second parameter of the mapper.R - The type of the mapped elements.that - The Iterable providing the second parameter of the mapper.mapper - a mapper.that iterable.public <U> HashSet<Tuple2<T,U>> zipAll(java.lang.Iterable<? extends U> that, T thisElem, U thatElem)
Traversable
The length of the returned traversable is the maximum of the lengths of this traversable and that
iterable.
Special case: if this traversable is shorter than that elements, and that elements contains duplicates, the resulting traversable may be shorter than the maximum of the lengths of this and that because a traversable contains an element at most once.
If this Traversable is shorter than that, thisElem values are used to fill the result. If that is shorter than this Traversable, thatElem values are used to fill the result.
zipAll in interface Set<T>zipAll in interface Traversable<T>U - The type of the second half of the returned pairs.that - The Iterable providing the second half of each result pair.thisElem - The element to be used to fill up the result if this traversable is shorter than that.thatElem - The element to be used to fill up the result if that is shorter than this traversable.public HashSet<Tuple2<T,java.lang.Integer>> zipWithIndex()
TraversablezipWithIndex in interface Set<T>zipWithIndex in interface Traversable<T>public <U> HashSet<U> zipWithIndex(java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)
TraversablezipWithIndex in interface Set<T>zipWithIndex in interface Traversable<T>U - The type of the mapped elements.mapper - a mapper.public boolean equals(java.lang.Object o)
TraversableNotes:
public int hashCode()
Traversable
int hash = 1;
for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }
Collections with arbitrary iteration order are hashed in a way such that the hash of a fixed number of elements is independent of their iteration order.
int hash = 1;
for (T t : this) { hash += Objects.hashCode(t); }
Please note that the particular hashing algorithms may change in a future version of Vavr.
public final class Hashed<K> {
private final K key;
private final Lazy<Integer> hashCode;
public Hashed(K key) {
this.key = key;
this.hashCode = Lazy.of(() -> Objects.hashCode(key));
}
public K key() {
return key;
}
@Override
public boolean equals(Object o) {
if (o == key) {
return true;
} else if (key != null && o instanceof Hashed) {
final Hashed that = (Hashed) o;
return key.equals(that.key);
} else {
return false;
}
}
@Override
public int hashCode() {
return hashCode.get();
}
@Override
public String toString() {
return "Hashed(" + (key == null ? "null" : key.toString()) + ")";
}
}
public java.lang.String stringPrefix()
ValuestringPrefix in interface Value<T>public java.lang.String toString()
ValueSee Object.toString().