Top Description Fields Constructors Methods
io.vavr.collection

public final Class TreeSet<T>

extends Object
implements SortedSet<T>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, io.vavr.collection.SortedSet, io.vavr.collection.Ordered, io.vavr.collection.Set, io.vavr.Function1, java.util.function.Function, io.vavr.collection.Traversable, io.vavr.Value, java.lang.Iterable, io.vavr.collection.Foldable
Type Parameters
<T>
Component type
Imports
io.vavr.*, io.vavr.control.Option, java.io.Serializable, java.util.ArrayList, .Comparator, .NoSuchElementException, .Objects, java.util.function.*, java.util.stream.Collector

SortedSet implementation, backed by a Red/Black Tree.
Author
Daniel Dietrich

Field Summary

Modifier and TypeField and Description
private static final long
private final RedBlackTree<T>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public TreeSet<T>
add(T
The element to be added.
element
)

Implements io.vavr.collection.SortedSet.add.

Add the given element to this set, if it is not already contained.

public TreeSet<T>
addAll(Iterable<? extends T>
The elements to be added.
elements
)

Implements io.vavr.collection.SortedSet.addAll.

Adds all of the given elements to this set, if not already contained.

public <R> TreeSet<R>
collect(PartialFunction<? super T, ? extends R>
A function that is not necessarily defined of all elements of this traversable.
partialFunction
)

Implements io.vavr.collection.SortedSet.collect.

Collects all elements that are in the domain of the given partialFunction by mapping the elements to type R.

public static <
Component type of the List.
T extends Comparable<? super T>
>
Collector<T, ArrayList<T>, TreeSet<T>>

Returns:

A io.vavr.collection.List Collector.
collector
()

Returns a java.util.stream.Collector which may be used in conjunction with java.util.stream.Stream#collect(java.util.stream.Collector) to obtain a TreeSet.

public static <
Component type of the List.
T
>
Collector<T, ArrayList<T>, TreeSet<T>>

Returns:

A io.vavr.collection.List Collector.
collector
(Comparator<? super T>
An element comparator
comparator
)

Returns a java.util.stream.Collector which may be used in conjunction with java.util.stream.Stream#collect(java.util.stream.Collector) to obtain a TreeSet.

public Comparator<T>
comparator()

Implements io.vavr.collection.Ordered.comparator.

Returns the comparator which defines the order of the elements contained in this collection.

public boolean
contains(T
An Object of type A, may be null.
element
)

Implements io.vavr.collection.Set.contains.

Shortcut for exists(e -> Objects.equals(e, element)), tests if the given element is contained.

public TreeSet<T>
diff(Set<? extends T>
Elements to be removed from this set.
elements
)

Implements io.vavr.collection.SortedSet.diff.

Calculates the difference between this set and another set.

public TreeSet<T>
distinct()

Implements io.vavr.collection.SortedSet.distinct.

Returns a new version of this which contains no duplicates.

public TreeSet<T>
distinctBy(Comparator<? super T>
A comparator
comparator
)

Implements io.vavr.collection.SortedSet.distinctBy.

Returns a new version of this which contains no duplicates.

public <U> TreeSet<T>
distinctBy(Function<? super T, ? extends U>
A key extractor
keyExtractor
)

Implements io.vavr.collection.SortedSet.distinctBy.

Returns a new version of this which contains no duplicates.

public TreeSet<T>
drop(int
The number of elements to drop.
n
)

Implements io.vavr.collection.SortedSet.drop.

Drops the first n elements of this or all elements, if this length < n.

public TreeSet<T>
dropRight(int
The number of elements to drop.
n
)

Implements io.vavr.collection.SortedSet.dropRight.

Drops the last n elements of this or all elements, if this length < n.

public TreeSet<T>
dropUntil(Predicate<? super T>
A condition tested subsequently for this elements.
predicate
)

Implements io.vavr.collection.SortedSet.dropUntil.

Drops elements until the predicate holds for the current element.

public TreeSet<T>
dropWhile(Predicate<? super T>
A condition tested subsequently for this elements.
predicate
)

Implements io.vavr.collection.SortedSet.dropWhile.

Drops elements while the predicate holds for the current element.

public static <T extends Comparable<? super T>> TreeSet<T>
public static <T> TreeSet<T>
empty(Comparator<? super T> comparator)

public boolean
equals(Object
an object, may be null
o
)

Overrides java.lang.Object.equals.

Implements io.vavr.collection.Traversable.equals.

In Vavr there are four basic classes of collections:

  • Seq (sequential elements)
  • Set (distinct elements)
  • Map (indexed elements)
  • Multimap (indexed collections)
public static <
Component type of the TreeSet
T
>
TreeSet<T>

Returns:

A TreeSet of size n, where each element contains the result supplied by s.
fill
(Comparator<? super T>
The comparator used to sort the elements
comparator
,
int
The number of elements in the TreeSet
n
,
Supplier<? extends T>
The Supplier computing element values
s
)

Returns a TreeSet containing tuples returned by n calls to a given Supplier s.

public static <
Component type of the TreeSet
T extends Comparable<? super T>
>
TreeSet<T>

Returns:

A TreeSet of size n, where each element contains the result supplied by s.
fill
(int
The number of elements in the TreeSet
n
,
Supplier<? extends T>
The Supplier computing element values
s
)

Returns a TreeSet containing tuples returned by n calls to a given Supplier s.

public TreeSet<T>
filter(Predicate<? super T>
A predicate
predicate
)

Implements io.vavr.collection.SortedSet.filter.

Returns a new traversable consisting of all elements which satisfy the given predicate.

public <U> TreeSet<U>
flatMap(Comparator<? super U>
A comparator for values of type U
comparator
,
Function<? super T, ? extends Iterable<? extends U>>
A function which maps values of type T to Iterables of values of type U
mapper
)

Implements io.vavr.collection.SortedSet.flatMap.

Same as flatMap(Function) but using a specific comparator for values of the codomain of the given mapper.

public <U> TreeSet<U>
flatMap(Function<? super T, ? extends Iterable<? extends U>>
A mapper
mapper
)

Implements io.vavr.collection.SortedSet.flatMap.

FlatMaps this Traversable.

public <U> U
foldRight(U
A zero element to start with.
zero
,
BiFunction<? super T, ? super U, ? extends U>
A function which combines elements.
f
)

Implements io.vavr.collection.Traversable.foldRight.

Folds this elements from the right, starting with zero and successively calling combine.

public <C> Map<C, TreeSet<T>>
groupBy(Function<? super T, ? extends C>
A function which classifies elements into classes
classifier
)

Implements io.vavr.collection.SortedSet.groupBy.

Groups this elements by classifying the elements.

public Iterator<TreeSet<T>>
grouped(int
a positive block size
size
)

Implements io.vavr.collection.SortedSet.grouped.

Groups this Traversable into fixed size blocks.

public boolean
hasDefiniteSize()

Implements io.vavr.collection.Traversable.hasDefiniteSize.

Checks if this Traversable is known to have a finite size.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements io.vavr.collection.Traversable.hashCode.

Returns the hash code of this collection.

public T
head()

Implements io.vavr.collection.Traversable.head.

Returns the first element of a non-empty Traversable.

public Option<T>
headOption()

Overrides default io.vavr.collection.Traversable.headOption.

Returns the first element of a non-empty Traversable as Option.

public TreeSet<T>
init()

Implements io.vavr.collection.SortedSet.init.

Dual of tail(), returning all elements except the last.

public Option<TreeSet<T>>
initOption()

Implements io.vavr.collection.SortedSet.initOption.

Dual of tailOption(), returning all elements except the last as Option.

public TreeSet<T>
intersect(Set<? extends T>
the set to intersect with.
elements
)

Implements io.vavr.collection.SortedSet.intersect.

Computes the intersection between this set and another set.

public boolean

Returns:

false
isAsync
()

Implements io.vavr.Value.isAsync.

A TreeSet is computed synchronously.

public boolean
isEmpty()

Overrides default io.vavr.collection.Traversable.isEmpty.

Checks if this Traversable is empty.

public boolean

Returns:

false
isLazy
()

Implements io.vavr.Value.isLazy.

A TreeSet is computed eagerly.

public boolean
isTraversableAgain()

Implements io.vavr.collection.Traversable.isTraversableAgain.

Checks if this Traversable can be repeatedly traversed.

public Iterator<T>
iterator()

Implements io.vavr.collection.Set.iterator.

An iterator by means of head() and tail().

public T
last()

Implements io.vavr.collection.Traversable.last.

Dual of head(), returning the last element.

public int
length()

Implements io.vavr.collection.Set.length.

Computes the number of elements of this Traversable.

public <U> TreeSet<U>
map(Comparator<? super U>
A comparator for values of type U
comparator
,
Function<? super T, ? extends U>
A function which maps values of type T to values of type U
mapper
)

Implements io.vavr.collection.SortedSet.map.

Same as map(Function) but using a specific comparator for values of the codomain of the given mapper.

public <U> TreeSet<U>
map(Function<? super T, ? extends U>
A mapper.
mapper
)

Implements io.vavr.collection.SortedSet.map.

Maps the elements of this Traversable to elements of a new type preserving their order, if any.

public static <
Component type of the TreeSet.
T
>
TreeSet<T>

Returns:

the given treeSet instance as narrowed type TreeSet<T>.
narrow
(TreeSet<? extends T>
A TreeSet.
treeSet
)

Narrows a widened TreeSet<?

public static <T extends Comparable<? super T>> TreeSet<T>
of(T value)

public static <T> TreeSet<T>
of(Comparator<? super T> comparator, T value)

public static <T extends Comparable<? super T>> TreeSet<T>
of(T... values)

public static <T> TreeSet<T>
of(Comparator<? super T> comparator, T... values)

public static <T extends Comparable<? super T>> TreeSet<T>
ofAll(Iterable<? extends T> values)

public static <T> TreeSet<T>
ofAll(Comparator<? super T> comparator, Iterable<? extends T> values)

public static <T extends Comparable<? super T>> TreeSet<T>
ofAll(Stream<? extends T> javaStream)

public static <T> TreeSet<T>
ofAll(Comparator<? super T> comparator, Stream<? extends T> javaStream)

public static TreeSet<Boolean>

Returns:

A new TreeSet of Boolean values
ofAll
(boolean...
boolean values
elements
)

Creates a TreeSet from boolean values.

public static TreeSet<Byte>

Returns:

A new TreeSet of Byte values
ofAll
(byte...
byte values
elements
)

Creates a TreeSet from byte values.

public static TreeSet<Character>

Returns:

A new TreeSet of Character values
ofAll
(char...
char values
elements
)

Creates a TreeSet from char values.

public static TreeSet<Double>

Returns:

A new TreeSet of Double values
ofAll
(double...
double values
elements
)

Creates a TreeSet from double values.

public static TreeSet<Float>

Returns:

A new TreeSet of Float values
ofAll
(float...
float values
elements
)

Creates a TreeSet from float values.

public static TreeSet<Integer>

Returns:

A new TreeSet of Integer values
ofAll
(int...
int values
elements
)

Creates a TreeSet from int values.

public static TreeSet<Long>

Returns:

A new TreeSet of Long values
ofAll
(long...
long values
elements
)

Creates a TreeSet from long values.

public static TreeSet<Short>

Returns:

A new TreeSet of Short values
ofAll
(short...
short values
elements
)

Creates a TreeSet from short values.

public TreeSet<T>

Returns:

this TreeSet if it is nonempty, otherwise TreeSet created from iterable, using existing comparator.
orElse
(Iterable<? extends T>
An alternative Traversable
other
)

Implements io.vavr.collection.SortedSet.orElse.

Returns this TreeSet if it is nonempty, otherwise TreeSet created from iterable, using existing comparator.

public TreeSet<T>

Returns:

this TreeSet if it is nonempty, otherwise TreeSet created from result of evaluating supplier, using existing comparator.
orElse
(Supplier<? extends Iterable<? extends T>>
An alternative Traversable
supplier
)

Implements io.vavr.collection.SortedSet.orElse.

Returns this TreeSet if it is nonempty, otherwise TreeSet created from result of evaluating supplier, using existing comparator.

public Tuple2<TreeSet<T>, TreeSet<T>>
partition(Predicate<? super T>
A predicate which classifies an element if it is in the first or the second traversable.
predicate
)

Implements io.vavr.collection.SortedSet.partition.

Creates a partition of this Traversable by splitting this elements in two in distinct traversables according to a predicate.

public TreeSet<T>
peek(Consumer<? super T>
The action that will be performed on the element(s).
action
)

Implements io.vavr.collection.SortedSet.peek.

Performs the given action on the first element if this is an eager implementation.

public static TreeSet<Integer>

Returns:

a range of int values as specified or the empty range if from >= toExclusive
range
(int
the first number
from
,
int
the last number + 1
toExclusive
)

Creates a TreeSet of int numbers starting from from, extending to toExclusive - 1.

public static TreeSet<Character>
range(char from, char toExclusive)

public static TreeSet<Long>

Returns:

a range of long values as specified or the empty range if from >= toExclusive
range
(long
the first number
from
,
long
the last number + 1
toExclusive
)

Creates a TreeSet of long numbers starting from from, extending to toExclusive - 1.

public static TreeSet<Integer>

Returns:

a range of long values as specified or the empty range if
from >= toInclusive and step > 0 or
from <= toInclusive and step < 0
rangeBy
(int
the first number
from
,
int
the last number + 1
toExclusive
,
int
the step
step
)

Creates a TreeSet of int numbers starting from from, extending to toExclusive - 1, with step.

public static TreeSet<Character>
rangeBy(char from, char toExclusive, int step)

public static TreeSet<Double>
rangeBy(double from, double toExclusive, double step)

public static TreeSet<Long>

Returns:

a range of long values as specified or the empty range if
from >= toInclusive and step > 0 or
from <= toInclusive and step < 0
rangeBy
(long
the first number
from
,
long
the last number + 1
toExclusive
,
long
the step
step
)

Creates a TreeSet of long numbers starting from from, extending to toExclusive - 1, with step.

public static TreeSet<Integer>

Returns:

a range of int values as specified or the empty range if from > toInclusive
rangeClosed
(int
the first number
from
,
int
the last number
toInclusive
)

Creates a TreeSet of int numbers starting from from, extending to toInclusive.

public static TreeSet<Character>
rangeClosed(char from, char toInclusive)

public static TreeSet<Long>

Returns:

a range of long values as specified or the empty range if from > toInclusive
rangeClosed
(long
the first number
from
,
long
the last number
toInclusive
)

Creates a TreeSet of long numbers starting from from, extending to toInclusive.

public static TreeSet<Integer>

Returns:

a range of int values as specified or the empty range if
from > toInclusive and step > 0 or
from < toInclusive and step < 0
rangeClosedBy
(int
the first number
from
,
int
the last number
toInclusive
,
int
the step
step
)

Creates a TreeSet of int numbers starting from from, extending to toInclusive, with step.

public static TreeSet<Character>
rangeClosedBy(char from, char toInclusive, int step)

public static TreeSet<Double>
rangeClosedBy(double from, double toInclusive, double step)

public static TreeSet<Long>

Returns:

a range of int values as specified or the empty range if
from > toInclusive and step > 0 or
from < toInclusive and step < 0
rangeClosedBy
(long
the first number
from
,
long
the last number
toInclusive
,
long
the step
step
)

Creates a TreeSet of long numbers starting from from, extending to toInclusive, with step.

public TreeSet<T>
reject(Predicate<? super T>
A predicate
predicate
)

Implements io.vavr.collection.SortedSet.reject.

Returns a new traversable consisting of all elements which do not satisfy the given predicate.

public TreeSet<T>
remove(T
The element to be removed from this set.
element
)

Implements io.vavr.collection.SortedSet.remove.

Removes a specific element from this set, if present.

public TreeSet<T>
removeAll(Iterable<? extends T>
The elements to be removed from this set.
elements
)

Implements io.vavr.collection.SortedSet.removeAll.

Removes all of the given elements from this set, if present.

public TreeSet<T>
replace(T
An element to be substituted.
currentElement
,
T
A replacement for currentElement.
newElement
)

Implements io.vavr.collection.SortedSet.replace.

Replaces the first occurrence (if exists) of the given currentElement with newElement.

public TreeSet<T>
replaceAll(T
An element to be substituted.
currentElement
,
T
A replacement for currentElement.
newElement
)

Implements io.vavr.collection.SortedSet.replaceAll.

Replaces all occurrences of the given currentElement with newElement.

public TreeSet<T>
retainAll(Iterable<? extends T>
Elements to be kept.
elements
)

Implements io.vavr.collection.SortedSet.retainAll.

Keeps all occurrences of the given elements from this.

public TreeSet<T>
scan(T
neutral element for the operator op
zero
,
BiFunction<? super T, ? super T, ? extends T>
the associative operator for the scan
operation
)

Implements io.vavr.collection.SortedSet.scan.

Computes a prefix scan of the elements of the collection.

public <U> Set<U>
scanLeft(U
the initial value
zero
,
BiFunction<? super U, ? super T, ? extends U>
the binary operator applied to the intermediate result and the element
operation
)

Implements io.vavr.collection.SortedSet.scanLeft.

Produces a collection containing cumulative results of applying the operator going left to right.

public <U> Set<U>
scanRight(U
the initial value
zero
,
BiFunction<? super T, ? super U, ? extends U>
the binary operator applied to the intermediate result and the element
operation
)

Implements io.vavr.collection.SortedSet.scanRight.

Produces a collection containing cumulative results of applying the operator going right to left.

public Iterator<TreeSet<T>>
slideBy(Function<? super T, ?>
A function which classifies elements into classes
classifier
)

Implements io.vavr.collection.SortedSet.slideBy.

Slides a non-overlapping window of a variable size over this Traversable.

public Iterator<TreeSet<T>>
sliding(int
a positive window size
size
)

Implements io.vavr.collection.SortedSet.sliding.

Slides a window of a specific size and step size 1 over this Traversable by calling sliding(int, int).

public Iterator<TreeSet<T>>
sliding(int
a positive window size
size
,
int
a positive step size
step
)

Implements io.vavr.collection.SortedSet.sliding.

Slides a window of a specific size and step size over this Traversable.

public Tuple2<TreeSet<T>, TreeSet<T>>
span(Predicate<? super T>
A predicate.
predicate
)

Implements io.vavr.collection.SortedSet.span.

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.

public String
stringPrefix()

Implements io.vavr.Value.stringPrefix.

Returns the name of this Value type, which is used by toString().

public static <
Component type of the TreeSet
T
>
TreeSet<T>

Returns:

A TreeSet consisting of elements f(0),f(1), ..., f(n - 1)
tabulate
(Comparator<? super T>
The comparator used to sort the elements
comparator
,
int
The number of elements in the TreeSet
n
,
Function<? super Integer, ? extends T>
The Function computing element values
f
)

Returns a TreeSet containing n values of a given Function f over a range of integer values from 0 to n - 1.

public static <
Component type of the TreeSet
T extends Comparable<? super T>
>
TreeSet<T>

Returns:

A TreeSet consisting of elements f(0),f(1), ..., f(n - 1)
tabulate
(int
The number of elements in the TreeSet
n
,
Function<? super Integer, ? extends T>
The Function computing element values
f
)

Returns a TreeSet containing n values of a given Function f over a range of integer values from 0 to n - 1.

public TreeSet<T>
tail()

Implements io.vavr.collection.SortedSet.tail.

Drops the first element of a non-empty Traversable.

public Option<TreeSet<T>>
tailOption()

Implements io.vavr.collection.SortedSet.tailOption.

Drops the first element of a non-empty Traversable and returns an Option.

public TreeSet<T>
take(int
The number of elements to take.
n
)

Implements io.vavr.collection.SortedSet.take.

Takes the first n elements of this or all elements, if this length < n.

public TreeSet<T>
takeRight(int
The number of elements to take.
n
)

Implements io.vavr.collection.SortedSet.takeRight.

Takes the last n elements of this or all elements, if this length < n.

public TreeSet<T>
takeUntil(Predicate<? super T>
A condition tested subsequently for this elements.
predicate
)

Implements io.vavr.collection.SortedSet.takeUntil.

Takes elements until the predicate holds for the current element.

public TreeSet<T>
takeWhile(Predicate<? super T>
A condition tested subsequently for the contained elements.
predicate
)

Implements io.vavr.collection.SortedSet.takeWhile.

Takes elements while the predicate holds for the current element.

public TreeSet<T>
toJavaSet()

Implements io.vavr.collection.SortedSet.toJavaSet.

Converts this Vavr Set to a java.util.Set while preserving characteristics like insertion order (LinkedHashSet) and sort order (SortedSet).

public String
toString()

Overrides java.lang.Object.toString.

Implements io.vavr.Value.toString.

Clarifies that values have a proper toString() method implemented.

public <
Type of transformation result
U
>
U

Returns:

An instance of type U
transform
(Function<? super TreeSet<T>, ? extends U>
A transformation
f
)

Transforms this TreeSet.

public TreeSet<T>
union(Set<? extends T>
The set to form the union with.
elements
)

Implements io.vavr.collection.SortedSet.union.

Adds all of the elements of that set to this set, if not already present.

public <T1, T2> Tuple2<TreeSet<T1>, TreeSet<T2>>
unzip(Function<? super T, Tuple2<? extends T1, ? extends T2>>
a function which converts elements of this to pairs
unzipper
)

Implements io.vavr.collection.SortedSet.unzip.

Unzips this elements by mapping this elements to pairs which are subsequently split into two distinct sets.

public <T1, T2, T3> Tuple3<TreeSet<T1>, TreeSet<T2>, TreeSet<T3>>
unzip3(Function<? super T, Tuple3<? extends T1, ? extends T2, ? extends T3>>
a function which converts elements of this to pairs
unzipper
)

Implements io.vavr.collection.SortedSet.unzip3.

Unzips this elements by mapping this elements to triples which are subsequently split into three distinct sets.

public <U> TreeSet<Tuple2<T, U>>
zip(Iterable<? extends U>
The Iterable providing the second half of each result pair.
that
)

Implements io.vavr.collection.SortedSet.zip.

Returns a traversable formed from this traversable and another Iterable collection by combining corresponding elements in pairs.

public <U> TreeSet<Tuple2<T, U>>
zipAll(Iterable<? extends U>
The Iterable providing the second half of each result pair.
that
,
T
The element to be used to fill up the result if this traversable is shorter than that.
thisElem
,
U
The element to be used to fill up the result if that is shorter than this traversable.
thatElem
)

Implements io.vavr.collection.SortedSet.zipAll.

Returns a traversable formed from this traversable and another Iterable by combining corresponding elements in pairs.

public <U, R> TreeSet<R>
zipWith(Iterable<? extends U>
The Iterable providing the second parameter of the mapper.
that
,
BiFunction<? super T, ? super U, ? extends R>
a mapper.
mapper
)

Implements io.vavr.collection.SortedSet.zipWith.

Returns a traversable formed from this traversable and another Iterable collection by mapping elements.

public TreeSet<Tuple2<T, Integer>>
zipWithIndex()

Implements io.vavr.collection.SortedSet.zipWithIndex.

Zips this traversable with its indices.

public <U> SortedSet<U>
zipWithIndex(BiFunction<? super T, ? super Integer, ? extends U>
a mapper.
mapper
)

Implements io.vavr.collection.SortedSet.zipWithIndex.

Zips this traversable with its indices by applying mapper provided.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait