T - Component typepublic final class LinkedHashSet<T> extends Object implements Set<T>, Serializable
HashSet implementation that has predictable (insertion-order) iteration.| Modifier and Type | Method and Description |
|---|---|
LinkedHashSet<T> |
add(T element)
Add the given element to this set, replacing existing one if it is already contained.
|
LinkedHashSet<T> |
addAll(Iterable<? extends T> elements)
Adds all of the given elements to this set, replacing existing one if they are not already contained.
|
<R> LinkedHashSet<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> Collector<T,ArrayList<T>,LinkedHashSet<T>> |
collector()
Returns a
Collector which may be used in conjunction with
Stream.collect(Collector) to obtain a LinkedHashSet. |
boolean |
contains(T element)
Shortcut for
exists(e -> Objects.equals(e, element)), tests if the given element is contained. |
LinkedHashSet<T> |
diff(Set<? extends T> elements)
Calculates the difference between this set and another set.
|
LinkedHashSet<T> |
distinct()
Returns a new version of this which contains no duplicates.
|
LinkedHashSet<T> |
distinctBy(Comparator<? super T> comparator)
Returns a new version of this which contains no duplicates.
|
<U> LinkedHashSet<T> |
distinctBy(Function<? super T,? extends U> keyExtractor)
Returns a new version of this which contains no duplicates.
|
LinkedHashSet<T> |
drop(int n)
Drops the first n elements of this or all elements, if this length < n.
|
LinkedHashSet<T> |
dropRight(int n)
Drops the last n elements of this or all elements, if this length < n.
|
LinkedHashSet<T> |
dropUntil(Predicate<? super T> predicate)
Drops elements until the predicate holds for the current element.
|
LinkedHashSet<T> |
dropWhile(Predicate<? super T> predicate)
Drops elements while the predicate holds for the current element.
|
static <T> LinkedHashSet<T> |
empty() |
boolean |
equals(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> LinkedHashSet<T> |
fill(int n,
Supplier<? extends T> s)
Returns a LinkedHashSet containing tuples returned by
n calls to a given Supplier s. |
LinkedHashSet<T> |
filter(Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which satisfy the given predicate.
|
<U> LinkedHashSet<U> |
flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
FlatMaps this Traversable.
|
<U> U |
foldRight(U zero,
BiFunction<? super T,? super U,? extends U> f)
Folds this elements from the right, starting with
zero and successively calling combine. |
<C> Map<C,LinkedHashSet<T>> |
groupBy(Function<? super T,? extends C> classifier)
Groups this elements by classifying the elements.
|
Iterator<LinkedHashSet<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. |
LinkedHashSet<T> |
init()
Dual of Traversable.tail(), returning all elements except the last.
|
Option<LinkedHashSet<T>> |
initOption()
Dual of Traversable.tailOption(), returning all elements except the last as
Option. |
LinkedHashSet<T> |
intersect(Set<? extends T> elements)
Computes the intersection between this set and another set.
|
boolean |
isAsync()
An
LinkedHashSet's value is computed synchronously. |
boolean |
isEmpty()
Checks if this Traversable is empty.
|
boolean |
isLazy()
An
LinkedHashSet's value is computed eagerly. |
boolean |
isSequential()
Checks if the elements of this Traversable appear in encounter order.
|
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> LinkedHashSet<U> |
map(Function<? super T,? extends U> mapper)
Maps the elements of this
Traversable to elements of a new type preserving their order, if any. |
String |
mkString(CharSequence prefix,
CharSequence delimiter,
CharSequence suffix)
Joins the string representations of this elements using a specific delimiter, prefix and suffix.
|
static <T> LinkedHashSet<T> |
narrow(LinkedHashSet<? extends T> linkedHashSet)
Narrows a widened
LinkedHashSet<? extends T> to LinkedHashSet<T>
by performing a type-safe cast. |
static <T> LinkedHashSet<T> |
of(T... elements)
Creates a LinkedHashSet of the given elements.
|
static <T> LinkedHashSet<T> |
of(T element)
Returns a singleton
LinkedHashSet, i.e. |
static LinkedHashSet<Boolean> |
ofAll(boolean... elements)
Creates a LinkedHashSet from boolean values.
|
static LinkedHashSet<Byte> |
ofAll(byte... elements)
Creates a LinkedHashSet from byte values.
|
static LinkedHashSet<Character> |
ofAll(char... elements)
Creates a LinkedHashSet from char values.
|
static LinkedHashSet<Double> |
ofAll(double... elements)
Creates a LinkedHashSet from double values.
|
static LinkedHashSet<Float> |
ofAll(float... elements)
Creates a LinkedHashSet from float values.
|
static LinkedHashSet<Integer> |
ofAll(int... elements)
Creates a LinkedHashSet from int values.
|
static <T> LinkedHashSet<T> |
ofAll(Iterable<? extends T> elements)
Creates a LinkedHashSet of the given elements.
|
static LinkedHashSet<Long> |
ofAll(long... elements)
Creates a LinkedHashSet from long values.
|
static LinkedHashSet<Short> |
ofAll(short... elements)
Creates a LinkedHashSet from short values.
|
static <T> LinkedHashSet<T> |
ofAll(Stream<? extends T> javaStream)
Creates a LinkedHashSet that contains the elements of the given
Stream. |
LinkedHashSet<T> |
orElse(Iterable<? extends T> other)
Returns this
Traversable if it is nonempty, otherwise return the alternative. |
LinkedHashSet<T> |
orElse(Supplier<? extends Iterable<? extends T>> supplier)
Returns this
Traversable if it is nonempty, otherwise return the result of evaluating supplier. |
Tuple2<LinkedHashSet<T>,LinkedHashSet<T>> |
partition(Predicate<? super T> predicate)
Creates a partition of this
Traversable by splitting this elements in two in distinct traversables
according to a predicate. |
LinkedHashSet<T> |
peek(Consumer<? super T> action)
Performs the given
action on the first element if this is an eager implementation. |
static LinkedHashSet<Character> |
range(char from,
char toExclusive) |
static LinkedHashSet<Integer> |
range(int from,
int toExclusive)
Creates a LinkedHashSet of int numbers starting from
from, extending to toExclusive - 1. |
static LinkedHashSet<Long> |
range(long from,
long toExclusive)
Creates a LinkedHashSet of long numbers starting from
from, extending to toExclusive - 1. |
static LinkedHashSet<Character> |
rangeBy(char from,
char toExclusive,
int step) |
static LinkedHashSet<Double> |
rangeBy(double from,
double toExclusive,
double step) |
static LinkedHashSet<Integer> |
rangeBy(int from,
int toExclusive,
int step)
Creates a LinkedHashSet of int numbers starting from
from, extending to toExclusive - 1,
with step. |
static LinkedHashSet<Long> |
rangeBy(long from,
long toExclusive,
long step)
Creates a LinkedHashSet of long numbers starting from
from, extending to toExclusive - 1,
with step. |
static LinkedHashSet<Character> |
rangeClosed(char from,
char toInclusive) |
static LinkedHashSet<Integer> |
rangeClosed(int from,
int toInclusive)
Creates a LinkedHashSet of int numbers starting from
from, extending to toInclusive. |
static LinkedHashSet<Long> |
rangeClosed(long from,
long toInclusive)
Creates a LinkedHashSet of long numbers starting from
from, extending to toInclusive. |
static LinkedHashSet<Character> |
rangeClosedBy(char from,
char toInclusive,
int step) |
static LinkedHashSet<Double> |
rangeClosedBy(double from,
double toInclusive,
double step) |
static LinkedHashSet<Integer> |
rangeClosedBy(int from,
int toInclusive,
int step)
Creates a LinkedHashSet of int numbers starting from
from, extending to toInclusive,
with step. |
static LinkedHashSet<Long> |
rangeClosedBy(long from,
long toInclusive,
long step)
Creates a LinkedHashSet of long numbers starting from
from, extending to toInclusive,
with step. |
LinkedHashSet<T> |
reject(Predicate<? super T> predicate)
Returns a new traversable consisting of all elements which do not satisfy the given predicate.
|
LinkedHashSet<T> |
remove(T element)
Removes a specific element from this set, if present.
|
LinkedHashSet<T> |
removeAll(Iterable<? extends T> elements)
Removes all of the given elements from this set, if present.
|
LinkedHashSet<T> |
replace(T currentElement,
T newElement)
Replaces the first occurrence (if exists) of the given currentElement with newElement.
|
LinkedHashSet<T> |
replaceAll(T currentElement,
T newElement)
Replaces all occurrences of the given currentElement with newElement.
|
LinkedHashSet<T> |
retainAll(Iterable<? extends T> elements)
Keeps all occurrences of the given elements from this.
|
LinkedHashSet<T> |
scan(T zero,
BiFunction<? super T,? super T,? extends T> operation)
Computes a prefix scan of the elements of the collection.
|
<U> LinkedHashSet<U> |
scanLeft(U zero,
BiFunction<? super U,? super T,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going left to right.
|
<U> LinkedHashSet<U> |
scanRight(U zero,
BiFunction<? super T,? super U,? extends U> operation)
Produces a collection containing cumulative results of applying the
operator going right to left.
|
Iterator<LinkedHashSet<T>> |
slideBy(Function<? super T,?> classifier)
Slides a non-overlapping window of a variable size over this
Traversable. |
Iterator<LinkedHashSet<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<LinkedHashSet<T>> |
sliding(int size,
int step)
Slides a window of a specific
size and step size over this Traversable. |
Tuple2<LinkedHashSet<T>,LinkedHashSet<T>> |
span(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. |
String |
stringPrefix()
Returns the name of this Value type, which is used by toString().
|
static <T> LinkedHashSet<T> |
tabulate(int n,
Function<? super Integer,? extends T> f)
Returns a LinkedHashSet containing
n values of a given Function f
over a range of integer values from 0 to n - 1. |
LinkedHashSet<T> |
tail()
Drops the first element of a non-empty Traversable.
|
Option<LinkedHashSet<T>> |
tailOption()
Drops the first element of a non-empty Traversable and returns an
Option. |
LinkedHashSet<T> |
take(int n)
Takes the first n elements of this or all elements, if this length < n.
|
LinkedHashSet<T> |
takeRight(int n)
Takes the last n elements of this or all elements, if this length < n.
|
LinkedHashSet<T> |
takeUntil(Predicate<? super T> predicate)
Takes elements until the predicate holds for the current element.
|
LinkedHashSet<T> |
takeWhile(Predicate<? super T> predicate)
Takes elements while the predicate holds for the current element.
|
LinkedHashSet<T> |
toJavaSet()
Converts this Vavr
Set to a java.util.Set while preserving characteristics
like insertion order (LinkedHashSet) and sort order (SortedSet). |
String |
toString()
Clarifies that values have a proper toString() method implemented.
|
<U> U |
transform(Function<? super LinkedHashSet<T>,? extends U> f)
Transforms this
LinkedHashSet. |
LinkedHashSet<T> |
union(Set<? extends T> elements)
Adds all of the elements of
elements to this set, replacing existing ones if they already present. |
<T1,T2> Tuple2<LinkedHashSet<T1>,LinkedHashSet<T2>> |
unzip(Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct
sets.
|
<T1,T2,T3> Tuple3<LinkedHashSet<T1>,LinkedHashSet<T2>,LinkedHashSet<T3>> |
unzip3(Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Unzips this elements by mapping this elements to triples which are subsequently split into three distinct
sets.
|
<U> LinkedHashSet<Tuple2<T,U>> |
zip(Iterable<? extends U> that)
Returns a traversable formed from this traversable and another Iterable collection by combining
corresponding elements in pairs.
|
<U> LinkedHashSet<Tuple2<T,U>> |
zipAll(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> LinkedHashSet<R> |
zipWith(Iterable<? extends U> that,
BiFunction<? super T,? super U,? extends R> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
LinkedHashSet<Tuple2<T,Integer>> |
zipWithIndex()
Zips this traversable with its indices.
|
<U> LinkedHashSet<U> |
zipWithIndex(BiFunction<? super T,? super Integer,? extends U> mapper)
Returns a traversable formed from this traversable and another Iterable collection by mapping elements.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitapply, isDistinct, narrowarrangeBy, average, containsAll, count, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, isOrdered, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, narrow, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sumfold, reduce, reduceOptioncollect, 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> LinkedHashSet<T> empty()
public static <T> Collector<T,ArrayList<T>,LinkedHashSet<T>> collector()
Collector which may be used in conjunction with
Stream.collect(Collector) to obtain a LinkedHashSet.T - Component type of the LinkedHashSet.public static <T> LinkedHashSet<T> narrow(LinkedHashSet<? extends T> linkedHashSet)
LinkedHashSet<? extends T> to LinkedHashSet<T>
by performing a type-safe cast. This is eligible because immutable/read-only
collections are covariant.T - Component type of the linkedHashSet.linkedHashSet - A LinkedHashSet.linkedHashSet instance as narrowed type LinkedHashSet<T>.public static <T> LinkedHashSet<T> of(T element)
LinkedHashSet, i.e. a LinkedHashSet of one element.@SafeVarargs public static <T> LinkedHashSet<T> of(T... elements)
LinkedHashSet.of(1, 2, 3, 4)T - Component type of the LinkedHashSet.elements - Zero or more elements.NullPointerException - if elements is nullpublic static <T> LinkedHashSet<T> tabulate(int n, Function<? super 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 LinkedHashSetn - The number of elements in the LinkedHashSetf - The Function computing element valuesf(0),f(1), ..., f(n - 1)NullPointerException - if f is nullpublic static <T> LinkedHashSet<T> fill(int n, Supplier<? extends T> s)
n calls to a given Supplier s.T - Component type of the LinkedHashSetn - The number of elements in the LinkedHashSets - The Supplier computing element valuesn, where each element contains the result supplied by s.NullPointerException - if s is nullpublic static <T> LinkedHashSet<T> ofAll(Iterable<? extends T> elements)
T - The value typeelements - Set elementspublic static <T> LinkedHashSet<T> ofAll(Stream<? extends T> javaStream)
Stream.T - Component type of the Stream.javaStream - A Streampublic static LinkedHashSet<Boolean> ofAll(boolean... elements)
elements - boolean valuesNullPointerException - if elements is nullpublic static LinkedHashSet<Byte> ofAll(byte... elements)
elements - byte valuesNullPointerException - if elements is nullpublic static LinkedHashSet<Character> ofAll(char... elements)
elements - char valuesNullPointerException - if elements is nullpublic static LinkedHashSet<Double> ofAll(double... elements)
elements - double valuesNullPointerException - if elements is nullpublic static LinkedHashSet<Float> ofAll(float... elements)
elements - a float valuesNullPointerException - if elements is nullpublic static LinkedHashSet<Integer> ofAll(int... elements)
elements - int valuesNullPointerException - if elements is nullpublic static LinkedHashSet<Long> ofAll(long... elements)
elements - long valuesNullPointerException - if elements is nullpublic static LinkedHashSet<Short> ofAll(short... elements)
elements - short valuesNullPointerException - if elements is nullpublic static LinkedHashSet<Integer> range(int from, int toExclusive)
from, extending to toExclusive - 1.
Examples:
LinkedHashSet.range(0, 0) // = LinkedHashSet()
LinkedHashSet.range(2, 0) // = LinkedHashSet()
LinkedHashSet.range(-2, 2) // = LinkedHashSet(-2, -1, 0, 1)
from - the first numbertoExclusive - the last number + 1from >= toExclusivepublic static LinkedHashSet<Character> range(char from, char toExclusive)
public static LinkedHashSet<Integer> rangeBy(int from, int toExclusive, int step)
from, extending to toExclusive - 1,
with step.
Examples:
LinkedHashSet.rangeBy(1, 3, 1) // = LinkedHashSet(1, 2)
LinkedHashSet.rangeBy(1, 4, 2) // = LinkedHashSet(1, 3)
LinkedHashSet.rangeBy(4, 1, -2) // = LinkedHashSet(4, 2)
LinkedHashSet.rangeBy(4, 1, 2) // = LinkedHashSet()
from - the first numbertoExclusive - the last number + 1step - the stepfrom >= toInclusive and step > 0 orfrom <= toInclusive and step < 0IllegalArgumentException - if step is zeropublic static LinkedHashSet<Character> rangeBy(char from, char toExclusive, int step)
@GwtIncompatible public static LinkedHashSet<Double> rangeBy(double from, double toExclusive, double step)
public static LinkedHashSet<Long> range(long from, long toExclusive)
from, extending to toExclusive - 1.
Examples:
LinkedHashSet.range(0L, 0L) // = LinkedHashSet()
LinkedHashSet.range(2L, 0L) // = LinkedHashSet()
LinkedHashSet.range(-2L, 2L) // = LinkedHashSet(-2L, -1L, 0L, 1L)
from - the first numbertoExclusive - the last number + 1from >= toExclusivepublic static LinkedHashSet<Long> rangeBy(long from, long toExclusive, long step)
from, extending to toExclusive - 1,
with step.
Examples:
LinkedHashSet.rangeBy(1L, 3L, 1L) // = LinkedHashSet(1L, 2L)
LinkedHashSet.rangeBy(1L, 4L, 2L) // = LinkedHashSet(1L, 3L)
LinkedHashSet.rangeBy(4L, 1L, -2L) // = LinkedHashSet(4L, 2L)
LinkedHashSet.rangeBy(4L, 1L, 2L) // = LinkedHashSet()
from - the first numbertoExclusive - the last number + 1step - the stepfrom >= toInclusive and step > 0 orfrom <= toInclusive and step < 0IllegalArgumentException - if step is zeropublic static LinkedHashSet<Integer> rangeClosed(int from, int toInclusive)
from, extending to toInclusive.
Examples:
LinkedHashSet.rangeClosed(0, 0) // = LinkedHashSet(0)
LinkedHashSet.rangeClosed(2, 0) // = LinkedHashSet()
LinkedHashSet.rangeClosed(-2, 2) // = LinkedHashSet(-2, -1, 0, 1, 2)
from - the first numbertoInclusive - the last numberfrom > toInclusivepublic static LinkedHashSet<Character> rangeClosed(char from, char toInclusive)
public static LinkedHashSet<Integer> rangeClosedBy(int from, int toInclusive, int step)
from, extending to toInclusive,
with step.
Examples:
LinkedHashSet.rangeClosedBy(1, 3, 1) // = LinkedHashSet(1, 2, 3)
LinkedHashSet.rangeClosedBy(1, 4, 2) // = LinkedHashSet(1, 3)
LinkedHashSet.rangeClosedBy(4, 1, -2) // = LinkedHashSet(4, 2)
LinkedHashSet.rangeClosedBy(4, 1, 2) // = LinkedHashSet()
from - the first numbertoInclusive - the last numberstep - the stepfrom > toInclusive and step > 0 orfrom < toInclusive and step < 0IllegalArgumentException - if step is zeropublic static LinkedHashSet<Character> rangeClosedBy(char from, char toInclusive, int step)
@GwtIncompatible public static LinkedHashSet<Double> rangeClosedBy(double from, double toInclusive, double step)
public static LinkedHashSet<Long> rangeClosed(long from, long toInclusive)
from, extending to toInclusive.
Examples:
LinkedHashSet.rangeClosed(0L, 0L) // = LinkedHashSet(0L)
LinkedHashSet.rangeClosed(2L, 0L) // = LinkedHashSet()
LinkedHashSet.rangeClosed(-2L, 2L) // = LinkedHashSet(-2L, -1L, 0L, 1L, 2L)
from - the first numbertoInclusive - the last numberfrom > toInclusivepublic static LinkedHashSet<Long> rangeClosedBy(long from, long toInclusive, long step)
from, extending to toInclusive,
with step.
Examples:
LinkedHashSet.rangeClosedBy(1L, 3L, 1L) // = LinkedHashSet(1L, 2L, 3L)
LinkedHashSet.rangeClosedBy(1L, 4L, 2L) // = LinkedHashSet(1L, 3L)
LinkedHashSet.rangeClosedBy(4L, 1L, -2L) // = LinkedHashSet(4L, 2L)
LinkedHashSet.rangeClosedBy(4L, 1L, 2L) // = LinkedHashSet()
from - the first numbertoInclusive - the last numberstep - the stepfrom > toInclusive and step > 0 orfrom < toInclusive and step < 0IllegalArgumentException - if step is zeropublic LinkedHashSet<T> add(T element)
Note that this method has a worst-case linear complexity.
public LinkedHashSet<T> addAll(Iterable<? extends T> elements)
Note that this method has a worst-case quadratic complexity.
public <R> LinkedHashSet<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 LinkedHashSet<T> diff(Set<? extends T> elements)
Set
See also Set.removeAll(Iterable).
public LinkedHashSet<T> distinct()
Traversableequals.public LinkedHashSet<T> distinctBy(Comparator<? super T> comparator)
Traversablecomparator.distinctBy in interface Set<T>distinctBy in interface Traversable<T>comparator - A comparatorTraversable containing this elements without duplicatespublic <U> LinkedHashSet<T> distinctBy(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 LinkedHashSet<T> drop(int n)
Traversablepublic LinkedHashSet<T> dropRight(int n)
Traversablepublic LinkedHashSet<T> dropUntil(Predicate<? super T> predicate)
Traversablepublic LinkedHashSet<T> dropWhile(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 LinkedHashSet<T> filter(Predicate<? super T> predicate)
Traversablepublic LinkedHashSet<T> reject(Predicate<? super T> predicate)
TraversableThe default implementation is equivalent to
filter(predicate.negate()public <U> LinkedHashSet<U> flatMap(Function<? super T,? extends Iterable<? extends U>> mapper)
Traversablepublic <U> U foldRight(U zero,
BiFunction<? super T,? super U,? extends U> f)
Foldablezero and successively calling combine.
Example:
// = "!cba"
List("a", "b", "c").foldRight("!", (x, xs) -> xs + x)
public <C> Map<C,LinkedHashSet<T>> groupBy(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<LinkedHashSet<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 LinkedHashSet<T> init()
Traversablepublic Option<LinkedHashSet<T>> initOption()
TraversableOption.initOption in interface Set<T>initOption in interface Traversable<T>Some(traversable) or None if this is empty.public LinkedHashSet<T> intersect(Set<? extends T> elements)
Set
See also Set.retainAll(Iterable).
public boolean isAsync()
LinkedHashSet's value is computed synchronously.public boolean isEmpty()
Traversablepublic boolean isLazy()
LinkedHashSet's value 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 boolean isSequential()
TraversableisSequential 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> LinkedHashSet<U> map(Function<? super T,? extends U> mapper)
TraversableTraversable to elements of a new type preserving their order, if any.public String mkString(CharSequence prefix, CharSequence delimiter, 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 LinkedHashSet<T> orElse(Iterable<? extends T> other)
TraversableTraversable if it is nonempty, otherwise return the alternative.public LinkedHashSet<T> orElse(Supplier<? extends Iterable<? extends T>> supplier)
TraversableTraversable if it is nonempty, otherwise return the result of evaluating supplier.public Tuple2<LinkedHashSet<T>,LinkedHashSet<T>> partition(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 LinkedHashSet<T> peek(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 LinkedHashSet<T> remove(T element)
Setpublic LinkedHashSet<T> removeAll(Iterable<? extends T> elements)
Setpublic LinkedHashSet<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 LinkedHashSet<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 LinkedHashSet<T> retainAll(Iterable<? extends T> elements)
Traversablepublic LinkedHashSet<T> scan(T zero, 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> LinkedHashSet<U> scanLeft(U zero, 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> LinkedHashSet<U> scanRight(U zero, 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<LinkedHashSet<T>> slideBy(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<LinkedHashSet<T>> sliding(int size)
Traversablesize and step size 1 over this Traversable by calling
Traversable.sliding(int, int).public Iterator<LinkedHashSet<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],[4]]
public Tuple2<LinkedHashSet<T>,LinkedHashSet<T>> span(Predicate<? super T> predicate)
Traversablepredicate and the second element is the remainder.public LinkedHashSet<T> tail()
Traversablepublic Option<LinkedHashSet<T>> tailOption()
TraversableOption.tailOption in interface Set<T>tailOption in interface Traversable<T>Some(traversable) or None if this is empty.public LinkedHashSet<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 LinkedHashSet<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 LinkedHashSet<T> takeUntil(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 LinkedHashSet<T> takeWhile(Predicate<? super T> predicate)
Traversablepublic <U> U transform(Function<? super LinkedHashSet<T>,? extends U> f)
LinkedHashSet.U - Type of transformation resultf - A transformationUNullPointerException - if f is nullpublic LinkedHashSet<T> toJavaSet()
SetSet to a java.util.Set while preserving characteristics
like insertion order (LinkedHashSet) and sort order (SortedSet).public LinkedHashSet<T> union(Set<? extends T> elements)
elements to this set, replacing existing ones if they already present.
Note that this method has a worst-case quadratic complexity.
See also addAll(Iterable).
public <T1,T2> Tuple2<LinkedHashSet<T1>,LinkedHashSet<T2>> unzip(Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Traversableunzip in interface Set<T>unzip in interface Traversable<T>T1 - 1st element type of a pair returned by unzipperT2 - 2nd element type of a pair returned by unzipperunzipper - a function which converts elements of this to pairspublic <T1,T2,T3> Tuple3<LinkedHashSet<T1>,LinkedHashSet<T2>,LinkedHashSet<T3>> unzip3(Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Traversableunzip3 in interface Set<T>unzip3 in interface Traversable<T>T1 - 1st element type of a triplet returned by unzipperT2 - 2nd element type of a triplet returned by unzipperT3 - 3rd element type of a triplet returned by unzipperunzipper - a function which converts elements of this to pairspublic <U> LinkedHashSet<Tuple2<T,U>> zip(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> LinkedHashSet<R> zipWith(Iterable<? extends U> that, 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> LinkedHashSet<Tuple2<T,U>> zipAll(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 LinkedHashSet<Tuple2<T,Integer>> zipWithIndex()
TraversablezipWithIndex in interface Set<T>zipWithIndex in interface Traversable<T>public <U> LinkedHashSet<U> zipWithIndex(BiFunction<? super T,? super Integer,? extends U> mapper)
Traversable
The length of the returned traversable is the minimum of the lengths of this traversable and that
iterable.
zipWithIndex in interface Set<T>zipWithIndex in interface Traversable<T>U - The type of the mapped elements.mapper - a mapper.that iterable.public boolean equals(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 String stringPrefix()
ValuestringPrefix in interface Value<T>Copyright © 2020. All Rights Reserved.