NavigableSet
implementation based on
a ConcurrentSkipListMap
. The elements of the set are kept
sorted according to their natural ordering,
or by a Comparator
provided at set creation time, depending
on which constructor is used.
This implementation provides expected average log(n) time
cost for the contains
, add
, and remove
operations and their variants. Insertion, removal, and access
operations safely execute concurrently by multiple threads.
Iterators and spliterators are weakly consistent.
Ascending ordered views and their iterators are faster than descending ones.
Beware that, unlike in most collections, the size
method is not a constant-time operation. Because of the
asynchronous nature of these sets, determining the current number
of elements requires a traversal of the elements, and so may report
inaccurate results if this collection is modified during traversal.
Bulk operations that add, remove, or examine multiple elements,
such as addAll
, removeIf
or forEach
,
are not guaranteed to be performed atomically.
For example, a forEach
traversal concurrent with an addAll
operation might observe only some of the added elements.
This class and its iterators implement all of the
optional methods of the Set
and Iterator
interfaces. Like most other concurrent collection implementations,
this class does not permit the use of null
elements,
because null
arguments and return values cannot be reliably
distinguished from the absence of elements.
This class is a member of the Java Collections Framework.
Modifier and Type | Field and Description |
---|---|
private final ConcurrentNavigableMap | m
The underlying map. |
private static final long |
Access | Constructor and Description |
---|---|
public | ConcurrentSkipListSet()
Constructs a new, empty set that orders its elements according to their natural ordering. |
public | ConcurrentSkipListSet(Comparator<? super E>
the comparator that will be used to order this set.
If comparator)null , the natural
ordering of the elements will be used.Constructs a new, empty set that orders its elements according to the specified comparator. |
public | ConcurrentSkipListSet(Collection<? extends E>
The elements that will comprise the new set c)Constructs a new set containing the elements in the specified collection, that orders its elements according to their natural ordering. |
public | ConcurrentSkipListSet(SortedSet<E>
sorted set whose elements will comprise the new set s)Constructs a new set containing the same elements and using the same ordering as the specified sorted set. |
pack-priv |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if this set did not already contain the
specified elementelement to be added to this set e)Overrides java. Implements java. Adds the specified element to this set if it is not already present. |
public void | addFirst(E
the element to be added e)Overrides default java. Throws |
public void | addLast(E
the element to be added. e)Overrides default java. Throws |
public E | ceiling(E
the value to match e)Implements java. Returns the least element in this set greater than or equal to
the given element, or |
public void | clear()
Overrides java. Implements java. Removes all of the elements from this set. |
public ConcurrentSkipListSet | Returns: a shallow copy of this setOverrides java. Returns a shallow copy of this |
public Comparator | comparator()
Implements java. Returns the comparator used to order the elements in this set,
or |
public boolean | Returns: true if this set contains the specified elementobject to be checked for containment in this set o)Overrides java. Implements java. Returns |
public Iterator | Returns: an iterator over the elements in this set in descending orderImplements java. Returns an iterator over the elements in this set in descending order. |
public NavigableSet | Returns: a reverse order view of this setImplements java. Returns a reverse order view of the elements contained in this set. |
public boolean | Returns: true if the specified object is equal to this setthe object to be compared for equality with this set o)Overrides java. Implements java. Compares the specified object with this set for equality. |
public E | first()
Implements java. Returns the first (lowest) element currently in this set. |
public E | floor(E
the value to match e)Implements java. Returns the greatest element in this set less than or equal to
the given element, or |
public NavigableSet | headSet(E
high endpoint of the returned set toElement, boolean true if the high endpoint
is to be included in the returned viewImplements java. Returns a view of the portion of this set whose elements are less than
(or equal to, if |
public NavigableSet | headSet(E
high endpoint (exclusive) of the returned set toElement)Implements java. Returns a view of the portion of this set whose elements are
strictly less than |
public E | higher(E
the value to match e)Implements java. Returns the least element in this set strictly greater than the
given element, or |
public boolean | Returns: true if this set contains no elementsOverrides java. Implements java. Returns |
public Iterator | Returns: an iterator over the elements in this set in ascending orderImplements abstract java. Implements java. Returns an iterator over the elements in this set in ascending order. |
public E | last()
Implements java. Returns the last (highest) element currently in this set. |
public E | lower(E
the value to match e)Implements java. Returns the greatest element in this set strictly less than the
given element, or |
public E | pollFirst()
Implements java. Retrieves and removes the first (lowest) element,
or returns |
public E | pollLast()
Implements java. Retrieves and removes the last (highest) element,
or returns |
public boolean | Returns: true if this set contained the specified elementobject to be removed from this set, if present o)Overrides java. Implements java. Removes the specified element from this set if it is present. |
public boolean | Returns: true if this set changed as a result of the callcollection containing elements to be removed from this set c)Overrides java. Implements java. Removes from this set all of its elements that are contained in the specified collection. |
private void | |
public int | Returns: the number of elements in this setImplements abstract java. Implements java. Returns the number of elements in this set. |
public Spliterator | Returns: aSpliterator over the elements in this setOverrides default java. Returns a |
public NavigableSet | subSet(E
low endpoint of the returned set fromElement, boolean true if the low endpoint
is to be included in the returned viewhigh endpoint of the returned set toElement, boolean true if the high endpoint
is to be included in the returned viewImplements java. Returns a view of the portion of this set whose elements range from
|
public NavigableSet | subSet(E
low endpoint (inclusive) of the returned set fromElement, E high endpoint (exclusive) of the returned set toElement)Implements java. Returns a view of the portion of this set whose elements range
from |
public NavigableSet | tailSet(E
low endpoint of the returned set fromElement, boolean true if the low endpoint
is to be included in the returned viewImplements java. Returns a view of the portion of this set whose elements are greater
than (or equal to, if |
public NavigableSet | tailSet(E
low endpoint (inclusive) of the returned set fromElement)Implements java. Returns a view of the portion of this set whose elements are
greater than or equal to |
m | back to summary |
---|---|
private final ConcurrentNavigableMap<E, Object> m The underlying map. Uses Boolean.TRUE as value for each element. This field is declared final for the sake of thread safety, which entails some ugliness in clone().
|
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID |
ConcurrentSkipListSet | back to summary |
---|---|
public ConcurrentSkipListSet() Constructs a new, empty set that orders its elements according to their natural ordering. |
ConcurrentSkipListSet | back to summary |
---|---|
public ConcurrentSkipListSet(Comparator<? super E> comparator) Constructs a new, empty set that orders its elements according to the specified comparator.
|
ConcurrentSkipListSet | back to summary |
---|---|
public ConcurrentSkipListSet(Collection<? extends E> c) Constructs a new set containing the elements in the specified collection, that orders its elements according to their natural ordering.
|
ConcurrentSkipListSet | back to summary |
---|---|
public ConcurrentSkipListSet(SortedSet<E> s) Constructs a new set containing the same elements and using the same ordering as the specified sorted set.
|
ConcurrentSkipListSet | back to summary |
---|---|
pack-priv ConcurrentSkipListSet(ConcurrentNavigableMap<E, Object> m) For use by submaps |
add | back to summary |
---|---|
public boolean add(E e) Overrides java. Implements java. Adds the specified element to this set if it is not already present.
More formally, adds the specified element
|
addFirst | back to summary |
---|---|
public void addFirst(E e) Overrides default java. Throws
|
addLast | back to summary |
---|---|
public void addLast(E e) Overrides default java. Throws
|
ceiling | back to summary |
---|---|
public E ceiling(E e) Implements java. Doc from java. Returns the least element in this set greater than or equal to
the given element, or
|
clear | back to summary |
---|---|
public void clear() Overrides java. Implements java. Removes all of the elements from this set. |
clone | back to summary |
---|---|
public ConcurrentSkipListSet Overrides java. Returns a shallow copy of this
|
comparator | back to summary |
---|---|
public Comparator Implements java. Doc from java. Returns the comparator used to order the elements in this set,
or
|
contains | back to summary |
---|---|
public boolean contains(Object o) Overrides java. Implements java. Returns
|
descendingIterator | back to summary |
---|---|
public Iterator Implements java. Returns an iterator over the elements in this set in descending order.
|
descendingSet | back to summary |
---|---|
public NavigableSet Implements java. Returns a reverse order view of the elements contained in this set. The descending set is backed by this set, so changes to the set are reflected in the descending set, and vice-versa. The returned set has an ordering equivalent to
|
equals | back to summary |
---|---|
public boolean equals(Object o) Overrides java. Implements java. Compares the specified object with this set for equality. Returns
|
first | back to summary |
---|---|
public E first() Implements java. Doc from java. Returns the first (lowest) element currently in this set.
|
floor | back to summary |
---|---|
public E floor(E e) Implements java. Doc from java. Returns the greatest element in this set less than or equal to
the given element, or
|
headSet | back to summary |
---|---|
public NavigableSet Implements java. Doc from java. Returns a view of the portion of this set whose elements are less than
(or equal to, if The returned set will throw an
|
headSet | back to summary |
---|---|
public NavigableSet Implements java. Doc from java. Returns a view of the portion of this set whose elements are
strictly less than The returned set will throw an Equivalent to
|
higher | back to summary |
---|---|
public E higher(E e) Implements java. Doc from java. Returns the least element in this set strictly greater than the
given element, or
|
isEmpty | back to summary |
---|---|
public boolean isEmpty() Overrides java. Implements java. Returns
|
iterator | back to summary |
---|---|
public Iterator Implements abstract java. Implements java. Returns an iterator over the elements in this set in ascending order.
|
last | back to summary |
---|---|
public E last() Implements java. Doc from java. Returns the last (highest) element currently in this set.
|
lower | back to summary |
---|---|
public E lower(E e) Implements java. Doc from java. Returns the greatest element in this set strictly less than the
given element, or
|
pollFirst | back to summary |
---|---|
public E pollFirst() Implements java. Doc from java. Retrieves and removes the first (lowest) element,
or returns
|
pollLast | back to summary |
---|---|
public E pollLast() Implements java. Doc from java. Retrieves and removes the last (highest) element,
or returns
|
remove | back to summary |
---|---|
public boolean remove(Object o) Overrides java. Implements java. Removes the specified element from this set if it is present.
More formally, removes an element
|
removeAll | back to summary |
---|---|
public boolean removeAll(Collection<?> c) Overrides java. Implements java. Removes from this set all of its elements that are contained in the specified collection. If the specified collection is also a set, this operation effectively modifies this set so that its value is the asymmetric set difference of the two sets.
|
setMap | back to summary |
---|---|
private void setMap(ConcurrentNavigableMap<E, Object> map) Initializes map field; for use in clone. |
size | back to summary |
---|---|
public int size() Implements abstract java. Implements java. Returns the number of elements in this set. If this set
contains more than Beware that, unlike in most collections, this method is NOT a constant-time operation. Because of the asynchronous nature of these sets, determining the current number of elements requires traversing them all to count them. Additionally, it is possible for the size to change during execution of this method, in which case the returned result will be inaccurate. Thus, this method is typically not very useful in concurrent applications.
|
spliterator | back to summary |
---|---|
public Spliterator Overrides default java. Returns a The The spliterator's comparator
is
|
subSet | back to summary |
---|---|
public NavigableSet Implements java. Doc from java. Returns a view of the portion of this set whose elements range from
The returned set will throw an
|
subSet | back to summary |
---|---|
public NavigableSet Implements java. Doc from java. Returns a view of the portion of this set whose elements range
from The returned set will throw an Equivalent to
|
tailSet | back to summary |
---|---|
public NavigableSet Implements java. Doc from java. Returns a view of the portion of this set whose elements are greater
than (or equal to, if The returned set will throw an
|
tailSet | back to summary |
---|---|
public NavigableSet Implements java. Doc from java. Returns a view of the portion of this set whose elements are
greater than or equal to The returned set will throw an Equivalent to
|