| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
Based on 47 examples
public class ConcurrentSkipListSet extends AbstractSet implements NavigableSet, Cloneable, Serializable
A scalable concurrent {@link NavigableSet} implementation based on a {@link ConcurrentSkipListMap}. The elements of the set are kept sorted according to their {@linkplain Comparable natural ordering}, or by a {@link 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 are weakly consistent, returning elements reflecting the state of the set at some point at or since the creation of the iterator. They do not throw {@link ConcurrentModificationException}, and may proceed concurrently with other operations. 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. Additionally, the bulk operations addAll, removeAll, retainAll, and containsAll are not guaranteed to be performed atomically. For example, an iterator operating concurrently with an addAll operation might view only some of the added elements.
This class and its iterators implement all of the optional methods of the {@link Set} and {@link 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.
Constructor Summary | |
---|---|
Constructs a new, empty set that orders its elements according to their java.lang.Comparable. |
|
Constructs a new set containing the elements in the specified collection, that orders its elements according to their java.lang.Comparable. |
|
ConcurrentSkipListSet(Comparator comparator) Constructs a new, empty set that orders its elements according to the specified comparator. |
|
Constructs a new set containing the same elements and using the same ordering as the specified sorted set. |
Method Summary | |
---|---|
boolean |
Adds the specified element to this set if it is not already present. |
Object |
|
void |
clear() Removes all of the elements from this set. |
ConcurrentSkipListSet |
clone() Returns a shallow copy of this ConcurrentSkipListSet instance. |
Comparator |
|
boolean |
Returns true if this set contains the specified element. |
Iterator |
Returns an iterator over the elements in this set in descending order. |
NavigableSet |
Returns a reverse order view of the elements contained in this set. |
boolean |
Compares the specified object with this set for equality. |
Object |
first() |
Object |
|
NavigableSet |
|
NavigableSet |
|
Object |
|
boolean |
isEmpty() Returns true if this set contains no elements. |
Iterator |
iterator() Returns an iterator over the elements in this set in ascending order. |
Object |
last() |
Object |
|
Object |
|
Object |
pollLast() |
boolean |
Removes the specified element from this set if it is present. |
boolean |
Removes from this set all of its elements that are contained in the specified collection. |
int |
size() Returns the number of elements in this set. |
NavigableSet |
|
NavigableSet |
|
NavigableSet |
|
NavigableSet |
|
Methods inherited from class java.util.AbstractSet |
---|
equals, hashCode, removeAll |
Methods inherited from class java.util.AbstractCollection |
---|
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ConcurrentSkipListSet()
public ConcurrentSkipListSet(Collection c)
c
- The elements that will comprise the new setpublic ConcurrentSkipListSet(Comparator comparator)
comparator
- the comparator that will be used to order this set.
If null, the {@linkplain Comparable natural
ordering} of the elements will be used.public ConcurrentSkipListSet(SortedSet s)
s
- sorted set whose elements will comprise the new setMethod Detail |
---|
public boolean add(Object e)
add
in class AbstractCollection
e
- element to be added to this setpublic Object ceiling(Object e)
e
public void clear()
clear
in class AbstractCollection
public ConcurrentSkipListSet clone()
clone
in class Object
public Comparator comparator()
public boolean contains(Object o)
contains
in class AbstractCollection
o
- object to be checked for containment in this setpublic Iterator descendingIterator()
public NavigableSet descendingSet()
The returned set has an ordering equivalent to {@link Collections#reverseOrder(Comparator) Collections.reverseOrder}(comparator()). The expression {@code s.descendingSet().descendingSet()} returns a view of {@code s} essentially equivalent to {@code s}.
public boolean equals(Object o)
equals
in class AbstractSet
o
- the object to be compared for equality with this setpublic Object first()
public Object floor(Object e)
e
public NavigableSet headSet(Object toElement)
toElement
public NavigableSet headSet(Object toElement, boolean inclusive)
toElement
inclusive
public Object higher(Object e)
e
public boolean isEmpty()
isEmpty
in class AbstractCollection
public Iterator iterator()
iterator
in class AbstractCollection
public Object last()
public Object lower(Object e)
e
public Object pollFirst()
public Object pollLast()
public boolean remove(Object o)
remove
in class AbstractCollection
o
- object to be removed from this set, if presentpublic boolean removeAll(Collection c)
removeAll
in class AbstractSet
c
- collection containing elements to be removed from this setpublic int size()
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.
size
in class AbstractCollection
public NavigableSet subSet(Object fromElement, boolean fromInclusive, Object toElement, boolean toInclusive)
fromElement
fromInclusive
toElement
toInclusive
public NavigableSet subSet(Object fromElement, Object toElement)
fromElement
toElement
public NavigableSet tailSet(Object fromElement)
fromElement
public NavigableSet tailSet(Object fromElement, boolean inclusive)
fromElement
inclusive
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |