Class TreeSet<T>
- java.lang.Object
-
- io.vavr.collection.TreeSet<T>
-
- Type Parameters:
T- Component type
- All Implemented Interfaces:
Foldable<T>,Ordered<T>,Set<T>,SortedSet<T>,Traversable<T>,Function1<T,java.lang.Boolean>,Value<T>,java.io.Serializable,java.lang.Iterable<T>,java.util.function.Function<T,java.lang.Boolean>
public final class TreeSet<T> extends java.lang.Object implements SortedSet<T>, java.io.Serializable
SortedSet implementation, backed by a Red/Black Tree.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static longserialVersionUIDprivate RedBlackTree<T>tree
-
Constructor Summary
Constructors Constructor Description TreeSet(RedBlackTree<T> tree)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TreeSet<T>add(T element)Returns a new set containing all elements of this set plus the given element, if it was not already present.TreeSet<T>addAll(@NonNull java.lang.Iterable<? extends T> elements)Returns a new set containing all elements of this set plus the given elements, excluding duplicates.<R> TreeSet<R>collect(@NonNull PartialFunction<? super T,? extends R> partialFunction)Applies aPartialFunctionto all elements that are defined for it and collects the results.static <T extends java.lang.Comparable<? super T>>
java.util.stream.Collector<T,java.util.ArrayList<T>,TreeSet<T>>collector()Returns aCollectorwhich may be used in conjunction withStream.collect(java.util.stream.Collector)to obtain aTreeSet.static <T> java.util.stream.Collector<T,java.util.ArrayList<T>,TreeSet<T>>collector(@NonNull java.util.Comparator<? super T> comparator)Returns aCollectorwhich may be used in conjunction withStream.collect(java.util.stream.Collector)to obtain aTreeSet.java.util.Comparator<T>comparator()Returns the comparator that governs the ordering of elements in this collection.booleancontains(T element)Shortcut forexists(e -> Objects.equals(e, element)), tests if the givenelementis contained.TreeSet<T>diff(@NonNull Set<? extends T> elements)Returns a new set containing all elements of this set except those in the given set.TreeSet<T>distinct()Returns a newTraversablecontaining the elements of this instance with all duplicates removed.TreeSet<T>distinctBy(@NonNull java.util.Comparator<? super T> comparator)Returns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.<U> TreeSet<T>distinctBy(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)Returns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.TreeSet<T>drop(int n)Returns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.TreeSet<T>dropRight(int n)Returns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.TreeSet<T>dropUntil(@NonNull java.util.function.Predicate<? super T> predicate)Returns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.TreeSet<T>dropWhile(@NonNull java.util.function.Predicate<? super T> predicate)Returns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.static <T extends java.lang.Comparable<? super T>>
TreeSet<T>empty()Returns the empty TreeSet with natural ordering.static <T> TreeSet<T>empty(@NonNull java.util.Comparator<? super T> comparator)Returns the empty TreeSet with the given comparator.booleanequals(java.lang.Object o)Determines whether this collection is equal to the given object.static <T extends java.lang.Comparable<? super T>>
TreeSet<T>fill(int n, @NonNull java.util.function.Supplier<? extends T> s)Returns a TreeSet containing tuples returned byncalls to a given Suppliers.static <T> TreeSet<T>fill(@NonNull java.util.Comparator<? super T> comparator, int n, @NonNull java.util.function.Supplier<? extends T> s)Returns a TreeSet containing tuples returned byncalls to a given Suppliers.TreeSet<T>filter(@NonNull java.util.function.Predicate<? super T> predicate)Returns a new traversable containing only the elements that satisfy the given predicate.<U> TreeSet<U>flatMap(@NonNull java.util.Comparator<? super U> comparator, @NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)Same asSortedSet.flatMap(Function)but using a specific comparator for values of the codomain of the givenmapper.<U> TreeSet<U>flatMap(@NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)Transforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.<U> UfoldRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> f)Folds the elements of this structure from the right, starting with the givenzerovalue and successively applying thecombinefunction to each element.<C> Map<C,TreeSet<T>>groupBy(@NonNull java.util.function.Function<? super T,? extends C> classifier)Groups elements of thisTraversablebased on a classifier function.Iterator<TreeSet<T>>grouped(int size)Splits thisTraversableinto consecutive blocks of the given size.booleanhasDefiniteSize()Indicates whether thisTraversablehas a known finite size.inthashCode()Returns the hash code of this collection.Thead()Returns the first element of this non-emptyTraversable.Option<T>headOption()Returns the first element of thisTraversableas anOption.TreeSet<T>init()Returns all elements of this Traversable except the last one.Option<TreeSet<T>>initOption()Returns all elements of this Traversable except the last one, wrapped in anOption.TreeSet<T>intersect(@NonNull Set<? extends T> elements)Returns a new set containing only the elements present in both this set and the given set.booleanisAsync()ATreeSetis computed synchronously.booleanisEmpty()Checks if this Traversable contains no elements.booleanisLazy()ATreeSetis computed eagerly.booleanisTraversableAgain()Checks if this Traversable can be traversed multiple times without side effects.@NonNull Iterator<T>iterator()Returns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail().Tlast()Returns the last element of this Traversable.intlength()Returns the number of elements in this Traversable.<U> TreeSet<U>map(@NonNull java.util.Comparator<? super U> comparator, @NonNull java.util.function.Function<? super T,? extends U> mapper)Same asSortedSet.map(Function)but using a specific comparator for values of the codomain of the givenmapper.<U> TreeSet<U>map(@NonNull java.util.function.Function<? super T,? extends U> mapper)Transforms the elements of this Traversable to a new type, preserving order if defined.<U> TreeSet<U>mapTo(U value)Maps the underlying value to another fixed value.TreeSet<java.lang.Void>mapToVoid()Maps the underlying value to Voidstatic <T> TreeSet<T>narrow(TreeSet<? extends T> treeSet)Narrows aTreeSet<? extends T>toTreeSet<T>via a type-safe cast.static <T> TreeSet<T>of(@NonNull java.util.Comparator<? super T> comparator, T value)Returns a singletonTreeSet, i.e.static <T> TreeSet<T>of(@NonNull java.util.Comparator<? super T> comparator, T @NonNull ... values)Creates a TreeSet of the given elements with the given comparator.static <T extends java.lang.Comparable<? super T>>
TreeSet<T>of(T value)Returns a singletonTreeSet, i.e.static <T extends java.lang.Comparable<? super T>>
TreeSet<T>of(T @NonNull ... values)Creates a TreeSet of the given elements with natural ordering.static TreeSet<java.lang.Boolean>ofAll(boolean @NonNull ... elements)Creates a TreeSet from boolean values.static TreeSet<java.lang.Byte>ofAll(byte @NonNull ... elements)Creates a TreeSet from byte values.static TreeSet<java.lang.Character>ofAll(char @NonNull ... elements)Creates a TreeSet from char values.static TreeSet<java.lang.Double>ofAll(double @NonNull ... elements)Creates a TreeSet from double values.static TreeSet<java.lang.Float>ofAll(float @NonNull ... elements)Creates a TreeSet from float values.static TreeSet<java.lang.Integer>ofAll(int @NonNull ... elements)Creates a TreeSet from int values.static TreeSet<java.lang.Long>ofAll(long @NonNull ... elements)Creates a TreeSet from long values.static TreeSet<java.lang.Short>ofAll(short @NonNull ... elements)Creates a TreeSet from short values.static <T extends java.lang.Comparable<? super T>>
TreeSet<T>ofAll(@NonNull java.lang.Iterable<? extends T> values)Creates a TreeSet of the given elements with natural ordering.static <T extends java.lang.Comparable<? super T>>
TreeSet<T>ofAll(@NonNull java.util.stream.Stream<? extends T> javaStream)Creates a TreeSet from a Java Stream with natural ordering.static <T> TreeSet<T>ofAll(java.util.Comparator<? super T> comparator, @NonNull java.lang.Iterable<? extends T> values)Creates a TreeSet of the given elements with the given comparator.static <T> TreeSet<T>ofAll(java.util.Comparator<? super T> comparator, @NonNull java.util.stream.Stream<? extends T> javaStream)Creates a TreeSet from a Java Stream with the given comparator.TreeSet<T>orElse(@NonNull java.lang.Iterable<? extends T> other)Returns thisTreeSetif it is nonempty, otherwiseTreeSetcreated from iterable, using existing comparator.TreeSet<T>orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)Returns thisTreeSetif it is nonempty, otherwiseTreeSetcreated from result of evaluating supplier, using existing comparator.Tuple2<TreeSet<T>,TreeSet<T>>partition(@NonNull java.util.function.Predicate<? super T> predicate)Splits thisTraversableinto two partitions according to a predicate.TreeSet<T>peek(@NonNull java.util.function.Consumer<? super T> action)Performs the givenactionon the first element if this is an eager implementation.static TreeSet<java.lang.Character>range(char from, char toExclusive)Creates a TreeSet of char numbers starting fromfrom, extending totoExclusive - 1.static TreeSet<java.lang.Integer>range(int from, int toExclusive)Creates a TreeSet of int numbers starting fromfrom, extending totoExclusive - 1.static TreeSet<java.lang.Long>range(long from, long toExclusive)Creates a TreeSet of long numbers starting fromfrom, extending totoExclusive - 1.static TreeSet<java.lang.Character>rangeBy(char from, char toExclusive, int step)Creates a TreeSet of char numbers starting fromfrom, extending totoExclusive - 1, withstep.static TreeSet<java.lang.Double>rangeBy(double from, double toExclusive, double step)Creates a TreeSet of double numbers starting fromfrom, extending up to (but not including)toExclusive, withstep.static TreeSet<java.lang.Integer>rangeBy(int from, int toExclusive, int step)Creates a TreeSet of int numbers starting fromfrom, extending totoExclusive - 1, withstep.static TreeSet<java.lang.Long>rangeBy(long from, long toExclusive, long step)Creates a TreeSet of long numbers starting fromfrom, extending totoExclusive - 1, withstep.static TreeSet<java.lang.Character>rangeClosed(char from, char toInclusive)Creates a TreeSet of char numbers starting fromfrom, extending totoInclusive.static TreeSet<java.lang.Integer>rangeClosed(int from, int toInclusive)Creates a TreeSet of int numbers starting fromfrom, extending totoInclusive.static TreeSet<java.lang.Long>rangeClosed(long from, long toInclusive)Creates a TreeSet of long numbers starting fromfrom, extending totoInclusive.static TreeSet<java.lang.Character>rangeClosedBy(char from, char toInclusive, int step)Creates a TreeSet of char numbers starting fromfrom, extending totoInclusive, withstep.static TreeSet<java.lang.Double>rangeClosedBy(double from, double toInclusive, double step)Creates a TreeSet of double numbers starting fromfrom, extending totoInclusive, withstep.static TreeSet<java.lang.Integer>rangeClosedBy(int from, int toInclusive, int step)Creates a TreeSet of int numbers starting fromfrom, extending totoInclusive, withstep.static TreeSet<java.lang.Long>rangeClosedBy(long from, long toInclusive, long step)Creates a TreeSet of long numbers starting fromfrom, extending totoInclusive, withstep.TreeSet<T>reject(@NonNull java.util.function.Predicate<? super T> predicate)Returns a new traversable containing only the elements that do not satisfy the given predicate.TreeSet<T>remove(T element)Returns a new set with the given element removed, if it was present.TreeSet<T>removeAll(@NonNull java.lang.Iterable<? extends T> elements)Returns a new set with all given elements removed, if present.TreeSet<T>replace(T currentElement, T newElement)Replaces the first occurrence ofcurrentElementwithnewElement, if it exists.TreeSet<T>replaceAll(T currentElement, T newElement)Replaces all occurrences ofcurrentElementwithnewElement.TreeSet<T>retainAll(@NonNull java.lang.Iterable<? extends T> elements)Retains only the elements from this Traversable that are contained in the givenelements.TreeSet<T>scan(T zero, @NonNull java.util.function.BiFunction<? super T,? super T,? extends T> operation)Computes a prefix scan of the elements of this Traversable.<U> Set<U>scanLeft(U zero, @NonNull java.util.function.BiFunction<? super U,? super T,? extends U> operation)Produces a collection containing cumulative results of applying the operator from left to right.<U> Set<U>scanRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> operation)Produces a collection containing cumulative results of applying the operator from right to left.Iterator<TreeSet<T>>slideBy(@NonNull java.util.function.Function<? super T,?> classifier)Partitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Iterator<TreeSet<T>>sliding(int size)Slides a window of a givensizeover thisTraversablewith a step size of 1.Iterator<TreeSet<T>>sliding(int size, int step)Slides a window of a specificsizewith a givenstepover thisTraversable.Tuple2<TreeSet<T>,TreeSet<T>>span(@NonNull java.util.function.Predicate<? super T> predicate)Splits thisTraversableinto a prefix and remainder according to the givenpredicate.java.lang.StringstringPrefix()Returns the name of this Value type, which is used by toString().static <T extends java.lang.Comparable<? super T>>
TreeSet<T>tabulate(int n, @NonNull java.util.function.Function<? super java.lang.Integer,? extends T> f)Returns a TreeSet containingnvalues of a given Functionfover a range of integer values from 0 ton - 1.static <T> TreeSet<T>tabulate(@NonNull java.util.Comparator<? super T> comparator, int n, @NonNull java.util.function.Function<? super java.lang.Integer,? extends T> f)Returns a TreeSet containingnvalues of a given Functionfover a range of integer values from 0 ton - 1.TreeSet<T>tail()Returns a newTraversablewithout its first element.Option<TreeSet<T>>tailOption()Returns a newTraversablewithout its first element as anOption.TreeSet<T>take(int n)Returns the firstnelements of thisTraversable, or all elements ifnexceeds the length.TreeSet<T>takeRight(int n)Returns the lastnelements of thisTraversable, or all elements ifnexceeds the length.TreeSet<T>takeUntil(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from thisTraversableuntil the given predicate holds for an element.TreeSet<T>takeWhile(@NonNull java.util.function.Predicate<? super T> predicate)Takes elements from thisTraversablewhile the given predicate holds.java.util.TreeSet<T>toJavaSet()Converts this Vavr set to ajava.util.Set, preserving insertion or sort order.java.lang.StringtoString()Clarifies that values have a proper toString() method implemented.<U> Utransform(java.util.function.Function<? super TreeSet<T>,? extends U> f)Transforms thisTreeSet.TreeSet<T>union(@NonNull Set<? extends T> elements)Returns a new set containing all distinct elements from this set and the given set.<T1,T2>
Tuple2<TreeSet<T1>,TreeSet<T2>>unzip(@NonNull java.util.function.Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)Unzips the elements of thisTraversableby mapping each element to a pair and splitting them into two separateTraversablecollections.<T1,T2,T3>
Tuple3<TreeSet<T1>,TreeSet<T2>,TreeSet<T3>>unzip3(@NonNull java.util.function.Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)Unzips the elements of thisTraversableby mapping each element to a triple and splitting them into three separateTraversablecollections.<U> TreeSet<Tuple2<T,U>>zip(@NonNull java.lang.Iterable<? extends U> that)Returns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable.<U> TreeSet<Tuple2<T,U>>zipAll(@NonNull java.lang.Iterable<? extends U> that, T thisElem, U thatElem)Returns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable, filling in placeholder elements when one collection is shorter than the other.<U,R>
TreeSet<R>zipWith(@NonNull java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super T,? super U,? extends R> mapper)Returns aTraversableby combining elements of thisTraversablewith elements of anotherIterableusing a mapping function.TreeSet<Tuple2<T,java.lang.Integer>>zipWithIndex()Zips thisTraversablewith its indices, starting at 0.<U> SortedSet<U>zipWithIndex(@NonNull java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)Zips thisTraversablewith its indices and maps the resulting pairs using the provided mapper.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.vavr.collection.Foldable
fold, reduce, reduceOption
-
Methods inherited from interface io.vavr.Function1
andThen, arity, compose, compose1, curried, isMemoized, memoized, partial, reversed, tupled
-
Methods inherited from interface io.vavr.collection.Set
apply, isDistinct
-
Methods inherited from interface io.vavr.collection.Traversable
arrangeBy, average, containsAll, count, existsUnique, find, findLast, foldLeft, forEachWithIndex, get, isSequential, isSingleValued, lastOption, max, maxBy, maxBy, min, minBy, minBy, mkCharSeq, mkCharSeq, mkCharSeq, mkString, mkString, mkString, nonEmpty, product, reduceLeft, reduceLeftOption, reduceRight, reduceRightOption, single, singleOption, size, spliterator, sum
-
Methods inherited from interface io.vavr.Value
collect, collect, corresponds, eq, exists, forAll, forEach, getOrElse, getOrElse, getOrElseThrow, getOrElseTry, getOrNull, 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, toVector
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
tree
private final RedBlackTree<T> tree
-
-
Constructor Detail
-
TreeSet
TreeSet(RedBlackTree<T> tree)
-
-
Method Detail
-
collector
public static <T extends java.lang.Comparable<? super T>> java.util.stream.Collector<T,java.util.ArrayList<T>,TreeSet<T>> collector()
Returns aCollectorwhich may be used in conjunction withStream.collect(java.util.stream.Collector)to obtain aTreeSet.The natural comparator is used to compare TreeSet elements.
- Type Parameters:
T- Component type of the List.- Returns:
- A io.vavr.collection.List Collector.
-
collector
public static <T> java.util.stream.Collector<T,java.util.ArrayList<T>,TreeSet<T>> collector(@NonNull java.util.Comparator<? super T> comparator)
Returns aCollectorwhich may be used in conjunction withStream.collect(java.util.stream.Collector)to obtain aTreeSet.- Type Parameters:
T- Component type of the List.- Parameters:
comparator- An element comparator- Returns:
- A io.vavr.collection.List Collector.
-
empty
public static <T extends java.lang.Comparable<? super T>> TreeSet<T> empty()
Returns the empty TreeSet with natural ordering.- Type Parameters:
T- Component type- Returns:
- The empty TreeSet with natural ordering.
-
empty
public static <T> TreeSet<T> empty(@NonNull java.util.Comparator<? super T> comparator)
Returns the empty TreeSet with the given comparator.- Type Parameters:
T- Component type- Parameters:
comparator- The comparator used to sort the elements- Returns:
- The empty TreeSet.
- Throws:
java.lang.NullPointerException- ifcomparatorisnull
-
narrow
public static <T> TreeSet<T> narrow(TreeSet<? extends T> treeSet)
Narrows aTreeSet<? extends T>toTreeSet<T>via a type-safe cast. Safe here because the set is immutable and no elements can be added that would violate the type (covariance)CAUTION: The underlying
Comparatormight fail!- Type Parameters:
T- the target element type- Parameters:
treeSet- the set to narrow- Returns:
- the same set viewed as
TreeSet<T>
-
of
public static <T extends java.lang.Comparable<? super T>> TreeSet<T> of(T value)
Returns a singletonTreeSet, i.e. aTreeSetof one element with natural ordering.- Type Parameters:
T- The component type- Parameters:
value- An element.- Returns:
- A new TreeSet instance containing the given element
-
of
public static <T> TreeSet<T> of(@NonNull java.util.Comparator<? super T> comparator, T value)
Returns a singletonTreeSet, i.e. aTreeSetof one element with the given comparator.- Type Parameters:
T- The component type- Parameters:
comparator- The comparator used to sort the elementsvalue- An element.- Returns:
- A new TreeSet instance containing the given element
- Throws:
java.lang.NullPointerException- ifcomparatorisnull
-
of
@SafeVarargs public static <T extends java.lang.Comparable<? super T>> TreeSet<T> of(T @NonNull ... values)
Creates a TreeSet of the given elements with natural ordering.- Type Parameters:
T- Component type of the TreeSet.- Parameters:
values- Zero or more elements.- Returns:
- A set containing the given elements.
- Throws:
java.lang.NullPointerException- ifvaluesis null
-
of
@SafeVarargs public static <T> TreeSet<T> of(@NonNull java.util.Comparator<? super T> comparator, T @NonNull ... values)
Creates a TreeSet of the given elements with the given comparator.- Type Parameters:
T- Component type of the TreeSet.- Parameters:
comparator- The comparator used to sort the elementsvalues- Zero or more elements.- Returns:
- A set containing the given elements.
- Throws:
java.lang.NullPointerException- ifcomparatororvaluesis null
-
tabulate
public static <T> TreeSet<T> tabulate(@NonNull java.util.Comparator<? super T> comparator, int n, @NonNull java.util.function.Function<? super java.lang.Integer,? extends T> f)
Returns a TreeSet containingnvalues of a given Functionfover a range of integer values from 0 ton - 1.- Type Parameters:
T- Component type of the TreeSet- Parameters:
comparator- The comparator used to sort the elementsn- The number of elements in the TreeSetf- The Function computing element values- Returns:
- A TreeSet consisting of elements
f(0),f(1), ..., f(n - 1) - Throws:
java.lang.NullPointerException- ifcomparatororfare null
-
tabulate
public static <T extends java.lang.Comparable<? super T>> TreeSet<T> tabulate(int n, @NonNull java.util.function.Function<? super java.lang.Integer,? extends T> f)
Returns a TreeSet containingnvalues of a given Functionfover a range of integer values from 0 ton - 1. The underlying comparator is the natural comparator of T.- Type Parameters:
T- Component type of the TreeSet- Parameters:
n- The number of elements in the TreeSetf- The Function computing element values- Returns:
- A TreeSet consisting of elements
f(0),f(1), ..., f(n - 1) - Throws:
java.lang.NullPointerException- iffis null
-
fill
public static <T> TreeSet<T> fill(@NonNull java.util.Comparator<? super T> comparator, int n, @NonNull java.util.function.Supplier<? extends T> s)
Returns a TreeSet containing tuples returned byncalls to a given Suppliers.- Type Parameters:
T- Component type of the TreeSet- Parameters:
comparator- The comparator used to sort the elementsn- The number of elements in the TreeSets- The Supplier computing element values- Returns:
- A TreeSet of size
n, where each element contains the result supplied bys. - Throws:
java.lang.NullPointerException- ifcomparatororsare null
-
fill
public static <T extends java.lang.Comparable<? super T>> TreeSet<T> fill(int n, @NonNull java.util.function.Supplier<? extends T> s)
Returns a TreeSet containing tuples returned byncalls to a given Suppliers. The underlying comparator is the natural comparator of T.- Type Parameters:
T- Component type of the TreeSet- Parameters:
n- The number of elements in the TreeSets- The Supplier computing element values- Returns:
- A TreeSet of size
n, where each element contains the result supplied bys. - Throws:
java.lang.NullPointerException- ifsis null
-
ofAll
public static <T extends java.lang.Comparable<? super T>> TreeSet<T> ofAll(@NonNull java.lang.Iterable<? extends T> values)
Creates a TreeSet of the given elements with natural ordering.- Type Parameters:
T- Component type of the TreeSet.- Parameters:
values- An Iterable of elements.- Returns:
- A set containing the given elements.
- Throws:
java.lang.NullPointerException- ifvaluesis null
-
ofAll
public static <T> TreeSet<T> ofAll(java.util.Comparator<? super T> comparator, @NonNull java.lang.Iterable<? extends T> values)
Creates a TreeSet of the given elements with the given comparator.- Type Parameters:
T- Component type of the TreeSet.- Parameters:
comparator- The comparator used to sort the elementsvalues- An Iterable of elements.- Returns:
- A set containing the given elements.
- Throws:
java.lang.NullPointerException- ifcomparatororvaluesis null
-
ofAll
public static <T extends java.lang.Comparable<? super T>> TreeSet<T> ofAll(@NonNull java.util.stream.Stream<? extends T> javaStream)
Creates a TreeSet from a Java Stream with natural ordering.- Type Parameters:
T- Component type of the TreeSet.- Parameters:
javaStream- A Java Stream- Returns:
- A TreeSet containing the elements of the given stream
- Throws:
java.lang.NullPointerException- ifjavaStreamis null
-
ofAll
public static <T> TreeSet<T> ofAll(java.util.Comparator<? super T> comparator, @NonNull java.util.stream.Stream<? extends T> javaStream)
Creates a TreeSet from a Java Stream with the given comparator.- Type Parameters:
T- Component type of the TreeSet.- Parameters:
comparator- The comparator used to sort the elementsjavaStream- A Java Stream- Returns:
- A TreeSet containing the elements of the given stream
- Throws:
java.lang.NullPointerException- ifjavaStreamis null
-
ofAll
public static TreeSet<java.lang.Boolean> ofAll(boolean @NonNull ... elements)
Creates a TreeSet from boolean values.- Parameters:
elements- boolean values- Returns:
- A new TreeSet of Boolean values
- Throws:
java.lang.NullPointerException- if elements is null
-
ofAll
public static TreeSet<java.lang.Byte> ofAll(byte @NonNull ... elements)
Creates a TreeSet from byte values.- Parameters:
elements- byte values- Returns:
- A new TreeSet of Byte values
- Throws:
java.lang.NullPointerException- if elements is null
-
ofAll
public static TreeSet<java.lang.Character> ofAll(char @NonNull ... elements)
Creates a TreeSet from char values.- Parameters:
elements- char values- Returns:
- A new TreeSet of Character values
- Throws:
java.lang.NullPointerException- if elements is null
-
ofAll
public static TreeSet<java.lang.Double> ofAll(double @NonNull ... elements)
Creates a TreeSet from double values.- Parameters:
elements- double values- Returns:
- A new TreeSet of Double values
- Throws:
java.lang.NullPointerException- if elements is null
-
ofAll
public static TreeSet<java.lang.Float> ofAll(float @NonNull ... elements)
Creates a TreeSet from float values.- Parameters:
elements- float values- Returns:
- A new TreeSet of Float values
- Throws:
java.lang.NullPointerException- if elements is null
-
ofAll
public static TreeSet<java.lang.Integer> ofAll(int @NonNull ... elements)
Creates a TreeSet from int values.- Parameters:
elements- int values- Returns:
- A new TreeSet of Integer values
- Throws:
java.lang.NullPointerException- if elements is null
-
ofAll
public static TreeSet<java.lang.Long> ofAll(long @NonNull ... elements)
Creates a TreeSet from long values.- Parameters:
elements- long values- Returns:
- A new TreeSet of Long values
- Throws:
java.lang.NullPointerException- if elements is null
-
ofAll
public static TreeSet<java.lang.Short> ofAll(short @NonNull ... elements)
Creates a TreeSet from short values.- Parameters:
elements- short values- Returns:
- A new TreeSet of Short values
- Throws:
java.lang.NullPointerException- if elements is null
-
range
public static TreeSet<java.lang.Integer> range(int from, int toExclusive)
Creates a TreeSet of int numbers starting fromfrom, extending totoExclusive - 1.Examples:
TreeSet.range(0, 0) // = TreeSet() TreeSet.range(2, 0) // = TreeSet() TreeSet.range(-2, 2) // = TreeSet(-2, -1, 0, 1)- Parameters:
from- the first numbertoExclusive- the last number + 1- Returns:
- a range of int values as specified or the empty range if
from >= toExclusive
-
range
public static TreeSet<java.lang.Character> range(char from, char toExclusive)
Creates a TreeSet of char numbers starting fromfrom, extending totoExclusive - 1.Examples:
TreeSet.range('a', 'a') // = TreeSet() TreeSet.range('b', 'a') // = TreeSet() TreeSet.range('a', 'c') // = TreeSet('a', 'b')- Parameters:
from- the first chartoExclusive- the last char + 1- Returns:
- a range of char values as specified or the empty range if
from >= toExclusive
-
rangeBy
public static TreeSet<java.lang.Integer> rangeBy(int from, int toExclusive, int step)
Creates a TreeSet of int numbers starting fromfrom, extending totoExclusive - 1, withstep.Examples:
TreeSet.rangeBy(1, 3, 1) // = TreeSet(1, 2) TreeSet.rangeBy(1, 4, 2) // = TreeSet(1, 3) TreeSet.rangeBy(4, 1, -2) // = TreeSet(4, 2) TreeSet.rangeBy(4, 1, 2) // = TreeSet()- Parameters:
from- the first numbertoExclusive- the last number + 1step- the step- Returns:
- a range of long values as specified or the empty range if
from >= toInclusiveandstep > 0or
from <= toInclusiveandstep < 0 - Throws:
java.lang.IllegalArgumentException- ifstepis zero
-
rangeBy
public static TreeSet<java.lang.Character> rangeBy(char from, char toExclusive, int step)
Creates a TreeSet of char numbers starting fromfrom, extending totoExclusive - 1, withstep.Examples:
TreeSet.rangeBy('a', 'c', 1) // = TreeSet('a', 'b') TreeSet.rangeBy('a', 'd', 2) // = TreeSet('a', 'c') TreeSet.rangeBy('d', 'a', -2) // = TreeSet('d', 'b') TreeSet.rangeBy('d', 'a', 2) // = TreeSet()- Parameters:
from- the first chartoExclusive- the last char + 1step- the step- Returns:
- a range of char values as specified or the empty range if
from >= toExclusiveandstep > 0or
from <= toExclusiveandstep < 0 - Throws:
java.lang.IllegalArgumentException- ifstepis zero
-
rangeBy
@GwtIncompatible public static TreeSet<java.lang.Double> rangeBy(double from, double toExclusive, double step)
Creates a TreeSet of double numbers starting fromfrom, extending up to (but not including)toExclusive, withstep.Examples:
TreeSet.rangeBy(1.0, 3.0, 1.0) // = TreeSet(1.0, 2.0) TreeSet.rangeBy(1.0, 4.0, 2.0) // = TreeSet(1.0, 3.0) TreeSet.rangeBy(4.0, 1.0, -2.0) // = TreeSet(4.0, 2.0) TreeSet.rangeBy(4.0, 1.0, 2.0) // = TreeSet()- Parameters:
from- the first doubletoExclusive- the upper bound (exclusive)step- the step- Returns:
- a range of double values as specified or the empty range if
from >= toExclusiveandstep > 0or
from <= toExclusiveandstep < 0 - Throws:
java.lang.IllegalArgumentException- ifstepis zero
-
range
public static TreeSet<java.lang.Long> range(long from, long toExclusive)
Creates a TreeSet of long numbers starting fromfrom, extending totoExclusive - 1.Examples:
TreeSet.range(0L, 0L) // = TreeSet() TreeSet.range(2L, 0L) // = TreeSet() TreeSet.range(-2L, 2L) // = TreeSet(-2L, -1L, 0L, 1L)- Parameters:
from- the first numbertoExclusive- the last number + 1- Returns:
- a range of long values as specified or the empty range if
from >= toExclusive
-
rangeBy
public static TreeSet<java.lang.Long> rangeBy(long from, long toExclusive, long step)
Creates a TreeSet of long numbers starting fromfrom, extending totoExclusive - 1, withstep.Examples:
TreeSet.rangeBy(1L, 3L, 1L) // = TreeSet(1L, 2L) TreeSet.rangeBy(1L, 4L, 2L) // = TreeSet(1L, 3L) TreeSet.rangeBy(4L, 1L, -2L) // = TreeSet(4L, 2L) TreeSet.rangeBy(4L, 1L, 2L) // = TreeSet()- Parameters:
from- the first numbertoExclusive- the last number + 1step- the step- Returns:
- a range of long values as specified or the empty range if
from >= toInclusiveandstep > 0or
from <= toInclusiveandstep < 0 - Throws:
java.lang.IllegalArgumentException- ifstepis zero
-
rangeClosed
public static TreeSet<java.lang.Integer> rangeClosed(int from, int toInclusive)
Creates a TreeSet of int numbers starting fromfrom, extending totoInclusive.Examples:
TreeSet.rangeClosed(0, 0) // = TreeSet(0) TreeSet.rangeClosed(2, 0) // = TreeSet() TreeSet.rangeClosed(-2, 2) // = TreeSet(-2, -1, 0, 1, 2)- Parameters:
from- the first numbertoInclusive- the last number- Returns:
- a range of int values as specified or the empty range if
from > toInclusive
-
rangeClosed
public static TreeSet<java.lang.Character> rangeClosed(char from, char toInclusive)
Creates a TreeSet of char numbers starting fromfrom, extending totoInclusive.Examples:
TreeSet.rangeClosed('a', 'a') // = TreeSet('a') TreeSet.rangeClosed('b', 'a') // = TreeSet() TreeSet.rangeClosed('a', 'c') // = TreeSet('a', 'b', 'c')- Parameters:
from- the first chartoInclusive- the last char- Returns:
- a range of char values as specified or the empty range if
from > toInclusive
-
rangeClosedBy
public static TreeSet<java.lang.Integer> rangeClosedBy(int from, int toInclusive, int step)
Creates a TreeSet of int numbers starting fromfrom, extending totoInclusive, withstep.Examples:
TreeSet.rangeClosedBy(1, 3, 1) // = TreeSet(1, 2, 3) TreeSet.rangeClosedBy(1, 4, 2) // = TreeSet(1, 3) TreeSet.rangeClosedBy(4, 1, -2) // = TreeSet(4, 2) TreeSet.rangeClosedBy(4, 1, 2) // = TreeSet()- Parameters:
from- the first numbertoInclusive- the last numberstep- the step- Returns:
- a range of int values as specified or the empty range if
from > toInclusiveandstep > 0or
from < toInclusiveandstep < 0 - Throws:
java.lang.IllegalArgumentException- ifstepis zero
-
rangeClosedBy
public static TreeSet<java.lang.Character> rangeClosedBy(char from, char toInclusive, int step)
Creates a TreeSet of char numbers starting fromfrom, extending totoInclusive, withstep.Examples:
TreeSet.rangeClosedBy('a', 'c', 1) // = TreeSet('a', 'b', 'c') TreeSet.rangeClosedBy('a', 'd', 2) // = TreeSet('a', 'c') TreeSet.rangeClosedBy('d', 'a', -2) // = TreeSet('d', 'b') TreeSet.rangeClosedBy('d', 'a', 2) // = TreeSet()- Parameters:
from- the first chartoInclusive- the last charstep- the step- Returns:
- a range of char values as specified or the empty range if
from > toInclusiveandstep > 0or
from < toInclusiveandstep < 0 - Throws:
java.lang.IllegalArgumentException- ifstepis zero
-
rangeClosedBy
@GwtIncompatible public static TreeSet<java.lang.Double> rangeClosedBy(double from, double toInclusive, double step)
Creates a TreeSet of double numbers starting fromfrom, extending totoInclusive, withstep.Examples:
TreeSet.rangeClosedBy(1.0, 3.0, 1.0) // = TreeSet(1.0, 2.0, 3.0) TreeSet.rangeClosedBy(1.0, 4.0, 2.0) // = TreeSet(1.0, 3.0) TreeSet.rangeClosedBy(4.0, 1.0, -2.0) // = TreeSet(4.0, 2.0) TreeSet.rangeClosedBy(4.0, 1.0, 2.0) // = TreeSet()- Parameters:
from- the first doubletoInclusive- the last doublestep- the step- Returns:
- a range of double values as specified or the empty range if
from > toInclusiveandstep > 0or
from < toInclusiveandstep < 0 - Throws:
java.lang.IllegalArgumentException- ifstepis zero
-
rangeClosed
public static TreeSet<java.lang.Long> rangeClosed(long from, long toInclusive)
Creates a TreeSet of long numbers starting fromfrom, extending totoInclusive.Examples:
TreeSet.rangeClosed(0L, 0L) // = TreeSet(0L) TreeSet.rangeClosed(2L, 0L) // = TreeSet() TreeSet.rangeClosed(-2L, 2L) // = TreeSet(-2L, -1L, 0L, 1L, 2L)- Parameters:
from- the first numbertoInclusive- the last number- Returns:
- a range of long values as specified or the empty range if
from > toInclusive
-
rangeClosedBy
public static TreeSet<java.lang.Long> rangeClosedBy(long from, long toInclusive, long step)
Creates a TreeSet of long numbers starting fromfrom, extending totoInclusive, withstep.Examples:
TreeSet.rangeClosedBy(1L, 3L, 1L) // = TreeSet(1L, 2L, 3L) TreeSet.rangeClosedBy(1L, 4L, 2L) // = TreeSet(1L, 3L) TreeSet.rangeClosedBy(4L, 1L, -2L) // = TreeSet(4L, 2L) TreeSet.rangeClosedBy(4L, 1L, 2L) // = TreeSet()- Parameters:
from- the first numbertoInclusive- the last numberstep- the step- Returns:
- a range of int values as specified or the empty range if
from > toInclusiveandstep > 0or
from < toInclusiveandstep < 0 - Throws:
java.lang.IllegalArgumentException- ifstepis zero
-
add
public TreeSet<T> add(T element)
Description copied from interface:SetReturns a new set containing all elements of this set plus the given element, if it was not already present.
-
addAll
public TreeSet<T> addAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:SetReturns a new set containing all elements of this set plus the given elements, excluding duplicates.
-
collect
public <R> TreeSet<R> collect(@NonNull PartialFunction<? super T,? extends R> partialFunction)
Description copied from interface:TraversableApplies aPartialFunctionto all elements that are defined for it and collects the results.For each element in iteration order, the function is first tested:
IfpartialFunction.isDefinedAt(element)true, the element is mapped to typeR:R newElement = partialFunction.apply(element)Note: If this
Traversableis ordered (i.e., extendsOrdered), the caller must ensure that the resulting elements are comparable (i.e., implementComparable).- Specified by:
collectin interfaceSet<T>- Specified by:
collectin interfaceSortedSet<T>- Specified by:
collectin interfaceTraversable<T>- Type Parameters:
R- the type of elements in the resultingTraversable- Parameters:
partialFunction- a function that may not be defined for all elements of this traversable- Returns:
- a new
Traversablecontaining the results of applying the partial function
-
comparator
public java.util.Comparator<T> comparator()
Description copied from interface:OrderedReturns the comparator that governs the ordering of elements in this collection. The returned comparator must be consistent with the collection's iteration order.- Specified by:
comparatorin interfaceOrdered<T>- Returns:
- the comparator defining the element order
-
diff
public TreeSet<T> diff(@NonNull Set<? extends T> elements)
Description copied from interface:SetReturns a new set containing all elements of this set except those in the given set.
-
contains
public boolean contains(T element)
Description copied from interface:ValueShortcut forexists(e -> Objects.equals(e, element)), tests if the givenelementis contained.
-
distinct
public TreeSet<T> distinct()
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance with all duplicates removed. Element equality is determined usingequals.
-
distinctBy
public TreeSet<T> distinctBy(@NonNull java.util.Comparator<? super T> comparator)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, as determined by the givencomparator.- Specified by:
distinctByin interfaceSet<T>- Specified by:
distinctByin interfaceSortedSet<T>- Specified by:
distinctByin interfaceTraversable<T>- Parameters:
comparator- a comparator used to determine equality of elements- Returns:
- a new
Traversablewith duplicates removed
-
distinctBy
public <U> TreeSet<T> distinctBy(@NonNull java.util.function.Function<? super T,? extends U> keyExtractor)
Description copied from interface:TraversableReturns a newTraversablecontaining the elements of this instance without duplicates, based on keys extracted from elements usingkeyExtractor.The first occurrence of each key is retained in the resulting sequence.
- Specified by:
distinctByin interfaceSet<T>- Specified by:
distinctByin interfaceSortedSet<T>- Specified by:
distinctByin interfaceTraversable<T>- Type Parameters:
U- the type of key- Parameters:
keyExtractor- a function to extract keys for determining uniqueness- Returns:
- a new
Traversablewith duplicates removed based on keys
-
drop
public TreeSet<T> drop(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the firstnelements, or an empty instance if this contains fewer thannelements.
-
dropRight
public TreeSet<T> dropRight(int n)
Description copied from interface:TraversableReturns a newTraversablewithout the lastnelements, or an empty instance if this contains fewer thannelements.
-
dropUntil
public TreeSet<T> dropUntil(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that satisfies the givenpredicate, dropping all preceding elements.
-
dropWhile
public TreeSet<T> dropWhile(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a newTraversablestarting from the first element that does not satisfy the givenpredicate, dropping all preceding elements.This is equivalent to
dropUntil(predicate.negate()), which is useful for method references that cannot be negated directly.
-
filter
public TreeSet<T> filter(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that satisfy the given predicate.
-
reject
public TreeSet<T> reject(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableReturns a new traversable containing only the elements that do not satisfy the given predicate.This is equivalent to
filter(predicate.negate()).
-
flatMap
public <U> TreeSet<U> flatMap(@NonNull java.util.Comparator<? super U> comparator, @NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
Description copied from interface:SortedSetSame asSortedSet.flatMap(Function)but using a specific comparator for values of the codomain of the givenmapper.
-
flatMap
public <U> TreeSet<U> flatMap(@NonNull java.util.function.Function<? super T,? extends java.lang.Iterable<? extends U>> mapper)
Description copied from interface:TraversableTransforms each element of this Traversable into anIterableof elements and flattens the resulting iterables into a single Traversable.- Specified by:
flatMapin interfaceSet<T>- Specified by:
flatMapin interfaceSortedSet<T>- Specified by:
flatMapin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the resulting Traversable- Parameters:
mapper- a function mapping elements to iterables- Returns:
- a new Traversable containing all elements produced by applying
mapperand flattening
-
foldRight
public <U> U foldRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> f)Description copied from interface:FoldableFolds the elements of this structure from the right, starting with the givenzerovalue and successively applying thecombinefunction to each element.Folding from the right means that elements are combined starting from the last element and associating each step with the accumulated result so far.
Example:
// Result: "!cba" List.of("a", "b", "c").foldRight("!", (x, acc) -> acc + x);- Specified by:
foldRightin interfaceFoldable<T>- Specified by:
foldRightin interfaceTraversable<T>- Type Parameters:
U- the type of the accumulated result- Parameters:
zero- the initial value to start folding withf- a function that combines the next element and the accumulated value- Returns:
- the folded result
-
groupBy
public <C> Map<C,TreeSet<T>> groupBy(@NonNull java.util.function.Function<? super T,? extends C> classifier)
Description copied from interface:TraversableGroups elements of thisTraversablebased on a classifier function.- Specified by:
groupByin interfaceSet<T>- Specified by:
groupByin interfaceSortedSet<T>- Specified by:
groupByin interfaceTraversable<T>- Type Parameters:
C- The type of the group keys- Parameters:
classifier- A function that assigns each element to a group- Returns:
- A map where each key corresponds to a group of elements
- See Also:
Traversable.arrangeBy(Function)
-
grouped
public Iterator<TreeSet<T>> grouped(int size)
Description copied from interface:TraversableSplits thisTraversableinto consecutive blocks of the given size.Let
lengthbe the number of elements in thisTraversable:- If empty, the resulting
Iteratoris empty. - If
size <= length, the resultingIteratorcontainslength / sizeblocks of sizesizeand possibly a final smaller block of sizelength % size. - If
size > length, the resultingIteratorcontains a single block of sizelength.
Examples:
[].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]]Note:
grouped(size)is equivalent tosliding(size, size). - If empty, the resulting
-
hasDefiniteSize
public boolean hasDefiniteSize()
Description copied from interface:TraversableIndicates whether thisTraversablehas a known finite size.This should typically be implemented by concrete classes, not interfaces.
- Specified by:
hasDefiniteSizein interfaceTraversable<T>- Returns:
trueif the number of elements is finite and known,falseotherwise.
-
head
public T head()
Description copied from interface:TraversableReturns the first element of this non-emptyTraversable.- Specified by:
headin interfaceTraversable<T>- Returns:
- the first element
-
headOption
public Option<T> headOption()
Description copied from interface:TraversableReturns the first element of thisTraversableas anOption.- Specified by:
headOptionin interfaceTraversable<T>- Returns:
Some(element)if non-empty, otherwiseNone
-
init
public TreeSet<T> init()
Description copied from interface:TraversableReturns all elements of this Traversable except the last one.This is the dual of
Traversable.tail().
-
initOption
public Option<TreeSet<T>> initOption()
Description copied from interface:TraversableReturns all elements of this Traversable except the last one, wrapped in anOption.This is the dual of
Traversable.tailOption().- Specified by:
initOptionin interfaceSet<T>- Specified by:
initOptionin interfaceSortedSet<T>- Specified by:
initOptionin interfaceTraversable<T>- Returns:
Some(traversable)if non-empty, orNoneif this Traversable is empty
-
intersect
public TreeSet<T> intersect(@NonNull Set<? extends T> elements)
Description copied from interface:SetReturns a new set containing only the elements present in both this set and the given set.
-
isAsync
public boolean isAsync()
ATreeSetis computed synchronously.
-
isEmpty
public boolean isEmpty()
Description copied from interface:TraversableChecks if this Traversable contains no elements.
-
isLazy
public boolean isLazy()
ATreeSetis computed eagerly.
-
isTraversableAgain
public boolean isTraversableAgain()
Description copied from interface:TraversableChecks if this Traversable can be traversed multiple times without side effects.Implementations should provide the correct behavior; this is not meant for interfaces alone.
- Specified by:
isTraversableAgainin interfaceTraversable<T>- Returns:
trueif this Traversable is guaranteed to be repeatably traversable,falseotherwise
-
iterator
public @NonNull Iterator<T> iterator()
Description copied from interface:TraversableReturns an iterator over the elements of this Traversable, implemented viaTraversable.head()andTraversable.tail(). Subclasses may override for a more efficient implementation.
-
last
public T last()
Description copied from interface:TraversableReturns the last element of this Traversable.- Specified by:
lastin interfaceTraversable<T>- Returns:
- the last element
-
length
public int length()
Description copied from interface:TraversableReturns the number of elements in this Traversable.Equivalent to
Traversable.size().
-
map
public <U> TreeSet<U> map(@NonNull java.util.Comparator<? super U> comparator, @NonNull java.util.function.Function<? super T,? extends U> mapper)
Description copied from interface:SortedSetSame asSortedSet.map(Function)but using a specific comparator for values of the codomain of the givenmapper.
-
map
public <U> TreeSet<U> map(@NonNull java.util.function.Function<? super T,? extends U> mapper)
Description copied from interface:TraversableTransforms the elements of this Traversable to a new type, preserving order if defined.- Specified by:
mapin interfaceSet<T>- Specified by:
mapin interfaceSortedSet<T>- Specified by:
mapin interfaceTraversable<T>- Specified by:
mapin interfaceValue<T>- Type Parameters:
U- the target element type- Parameters:
mapper- a mapping function- Returns:
- a new Traversable containing the mapped elements
-
mapTo
public <U> TreeSet<U> mapTo(U value)
Description copied from interface:ValueMaps the underlying value to another fixed value.
-
mapToVoid
public TreeSet<java.lang.Void> mapToVoid()
Description copied from interface:ValueMaps the underlying value to Void
-
orElse
public TreeSet<T> orElse(@NonNull java.lang.Iterable<? extends T> other)
Returns thisTreeSetif it is nonempty, otherwiseTreeSetcreated from iterable, using existing comparator.
-
orElse
public TreeSet<T> orElse(@NonNull java.util.function.Supplier<? extends java.lang.Iterable<? extends T>> supplier)
Returns thisTreeSetif it is nonempty, otherwiseTreeSetcreated from result of evaluating supplier, using existing comparator.- Specified by:
orElsein interfaceSet<T>- Specified by:
orElsein interfaceSortedSet<T>- Specified by:
orElsein interfaceTraversable<T>- Parameters:
supplier- An alternativeTraversable- Returns:
- this
TreeSetif it is nonempty, otherwiseTreeSetcreated from result of evaluating supplier, using existing comparator.
-
partition
public Tuple2<TreeSet<T>,TreeSet<T>> partition(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableSplits thisTraversableinto two partitions according to a predicate.The first partition contains all elements that satisfy the predicate, and the second contains all elements that do not. The original iteration order is preserved.
-
peek
public TreeSet<T> peek(@NonNull java.util.function.Consumer<? super T> action)
Description copied from interface:ValuePerforms the givenactionon the first element if this is an eager implementation. Performs the givenactionon all elements (the first immediately, successive deferred), if this is a lazy implementation.
-
remove
public TreeSet<T> remove(T element)
Description copied from interface:SetReturns a new set with the given element removed, if it was present.
-
removeAll
public TreeSet<T> removeAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:SetReturns a new set with all given elements removed, if present.
-
replace
public TreeSet<T> replace(T currentElement, T newElement)
Description copied from interface:TraversableReplaces the first occurrence ofcurrentElementwithnewElement, if it exists.- Specified by:
replacein interfaceSet<T>- Specified by:
replacein interfaceSortedSet<T>- Specified by:
replacein interfaceTraversable<T>- Parameters:
currentElement- the element to be replacednewElement- the replacement element- Returns:
- a new Traversable with the first occurrence of
currentElementreplaced bynewElement
-
replaceAll
public TreeSet<T> replaceAll(T currentElement, T newElement)
Description copied from interface:TraversableReplaces all occurrences ofcurrentElementwithnewElement.- Specified by:
replaceAllin interfaceSet<T>- Specified by:
replaceAllin interfaceSortedSet<T>- Specified by:
replaceAllin interfaceTraversable<T>- Parameters:
currentElement- the element to be replacednewElement- the replacement element- Returns:
- a new Traversable with all occurrences of
currentElementreplaced bynewElement
-
retainAll
public TreeSet<T> retainAll(@NonNull java.lang.Iterable<? extends T> elements)
Description copied from interface:TraversableRetains only the elements from this Traversable that are contained in the givenelements.
-
scan
public TreeSet<T> scan(T zero, @NonNull java.util.function.BiFunction<? super T,? super T,? extends T> operation)
Description copied from interface:TraversableComputes a prefix scan of the elements of this Traversable.The neutral element
zeromay be applied more than once.
-
scanLeft
public <U> Set<U> scanLeft(U zero, @NonNull java.util.function.BiFunction<? super U,? super T,? extends U> operation)
Description copied from interface:TraversableProduces a collection containing cumulative results of applying the operator from left to right.Will not terminate for infinite collections. The results may vary across runs unless the collection is ordered.
- Specified by:
scanLeftin interfaceSet<T>- Specified by:
scanLeftin interfaceSortedSet<T>- Specified by:
scanLeftin interfaceTraversable<T>- Type Parameters:
U- the type of the resulting elements- Parameters:
zero- the initial valueoperation- a binary operator applied to the intermediate result and each element- Returns:
- a new Traversable containing the cumulative results
-
scanRight
public <U> Set<U> scanRight(U zero, @NonNull java.util.function.BiFunction<? super T,? super U,? extends U> operation)
Description copied from interface:TraversableProduces a collection containing cumulative results of applying the operator from right to left.The head of the resulting collection is the last cumulative result. Will not terminate for infinite collections. Results may vary across runs unless the collection is ordered.
- Specified by:
scanRightin interfaceSet<T>- Specified by:
scanRightin interfaceSortedSet<T>- Specified by:
scanRightin interfaceTraversable<T>- Type Parameters:
U- the type of the resulting elements- Parameters:
zero- the initial valueoperation- a binary operator applied to each element and the intermediate result- Returns:
- a new Traversable containing the cumulative results
-
slideBy
public Iterator<TreeSet<T>> slideBy(@NonNull java.util.function.Function<? super T,?> classifier)
Description copied from interface:TraversablePartitions thisTraversableinto consecutive non-overlapping windows according to a classification function.Each window contains elements with the same class, as determined by
classifier. Two consecutive elements belong to the same window only ifclassifierreturns equal values for both. Otherwise, the current window ends and a new window begins with the next element.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]]
-
sliding
public Iterator<TreeSet<T>> sliding(int size)
Description copied from interface:TraversableSlides a window of a givensizeover thisTraversablewith a step size of 1.This is equivalent to calling
Traversable.sliding(int, int)with a step size of 1.
-
sliding
public Iterator<TreeSet<T>> sliding(int size, int step)
Description copied from interface:TraversableSlides a window of a specificsizewith a givenstepover thisTraversable.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]]
-
span
public Tuple2<TreeSet<T>,TreeSet<T>> span(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableSplits thisTraversableinto a prefix and remainder according to the givenpredicate.The first element of the returned
Tupleis the longest prefix of elements satisfyingpredicate, and the second element is the remaining elements.
-
tail
public TreeSet<T> tail()
Description copied from interface:TraversableReturns a newTraversablewithout its first element.
-
tailOption
public Option<TreeSet<T>> tailOption()
Description copied from interface:TraversableReturns a newTraversablewithout its first element as anOption.- Specified by:
tailOptionin interfaceSet<T>- Specified by:
tailOptionin interfaceSortedSet<T>- Specified by:
tailOptionin interfaceTraversable<T>- Returns:
Some(traversable)if non-empty, otherwiseNone
-
take
public TreeSet<T> take(int n)
Description copied from interface:TraversableReturns the firstnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(0, max(0, min(length(), n))), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.
-
takeRight
public TreeSet<T> takeRight(int n)
Description copied from interface:TraversableReturns the lastnelements of thisTraversable, or all elements ifnexceeds the length.Equivalent to
sublist(max(0, length() - n), length()), but safe forn < 0orn > length().If
n < 0, an empty instance is returned. Ifn > length(), the full instance is returned.
-
takeUntil
public TreeSet<T> takeUntil(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableTakes elements from thisTraversableuntil the given predicate holds for an element.Equivalent to
takeWhile(predicate.negate()), but useful when using method references that cannot be negated directly.- Specified by:
takeUntilin interfaceSet<T>- Specified by:
takeUntilin interfaceSortedSet<T>- Specified by:
takeUntilin interfaceTraversable<T>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining all elements before the first one that satisfies the predicate
-
takeWhile
public TreeSet<T> takeWhile(@NonNull java.util.function.Predicate<? super T> predicate)
Description copied from interface:TraversableTakes elements from thisTraversablewhile the given predicate holds.- Specified by:
takeWhilein interfaceSet<T>- Specified by:
takeWhilein interfaceSortedSet<T>- Specified by:
takeWhilein interfaceTraversable<T>- Parameters:
predicate- a condition tested sequentially on the elements- Returns:
- a new
Traversablecontaining all elements up to (but not including) the first one that does not satisfy the predicate
-
transform
public <U> U transform(java.util.function.Function<? super TreeSet<T>,? extends U> f)
Transforms thisTreeSet.- Type Parameters:
U- Type of transformation result- Parameters:
f- A transformation- Returns:
- An instance of type
U - Throws:
java.lang.NullPointerException- iffis null
-
toJavaSet
public java.util.TreeSet<T> toJavaSet()
Description copied from interface:SetConverts this Vavr set to ajava.util.Set, preserving insertion or sort order.
-
union
public TreeSet<T> union(@NonNull Set<? extends T> elements)
Description copied from interface:SetReturns a new set containing all distinct elements from this set and the given set.
-
unzip
public <T1,T2> Tuple2<TreeSet<T1>,TreeSet<T2>> unzip(@NonNull java.util.function.Function<? super T,Tuple2<? extends T1,? extends T2>> unzipper)
Description copied from interface:TraversableUnzips the elements of thisTraversableby mapping each element to a pair and splitting them into two separateTraversablecollections.- Specified by:
unzipin interfaceSet<T>- Specified by:
unzipin interfaceSortedSet<T>- Specified by:
unzipin interfaceTraversable<T>- Type Parameters:
T1- type of the first element in the resulting pairsT2- type of the second element in the resulting pairs- Parameters:
unzipper- a function that maps elements of thisTraversableto pairs- Returns:
- a
Tuple2containing twoTraversablecollections with the split elements
-
unzip3
public <T1,T2,T3> Tuple3<TreeSet<T1>,TreeSet<T2>,TreeSet<T3>> unzip3(@NonNull java.util.function.Function<? super T,Tuple3<? extends T1,? extends T2,? extends T3>> unzipper)
Description copied from interface:TraversableUnzips the elements of thisTraversableby mapping each element to a triple and splitting them into three separateTraversablecollections.- Specified by:
unzip3in interfaceSet<T>- Specified by:
unzip3in interfaceSortedSet<T>- Specified by:
unzip3in interfaceTraversable<T>- Type Parameters:
T1- type of the first element in the resulting triplesT2- type of the second element in the resulting triplesT3- type of the third element in the resulting triples- Parameters:
unzipper- a function that maps elements of thisTraversableto triples- Returns:
- a
Tuple3containing threeTraversablecollections with the split elements
-
zip
public <U> TreeSet<Tuple2<T,U>> zip(@NonNull java.lang.Iterable<? extends U> that)
Description copied from interface:TraversableReturns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable. Pairing stops when either collection runs out of elements; any remaining elements in the longer collection are ignored.The length of the resulting
Traversableis the minimum of the lengths of thisTraversableandthat.- Specified by:
zipin interfaceSet<T>- Specified by:
zipin interfaceSortedSet<T>- Specified by:
zipin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the second half of each pair- Parameters:
that- anIterableproviding the second element of each pair- Returns:
- a new
Traversablecontaining pairs of corresponding elements
-
zipWith
public <U,R> TreeSet<R> zipWith(@NonNull java.lang.Iterable<? extends U> that, java.util.function.BiFunction<? super T,? super U,? extends R> mapper)
Description copied from interface:TraversableReturns aTraversableby combining elements of thisTraversablewith elements of anotherIterableusing a mapping function. Pairing stops when either collection runs out of elements.The length of the resulting
Traversableis the minimum of the lengths of thisTraversableandthat.- Specified by:
zipWithin interfaceSet<T>- Specified by:
zipWithin interfaceSortedSet<T>- Specified by:
zipWithin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the second parameter of the mapperR- the type of elements in the resultingTraversable- Parameters:
that- anIterableproviding the second parameter of the mappermapper- a function that combines elements from this andthatinto a new element- Returns:
- a new
Traversablecontaining mapped elements
-
zipAll
public <U> TreeSet<Tuple2<T,U>> zipAll(@NonNull java.lang.Iterable<? extends U> that, T thisElem, U thatElem)
Description copied from interface:TraversableReturns aTraversableformed by pairing elements of thisTraversablewith elements of anotherIterable, filling in placeholder elements when one collection is shorter than the other.The length of the resulting
Traversableis the maximum of the lengths of thisTraversableandthat.If this
Traversableis shorter thanthat,thisElemis used as a filler. Conversely, ifthatis shorter,thatElemis used.- Specified by:
zipAllin interfaceSet<T>- Specified by:
zipAllin interfaceSortedSet<T>- Specified by:
zipAllin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the second half of each pair- Parameters:
that- anIterableproviding the second element of each pairthisElem- the element used to fill missing values if thisTraversableis shorter thanthatthatElem- the element used to fill missing values ifthatis shorter than thisTraversable- Returns:
- a new
Traversablecontaining pairs of elements, including fillers as needed
-
zipWithIndex
public TreeSet<Tuple2<T,java.lang.Integer>> zipWithIndex()
Description copied from interface:TraversableZips thisTraversablewith its indices, starting at 0.- Specified by:
zipWithIndexin interfaceSet<T>- Specified by:
zipWithIndexin interfaceSortedSet<T>- Specified by:
zipWithIndexin interfaceTraversable<T>- Returns:
- a new
Traversablecontaining each element paired with its index
-
zipWithIndex
public <U> SortedSet<U> zipWithIndex(@NonNull java.util.function.BiFunction<? super T,? super java.lang.Integer,? extends U> mapper)
Description copied from interface:TraversableZips thisTraversablewith its indices and maps the resulting pairs using the provided mapper.- Specified by:
zipWithIndexin interfaceSet<T>- Specified by:
zipWithIndexin interfaceSortedSet<T>- Specified by:
zipWithIndexin interfaceTraversable<T>- Type Parameters:
U- the type of elements in the resultingTraversable- Parameters:
mapper- a function mapping an element and its index to a new element- Returns:
- a new
Traversablecontaining the mapped elements
-
equals
public boolean equals(java.lang.Object o)
Description copied from interface:TraversableDetermines whether this collection is equal to the given object.In Vavr, there are four basic collection types:
Seq– sequential elementsSet– distinct elementsMap– key-value pairsMultimap– keys mapped to multiple values
- They are of the same collection type (Seq, Set, Map, Multimap)
- They contain the same elements
- For
Seq, the element order is the same
For
MapandMultimap, two entries(key1, value1)and(key2, value2)are equal if both their keys and values are equal.Additional notes:
- No collection equals
null(e.g.,Queue(1) != null) - Null elements are allowed and treated as expected
(e.g.,
List(null, 1) == Stream(null, 1),HashMap((null,1)) == LinkedHashMap((null,1))) - Element order matters only for
Seq - Other collection classes are equal if their types and elements (in iteration order) are equal
- Iterators are compared by reference only
-
hashCode
public int hashCode()
Description copied from interface:TraversableReturns the hash code of this collection.Vavr distinguishes between collections with predictable iteration order (like
Seq) and collections with arbitrary iteration order (likeSet,Map, andMultimap). In all cases, the hash of an empty collection is defined as1.For collections with predictable iteration order, the hash is computed as:
int hash = 1; for (T t : this) { hash = hash * 31 + Objects.hashCode(t); }For collections with arbitrary iteration order, the hash is computed to be independent of element order:
int hash = 1; for (T t : this) { hash += Objects.hashCode(t); }Note that these algorithms may change in future Vavr versions. Hash codes are generally not cached, unlike size/length, because caching would increase memory usage due to persistent tree-based structures. Computing the hash code is linear in time, O(n). For frequently re-used collections (e.g., as
HashMapkeys), caching can be done externally using a wrapper, for example:{@code public final class Hashed{ private final K key; private final Lazy hashCode; public Hashed(K key) { this.key = key; this.hashCode = Lazy.of(() -> Objects.hashCode(key)); } public K key() { return key; }
-
stringPrefix
public java.lang.String stringPrefix()
Description copied from interface:ValueReturns the name of this Value type, which is used by toString().- Specified by:
stringPrefixin interfaceValue<T>- Returns:
- This type name.
-
toString
public java.lang.String toString()
Description copied from interface:ValueClarifies that values have a proper toString() method implemented.See Object.toString().
-
-