public class ObjectRBTreeSet<K> extends AbstractObjectSortedSet<K> implements Serializable, Cloneable, ObjectSortedSet<K>
The iterators provided by this class are type-specific
bidirectional iterators.
Moreover, the iterator returned by iterator() can be safely cast to a
type-specific list iterator.
| Constructor and Description |
|---|
ObjectRBTreeSet()
Creates a new empty tree set.
|
ObjectRBTreeSet(Collection<? extends K> c)
Creates a new tree set copying a given collection.
|
ObjectRBTreeSet(Comparator<? super K> c)
Creates a new empty tree set with the given comparator.
|
ObjectRBTreeSet(Iterator<? extends K> i)
Creates a new tree set using elements provided by a type-specific
iterator.
|
ObjectRBTreeSet(K[] a)
Creates a new tree set copying the elements of an array.
|
ObjectRBTreeSet(K[] a,
Comparator<? super K> c)
Creates a new tree set copying the elements of an array using a given
Comparator. |
ObjectRBTreeSet(K[] a,
int offset,
int length)
Creates a new tree set and fills it with the elements of a given array.
|
ObjectRBTreeSet(K[] a,
int offset,
int length,
Comparator<? super K> c)
Creates a new tree set and fills it with the elements of a given array
using a given
Comparator. |
ObjectRBTreeSet(ObjectCollection<? extends K> c)
Creates a new tree set copying a given type-specific collection.
|
ObjectRBTreeSet(ObjectSortedSet<K> s)
Creates a new tree set copying a given type-specific sorted set (and its
Comparator). |
ObjectRBTreeSet(SortedSet<K> s)
Creates a new tree set copying a given sorted set (and its
Comparator). |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(K k)
Ensures that this collection contains the specified element (optional
operation).
|
void |
clear()
Removes all of the elements from this collection (optional operation).
|
Object |
clone()
Returns a deep copy of this tree set.
|
Comparator<? super K> |
comparator()
Returns the comparator used to order the elements in this set,
or null if this set uses the natural ordering of its elements.
|
boolean |
contains(Object k)
Returns true if this collection contains the specified element.
|
K |
first()
Returns the first (lowest) element currently in this set.
|
K |
get(Object k) |
ObjectSortedSet<K> |
headSet(K to)
Returns a view of the portion of this sorted set whose elements are
strictly less than
toElement. |
boolean |
isEmpty()
Returns true if this collection contains no elements.
|
ObjectBidirectionalIterator<K> |
iterator()
Returns an iterator over the elements contained in this collection.
|
ObjectBidirectionalIterator<K> |
iterator(K from)
Returns a type-specific
BidirectionalIterator on the elements in
this set, starting from a given element of the domain (optional
operation). |
K |
last()
Returns the last (highest) element currently in this set.
|
boolean |
remove(Object k)
Removes a single instance of the specified element from this
collection, if it is present (optional operation).
|
int |
size()
Returns the number of elements in this collection.
|
ObjectSortedSet<K> |
subSet(K from,
K to)
Returns a view of the portion of this sorted set whose elements range
from
fromElement, inclusive, to toElement, exclusive. |
ObjectSortedSet<K> |
tailSet(K from)
Returns a view of the portion of this sorted set whose elements are
greater than or equal to
fromElement. |
equals, hashCodetoStringaddAll, containsAll, removeAll, retainAll, toArray, toArrayspliteratoraddAll, containsAll, equals, hashCode, removeAll, retainAll, toArray, toArrayparallelStream, removeIf, streampublic ObjectRBTreeSet()
public ObjectRBTreeSet(Comparator<? super K> c)
c - a Comparator (even better, a type-specific
comparator).public ObjectRBTreeSet(Collection<? extends K> c)
c - a collection to be copied into the new tree set.public ObjectRBTreeSet(SortedSet<K> s)
Comparator).s - a SortedSet to be copied into the new tree set.public ObjectRBTreeSet(ObjectCollection<? extends K> c)
c - a type-specific collection to be copied into the new tree set.public ObjectRBTreeSet(ObjectSortedSet<K> s)
Comparator).s - a type-specific sorted set to be copied into the new tree set.public ObjectRBTreeSet(Iterator<? extends K> i)
i - a type-specific iterator whose elements will fill the set.public ObjectRBTreeSet(K[] a, int offset, int length, Comparator<? super K> c)
Comparator.a - an array whose elements will be used to fill the set.offset - the first element to use.length - the number of elements to use.c - a Comparator (even better, a type-specific
comparator).public ObjectRBTreeSet(K[] a, int offset, int length)
a - an array whose elements will be used to fill the set.offset - the first element to use.length - the number of elements to use.public ObjectRBTreeSet(K[] a)
a - an array to be copied into the new tree set.public ObjectRBTreeSet(K[] a, Comparator<? super K> c)
Comparator.a - an array to be copied into the new tree set.c - a Comparator (even better, a type-specific
comparator).public boolean add(K k)
java.util.AbstractCollectionCollections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.
If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.
This implementation always throws an UnsupportedOperationException.
add in interface Collection<K>add in interface Set<K>add in class AbstractCollection<K>k - element whose presence in this collection is to be ensuredpublic boolean remove(Object k)
java.util.AbstractCollectionThis implementation iterates over the collection looking for the specified element. If it finds the element, it removes the element from the collection using the iterator's remove method.
Note that this implementation throws an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection contains the specified object.
remove in interface Collection<K>remove in interface Set<K>remove in class AbstractCollection<K>k - element to be removed from this collection, if presentpublic boolean contains(Object k)
java.util.AbstractCollectionThis implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.
contains in interface Collection<K>contains in interface Set<K>contains in class AbstractCollection<K>k - element whose presence in this collection is to be testedpublic void clear()
java.util.AbstractCollectionThis implementation iterates over this collection, removing each element using the Iterator.remove operation. Most implementations will probably choose to override this method for efficiency.
Note that this implementation will throw an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection is non-empty.
clear in interface Collection<K>clear in interface Set<K>clear in class AbstractCollection<K>public int size()
java.util.Collectionsize in interface Collection<K>size in interface Set<K>size in class AbstractCollection<K>public boolean isEmpty()
java.util.AbstractCollectionThis implementation returns size() == 0.
isEmpty in interface Collection<K>isEmpty in interface Set<K>isEmpty in class AbstractCollection<K>public K first()
java.util.SortedSetpublic K last()
java.util.SortedSetpublic ObjectBidirectionalIterator<K> iterator()
java.util.AbstractCollectioniterator in interface ObjectBidirectionalIterable<K>iterator in interface ObjectCollection<K>iterator in interface ObjectIterable<K>iterator in interface ObjectSet<K>iterator in interface ObjectSortedSet<K>iterator in interface Iterable<K>iterator in interface Collection<K>iterator in interface Set<K>iterator in class AbstractObjectSortedSet<K>Iterable.iterator()public ObjectBidirectionalIterator<K> iterator(K from)
ObjectSortedSetBidirectionalIterator on the elements in
this set, starting from a given element of the domain (optional
operation).
This method returns a type-specific bidirectional iterator with given
starting point. The starting point is any element comparable to the
elements of this set (even if it does not actually belong to the set).
The next element of the returned iterator is the least element of the set
that is greater than the starting point (if there are no elements greater
than the starting point,
hasNext()
will return false). The previous element of the returned iterator
is the greatest element of the set that is smaller than or equal to the
starting point (if there are no elements smaller than or equal to the
starting point,
hasPrevious() will return false).
Note that passing the last element of the set as starting point and
calling previous() you can traverse the entire set in reverse order.
iterator in interface ObjectSortedSet<K>from - an element to start from.public Comparator<? super K> comparator()
java.util.SortedSetcomparator in interface SortedSet<K>public ObjectSortedSet<K> headSet(K to)
ObjectSortedSettoElement.
Note that this specification strengthens the one given in
SortedSet.headSet(Object).
headSet in interface ObjectSortedSet<K>headSet in interface SortedSet<K>to - high endpoint (exclusive) of the returned setSortedSet.headSet(Object)public ObjectSortedSet<K> tailSet(K from)
ObjectSortedSetfromElement.
Note that this specification strengthens the one given in
SortedSet.headSet(Object).
tailSet in interface ObjectSortedSet<K>tailSet in interface SortedSet<K>from - low endpoint (inclusive) of the returned setSortedSet.tailSet(Object)public ObjectSortedSet<K> subSet(K from, K to)
ObjectSortedSetfromElement, inclusive, to toElement, exclusive.
Note that this specification strengthens the one given in
SortedSet.subSet(Object,Object).
subSet in interface ObjectSortedSet<K>subSet in interface SortedSet<K>from - low endpoint (inclusive) of the returned setto - high endpoint (exclusive) of the returned setSortedSet.subSet(Object,Object)public Object clone()
This method performs a deep copy of this tree set; the data stored in the set, however, is not cloned. Note that this makes a difference only for object keys.