public class CountingTreeSet<T> extends AbstractBasicCountingSet<T> implements java.util.SortedSet<T>
Because it would be breaking the set semantics removal is not allowed.
All removal methods but AbstractBasicCountingSet.clear()
therefore will throw an UnsupportedOperationException
.
The methods which return subsets will return standard sets, not members of this class.
creator, map
Constructor and Description |
---|
CountingTreeSet()
Deprecated.
use
create() instead because it handles comparability correctly |
CountingTreeSet(java.util.Comparator<? super T> comparator)
Constructor.
|
CountingTreeSet(java.util.Comparator<? super T> comparator,
java.util.function.Supplier<Counter> creator)
Constructor.
|
CountingTreeSet(java.util.function.Supplier<Counter> creator)
Deprecated.
use
create(Supplier) instead because it handles comparability correctly |
Modifier and Type | Method and Description |
---|---|
java.util.Comparator<? super T> |
comparator()
Returns the comparator associated with this sorted set, or
null if it uses its elements' natural ordering.
|
<TT extends java.lang.Comparable<TT>> |
create()
Create a new simple counting tree set.
|
<TT extends java.lang.Comparable<T>> |
create(java.util.function.Supplier<Counter> creator)
Create a new non-threadsafe counting tree set.
|
<TT extends java.lang.Comparable<T>> |
createThreadSafe(java.util.function.Supplier<Counter> creator)
Create a new non-threadsafe counting tree set.
|
T |
first()
Returns the first (lowest) element currently in this sorted set.
|
java.util.SortedSet<T> |
headSet(T toElement)
Returns a view of the portion of this sorted set whose elements are
strictly less than toElement.
|
T |
last()
Returns the last (highest) element currently in this sorted set.
|
java.util.SortedSet<T> |
subSet(T fromElement,
T toElement)
Returns a view of the portion of this sorted set whose elements range
from fromElement, inclusive, to toElement, exclusive.
|
java.util.SortedSet<T> |
tailSet(T fromElement)
Returns a view of the portion of this sorted set whose elements are
greater than or equal to fromElement.
|
add, addAll, clear, contains, containsAll, getCount, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
@Deprecated public CountingTreeSet(@NotNull java.util.function.Supplier<Counter> creator)
create(Supplier)
instead because it handles comparability correctlyThis constructor silently assumes that T is Comparable!
creator
- counter creator used for counter creation,
see Counter.SIMPLE
or Counter.THREAD_SAFE
for standard onespublic CountingTreeSet(@NotNull java.util.Comparator<? super T> comparator, @NotNull java.util.function.Supplier<Counter> creator)
comparator
- comparator for element comparisioncreator
- counter creator used for counter creation,
see Counter.SIMPLE
or Counter.THREAD_SAFE
for standard ones@Deprecated public CountingTreeSet()
create()
instead because it handles comparability correctly
This will use simple counters
.
This constructor silently assumes that T is Comparable!
public CountingTreeSet(@NotNull java.util.Comparator<? super T> comparator)
This will use simple counters
.
comparator
- comparator for element comparison@NotNull public <TT extends java.lang.Comparable<T>> CountingTreeSet<TT> create(@NotNull java.util.function.Supplier<Counter> creator)
TT
- type of set keyscreator
- creator for new elements@NotNull public <TT extends java.lang.Comparable<T>> CountingTreeSet<TT> createThreadSafe(@NotNull java.util.function.Supplier<Counter> creator)
TT
- type of set keyscreator
- creator for new elements@NotNull public <TT extends java.lang.Comparable<TT>> CountingTreeSet<TT> create()
TT
- type of tree setpublic java.util.Comparator<? super T> comparator()
comparator
in interface java.util.SortedSet<T>
@NotNull public java.util.SortedSet<T> subSet(T fromElement, T toElement)
The sorted set returned by this method will throw an IllegalArgumentException if the user attempts to insert a element outside the specified range.
Note: this method always returns a half-open range (which includes its low endpoint but not its high endpoint). If you need a closed range (which includes both endpoints), and the element type allows for calculation of the successor a given value, merely request the subrange from lowEndpoint to successor(highEndpoint). For example, suppose that s is a sorted set of strings. The following idiom obtains a view containing all of the strings in s from low to high, inclusive:
SortedSet sub = s.subSet(low, high+"\0");A similar technique can be used to generate an open range (which contains neither endpoint). The following idiom obtains a view containing all of the Strings in s from low to high, exclusive:
SortedSet sub = s.subSet(low+"\0", high);
subSet
in interface java.util.SortedSet<T>
fromElement
- low endpoint (inclusive) of the subSet.toElement
- high endpoint (exclusive) of the subSet.java.lang.ClassCastException
- if fromElement and
toElement cannot be compared to one another using this
set's comparator (or, if the set has no comparator, using
natural ordering). Implementations may, but are not required
to, throw this exception if fromElement or
toElement cannot be compared to elements currently in
the set.java.lang.IllegalArgumentException
- if fromElement is greater than
toElement; or if this set is itself a subSet, headSet,
or tailSet, and fromElement or toElement are
not within the specified range of the subSet, headSet, or
tailSet.java.lang.NullPointerException
- if fromElement or
toElement is null and this sorted set does
not tolerate null elements.@NotNull public java.util.SortedSet<T> headSet(T toElement)
The sorted set returned by this method will throw an IllegalArgumentException if the user attempts to insert a element outside the specified range.
Note: this method always returns a view that does not contain its (high) endpoint. If you need a view that does contain this endpoint, and the element type allows for calculation of the successor a given value, merely request a headSet bounded by successor(highEndpoint). For example, suppose that s is a sorted set of strings. The following idiom obtains a view containing all of the strings in s that are less than or equal to high:
SortedSet head = s.headSet(high+"\0");
headSet
in interface java.util.SortedSet<T>
toElement
- high endpoint (exclusive) of the headSet.java.lang.ClassCastException
- if toElement is not compatible
with this set's comparator (or, if the set has no comparator,
if toElement does not implement Comparable).
Implementations may, but are not required to, throw this
exception if toElement cannot be compared to elements
currently in the set.java.lang.NullPointerException
- if toElement is null and
this sorted set does not tolerate null elements.java.lang.IllegalArgumentException
- if this set is itself a subSet,
headSet, or tailSet, and toElement is not within the
specified range of the subSet, headSet, or tailSet.@NotNull public java.util.SortedSet<T> tailSet(T fromElement)
The sorted set returned by this method will throw an IllegalArgumentException if the user attempts to insert a element outside the specified range.
Note: this method always returns a view that contains its (low) endpoint. If you need a view that does not contain this endpoint, and the element type allows for calculation of the successor a given value, merely request a tailSet bounded by successor(lowEndpoint). For example, suppose that s is a sorted set of strings. The following idiom obtains a view containing all of the strings in s that are strictly greater than low:
SortedSet tail = s.tailSet(low+"\0");
tailSet
in interface java.util.SortedSet<T>
fromElement
- low endpoint (inclusive) of the tailSet.java.lang.ClassCastException
- if fromElement is not compatible
with this set's comparator (or, if the set has no comparator,
if fromElement does not implement Comparable).
Implementations may, but are not required to, throw this
exception if fromElement cannot be compared to elements
currently in the set.java.lang.NullPointerException
- if fromElement is null
and this sorted set does not tolerate null elements.java.lang.IllegalArgumentException
- if this set is itself a subSet,
headSet, or tailSet, and fromElement is not within the
specified range of the subSet, headSet, or tailSet.public T first()
first
in interface java.util.SortedSet<T>
java.util.NoSuchElementException
- sorted set is empty.