java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<E>
org.pcollections.AbstractUnmodifiableSet<E>
org.pcollections.TreePSet<E>
- Type Parameters:
E- the type of elements maintained by this set
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,NavigableSet<E>,Set<E>,SortedSet<E>,PCollection<E>,PSet<E>,PSortedSet<E>
public final class TreePSet<E>
extends AbstractUnmodifiableSet<E>
implements PSortedSet<E>, Serializable
An implementation of
PSortedSet based on a self-balancing binary search tree.
Null values are not allowed.
Instances of this class are obtained via any of various static factory methods and static collector methods. These methods come in pairs, with one version that accepts an explicit comparator to use and one version that uses the natural ordering of the elements.
All operations are guaranteed to complete within O(log n) time, except for plusAll and minusAll, whose time cost is equivalent to the corresponding sequence of calls to plus or minus. A complete iteration pass completes in O(n) time. A few operations -- namely comparator, descendingSet, isEmpty, and size -- complete in O(1) time.
- Since:
- 3.2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionComparator<? super E>booleanstatic <E extends Comparable<? super E>>
TreePSet<E>empty()Returns an empty TreePSet using the natural ordering.static <E> TreePSet<E>empty(Comparator<? super E> comparator) Returns an empty TreePSet using the specified comparator.first()static <E extends Comparable<? super E>>
TreePSet<E>from(Collection<? extends E> list) Returns a TreePSet with the specified elements, using their natural ordering.static <E> TreePSet<E>from(Comparator<? super E> comparator, Collection<? extends E> list) Returns a TreePSet with the specified comparator and elements.static <E> TreePSet<E>fromSortedSet(SortedSet<E> set) Returns a TreePSet with the same elements and ordering as the specified set.intersect(Collection<? extends E> list) iterator()last()minusAll(Collection<?> list) static <E extends Comparable<? super E>>
TreePSet<E>of(E... elements) Returns a TreePSet with the specified elements, using their natural ordering.static <E> TreePSet<E>of(Comparator<? super E> comparator, E... elements) Returns a TreePSet with the specified comparator and elements.plusAll(Collection<? extends E> list) static <E extends Comparable<? super E>>
TreePSet<E>singleton(E e) Returns a TreePSet with a single element, using the natural ordering.static <E> TreePSet<E>singleton(Comparator<? super E> comparator, E e) Returns a TreePSet with a single element, using the specified comparator.intsize()static <E extends Comparable<? super E>>
Collector<E,?, TreePSet<E>> Returns a collector that gathers a stream into a TreePSet with the elements of that stream, using their natural ordering.toTreePSet(Comparator<? super E> comparator) Returns a collector that gathers a stream into a TreePSet with the elements of that stream, using the specified comparator.Methods inherited from class org.pcollections.AbstractUnmodifiableSet
add, addAll, clear, remove, removeAll, removeIf, retainAllMethods inherited from class java.util.AbstractSet
equals, hashCodeMethods inherited from class java.util.AbstractCollection
containsAll, isEmpty, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface org.pcollections.PCollection
add, addAll, clear, remove, removeAll, retainAllMethods inherited from interface org.pcollections.PSortedSet
pollFirst, pollLastMethods inherited from interface java.util.Set
add, addAll, clear, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArrayMethods inherited from interface java.util.SortedSet
spliterator
-
Method Details
-
empty
Returns an empty TreePSet using the natural ordering.- Type Parameters:
E- the type of elements to be maintained by the set- Returns:
- an empty TreePSet using the natural ordering
-
empty
Returns an empty TreePSet using the specified comparator.- Type Parameters:
E- the type of elements to be maintained by the set- Parameters:
comparator- the comparator according to which elements should be ordered- Returns:
- an empty TreePSet using the specified comparator
- Throws:
NullPointerException- if comparator is null
-
from
Returns a TreePSet with the specified elements, using their natural ordering.- Type Parameters:
E- the type of elements to be maintained by the set- Parameters:
list- the elements to include- Returns:
- a TreePSet containing the elements of list and using the natural ordering
- Throws:
NullPointerException- if list is null or contains null
-
from
Returns a TreePSet with the specified comparator and elements.- Type Parameters:
E- the type of elements to be maintained by the set- Parameters:
comparator- the comparator to uselist- the collection of elements to include; may include duplicates, but the returned TreePSet will not- Returns:
- a TreePSet with the specified comparator and elements
- Throws:
NullPointerException- if the comparator is null or the collection is or contains null
-
fromSortedSet
Returns a TreePSet with the same elements and ordering as the specified set. This is essentially equivalent toTreePSet.from(set.comparator(), set), except that it gracefully handles a null comparator, and is much more efficient.- Type Parameters:
E- the type of elements to be maintained by the set- Parameters:
set- the set whose elements and ordering to use- Returns:
- a TreePSet with the same elements and ordering as the specified set
- Throws:
NullPointerException- if the specified set is or contains null
-
of
Returns a TreePSet with the specified elements, using their natural ordering.- Type Parameters:
E- the type of elements to be maintained by the set- Parameters:
elements- the elements to include; may include duplicates, but the returned TreePSet will not- Returns:
- a TreePSet containing the specified elements and using their natural ordering
- Throws:
NullPointerException- if any of the specified elements is null, or if the varargs array-ref is itself null
-
of
Returns a TreePSet with the specified comparator and elements.- Type Parameters:
E- the type of elements to be maintained by the set- Parameters:
comparator- the comparator to useelements- the elements to include; may include duplicates, but the returned TreePSet will not- Returns:
- a TreePSet containing the specified elements and using the specified comparator
- Throws:
NullPointerException- if the specified comparator is null, or if any of the specified elements is null, or if the varargs array-ref is itself null
-
singleton
Returns a TreePSet with a single element, using the natural ordering.- Type Parameters:
E- the type of elements to be maintained by the set- Parameters:
e- the element- Returns:
- a TreePSet containing the specified element and using the natural ordering
- Throws:
NullPointerException- if the specified element is null
-
singleton
Returns a TreePSet with a single element, using the specified comparator.- Type Parameters:
E- the type of elements to be maintained by the set- Parameters:
comparator- the comparator according to which elements should be orderede- the element- Returns:
- a TreePSet containing the specified element and using the specified comparator
- Throws:
NullPointerException- if either the comparator or the element is null
-
toTreePSet
Returns a collector that gathers a stream into a TreePSet with the elements of that stream, using their natural ordering.- Type Parameters:
E- the type of elements to be maintained by the set- Returns:
- a collector that gathers the elements of the stream into a TreePSet that uses the natural ordering
-
toTreePSet
Returns a collector that gathers a stream into a TreePSet with the elements of that stream, using the specified comparator.- Type Parameters:
E- the type of elements to be maintained by the set- Parameters:
comparator- the comparator to use- Returns:
- a collector that gathers the elements of the stream into a TreePSet that uses the specified comparator
- Throws:
NullPointerException- if the comparator is null
-
ceiling
- Specified by:
ceilingin interfaceNavigableSet<E>
-
comparator
- Specified by:
comparatorin interfacePSortedSet<E>- Specified by:
comparatorin interfaceSortedSet<E>- Returns:
- The comparator used to order the elements in this set. May be null if this set uses the natural ordering of its elements, though in that case the implementations provided by this library (pcollections) return a Comparator instance that implements the natural ordering.
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
descendingIterator
- Specified by:
descendingIteratorin interfaceNavigableSet<E>
-
descendingSet
- Specified by:
descendingSetin interfaceNavigableSet<E>- Specified by:
descendingSetin interfacePSortedSet<E>
-
first
-
floor
- Specified by:
floorin interfaceNavigableSet<E>
-
headSet
- Specified by:
headSetin interfaceNavigableSet<E>- Specified by:
headSetin interfacePSortedSet<E>- Specified by:
headSetin interfaceSortedSet<E>
-
headSet
- Specified by:
headSetin interfaceNavigableSet<E>- Specified by:
headSetin interfacePSortedSet<E>
-
higher
- Specified by:
higherin interfaceNavigableSet<E>
-
iterator
- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceNavigableSet<E>- Specified by:
iteratorin interfaceSet<E>- Specified by:
iteratorin classAbstractCollection<E>
-
last
-
lower
- Specified by:
lowerin interfaceNavigableSet<E>
-
minus
- Specified by:
minusin interfacePCollection<E>- Specified by:
minusin interfacePSet<E>- Specified by:
minusin interfacePSortedSet<E>- Returns:
- This set, except with e removed (if e is an element of this set).
-
minusAll
- Specified by:
minusAllin interfacePCollection<E>- Specified by:
minusAllin interfacePSet<E>- Specified by:
minusAllin interfacePSortedSet<E>- Returns:
- This set, except with the elements of list removed (if they are elements of this set).
-
intersect
-
minusFirst
- Specified by:
minusFirstin interfacePSortedSet<E>- Returns:
- This set, except with its first (least) element removed.
-
minusLast
- Specified by:
minusLastin interfacePSortedSet<E>- Returns:
- This set, except with its last (greatest) element removed.
-
plus
- Specified by:
plusin interfacePCollection<E>- Specified by:
plusin interfacePSet<E>- Specified by:
plusin interfacePSortedSet<E>- Returns:
- This set, except with e added (unless e is already an element of this set).
-
plusAll
- Specified by:
plusAllin interfacePCollection<E>- Specified by:
plusAllin interfacePSet<E>- Specified by:
plusAllin interfacePSortedSet<E>- Returns:
- This set, except with the elements of list added (unless they are already elements of this set).
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
subSet
- Specified by:
subSetin interfaceNavigableSet<E>- Specified by:
subSetin interfacePSortedSet<E>- Specified by:
subSetin interfaceSortedSet<E>
-
subSet
- Specified by:
subSetin interfaceNavigableSet<E>- Specified by:
subSetin interfacePSortedSet<E>
-
tailSet
- Specified by:
tailSetin interfaceNavigableSet<E>- Specified by:
tailSetin interfacePSortedSet<E>- Specified by:
tailSetin interfaceSortedSet<E>
-
tailSet
- Specified by:
tailSetin interfaceNavigableSet<E>- Specified by:
tailSetin interfacePSortedSet<E>
-