Class TreeSet<E>
- java.lang.Object
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractIterable<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractSet<E>
-
- com.github.andrewoma.dexx.collection.internal.base.AbstractSortedSet<E>
-
- com.github.andrewoma.dexx.collection.TreeSet<E>
-
- All Implemented Interfaces:
Iterable<E>
,Set<E>
,SortedSet<E>
,Traversable<E>
,java.lang.Iterable<E>
public class TreeSet<E> extends AbstractSortedSet<E>
TreeSet
is an implementation ofSortedSet
backed by aTreeMap
.
-
-
Field Summary
Fields Modifier and Type Field Description protected static TreeSet
EMPTY
private RedBlackTree<E,E>
redBlackTree
private Tree<E,E>
tree
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description @NotNull TreeSet<E>
add(E value)
Returns a set that adds the specified value if it doesn't already exist in this set.java.util.Comparator<? super E>
comparator()
Returns the comparator associated with this map, ornull
if the default ordering is used.boolean
contains(E value)
Returns true if the value exists in this set.@NotNull SortedSet<E>
drop(int number)
Returns a set containing all elements in this set, excluding the firstnumber
of elements.static <E> @NotNull TreeSet<E>
empty()
static <E> @NotNull BuilderFactory<E,TreeSet<E>>
factory(java.util.Comparator<? super E> ordering)
E
first()
Returns the first element in the set ornull
of the set is empty.@NotNull SortedSet<E>
from(E value, boolean inclusive)
Returns the bottom of the set starting from the key specified.@NotNull java.util.Iterator<E>
iterator()
E
last()
Returns the last element in the set ornull
of the set is empty.@NotNull SortedSet<E>
range(E from, boolean fromInclusive, E to, boolean toInclusive)
Returns a subset of the set between thefrom
andto
keys specified.@NotNull TreeSet<E>
remove(E value)
Removes the specified value from the set if it exists.int
size()
Returns the size of the collection.@NotNull SortedSet<E>
take(int number)
Returns a set containing the firstnumber
of elements from this set.@NotNull SortedSet<E>
to(E value, boolean inclusive)
Returns the top of the set up until the key specified.-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractSortedSet
asSortedSet
-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractSet
asSet, equals, hashCode
-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractIterable
forEach
-
Methods inherited from class com.github.andrewoma.dexx.collection.internal.base.AbstractTraversable
isEmpty, makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.andrewoma.dexx.collection.Traversable
forEach, isEmpty, makeString, makeString, to, toArray, toArray, toIndexedList, toSet, toSortedSet
-
-
-
-
Method Detail
-
factory
@NotNull public static <E> @NotNull BuilderFactory<E,TreeSet<E>> factory(java.util.Comparator<? super E> ordering)
-
empty
@NotNull public static <E> @NotNull TreeSet<E> empty()
-
comparator
public java.util.Comparator<? super E> comparator()
Description copied from interface:SortedSet
Returns the comparator associated with this map, ornull
if the default ordering is used.
-
add
@NotNull public @NotNull TreeSet<E> add(E value)
Description copied from interface:Set
Returns a set that adds the specified value if it doesn't already exist in this set.
-
remove
@NotNull public @NotNull TreeSet<E> remove(E value)
Description copied from interface:Set
Removes the specified value from the set if it exists.
-
contains
public boolean contains(E value)
Description copied from interface:Set
Returns true if the value exists in this set.
-
size
public int size()
Description copied from interface:Traversable
Returns the size of the collection.Warning: infinite collections are possible, as are collections that require traversal to calculate the size.
- Specified by:
size
in interfaceTraversable<E>
- Overrides:
size
in classAbstractTraversable<E>
-
first
@Nullable public E first()
Description copied from interface:SortedSet
Returns the first element in the set ornull
of the set is empty.
-
last
@Nullable public E last()
Description copied from interface:SortedSet
Returns the last element in the set ornull
of the set is empty.
-
iterator
@NotNull public @NotNull java.util.Iterator<E> iterator()
-
drop
@NotNull public @NotNull SortedSet<E> drop(int number)
Description copied from interface:SortedSet
Returns a set containing all elements in this set, excluding the firstnumber
of elements.
-
take
@NotNull public @NotNull SortedSet<E> take(int number)
Description copied from interface:SortedSet
Returns a set containing the firstnumber
of elements from this set.
-
from
@NotNull public @NotNull SortedSet<E> from(@NotNull E value, boolean inclusive)
Description copied from interface:SortedSet
Returns the bottom of the set starting from the key specified.
-
to
@NotNull public @NotNull SortedSet<E> to(@NotNull E value, boolean inclusive)
Description copied from interface:SortedSet
Returns the top of the set up until the key specified.
-
range
@NotNull public @NotNull SortedSet<E> range(@NotNull E from, boolean fromInclusive, @NotNull E to, boolean toInclusive)
Description copied from interface:SortedSet
Returns a subset of the set between thefrom
andto
keys specified.fromInclusive
- if true, the key will be included in the result, otherwise it will be excludedtoInclusive
- if true, the key will be included in the result, otherwise it will be excluded
-
-