edu.emory.mathcs.backport.java.util.concurrent
public class ConcurrentSkipListMap extends AbstractMap implements ConcurrentNavigableMap, Cloneable, Serializable
This class implements a concurrent variant of SkipLists providing expected average log(n) time cost for the containsKey, get, put and remove operations and their variants. Insertion, removal, update, and access operations safely execute concurrently by multiple threads. Iterators are weakly consistent, returning elements reflecting the state of the map at some point at or since the creation of the iterator. They do not throw java.util.ConcurrentModificationException, and may proceed concurrently with other operations. Ascending key ordered views and their iterators are faster than descending ones.
All Map.Entry pairs returned by methods in this class and its views represent snapshots of mappings at the time they were produced. They do not support the Entry.setValue method. (Note however that it is possible to change mappings in the associated map using put, putIfAbsent, or replace, depending on exactly which effect you need.)
Beware that, unlike in most collections, the size method is not a constant-time operation. Because of the asynchronous nature of these maps, determining the current number of elements requires a traversal of the elements. Additionally, the bulk operations putAll, equals, and clear are not guaranteed to be performed atomically. For example, an iterator operating concurrently with a putAll operation might view only some of the added elements.
This class and its views and iterators implement all of the optional methods of the Map and Iterator interfaces. Like most other concurrent collections, this class does not permit the use of null keys or values because some null return values cannot be reliably distinguished from the absence of elements.
This class is a member of the Java Collections Framework.
Since: 1.6
Constructor Summary | |
---|---|
ConcurrentSkipListMap()
Constructs a new, empty map, sorted according to the
Comparable natural ordering of the keys. | |
ConcurrentSkipListMap(Comparator comparator)
Constructs a new, empty map, sorted according to the specified
comparator.
| |
ConcurrentSkipListMap(Map m)
Constructs a new map containing the same mappings as the given map,
sorted according to the Comparable natural ordering of
the keys.
| |
ConcurrentSkipListMap(SortedMap m)
Constructs a new map containing the same mappings and using the
same ordering as the specified sorted map.
|
Method Summary | |
---|---|
Entry | ceilingEntry(Object key)
Returns a key-value mapping associated with the least key
greater than or equal to the given key, or null if
there is no such entry. |
Object | ceilingKey(Object key) |
void | clear()
Removes all of the mappings from this map. |
Object | clone()
Returns a shallow copy of this ConcurrentSkipListMap
instance. |
Comparator | comparator() |
boolean | containsKey(Object key)
Returns true if this map contains a mapping for the specified
key.
|
boolean | containsValue(Object value)
Returns true if this map maps one or more keys to the
specified value. |
NavigableSet | descendingKeySet() |
NavigableMap | descendingMap() |
Set | entrySet()
Returns a Set view of the mappings contained in this map.
|
boolean | equals(Object o)
Compares the specified object with this map for equality.
|
Entry | firstEntry()
Returns a key-value mapping associated with the least
key in this map, or null if the map is empty.
|
Object | firstKey() |
Entry | floorEntry(Object key)
Returns a key-value mapping associated with the greatest key
less than or equal to the given key, or null if there
is no such key. |
Object | floorKey(Object key) |
Object | get(Object key)
Returns the value to which the specified key is mapped,
or {@code null} if this map contains no mapping for the key.
|
NavigableMap | headMap(Object toKey, boolean inclusive) |
SortedMap | headMap(Object toKey) |
Entry | higherEntry(Object key)
Returns a key-value mapping associated with the least key
strictly greater than the given key, or null if there
is no such key. |
Object | higherKey(Object key) |
boolean | isEmpty()
Returns true if this map contains no key-value mappings. |
Set | keySet()
Returns a NavigableSet view of the keys contained in this map.
|
Entry | lastEntry()
Returns a key-value mapping associated with the greatest
key in this map, or null if the map is empty.
|
Object | lastKey() |
Entry | lowerEntry(Object key)
Returns a key-value mapping associated with the greatest key
strictly less than the given key, or null if there is
no such key. |
Object | lowerKey(Object key) |
NavigableSet | navigableKeySet() |
Entry | pollFirstEntry()
Removes and returns a key-value mapping associated with
the least key in this map, or null if the map is empty.
|
Entry | pollLastEntry()
Removes and returns a key-value mapping associated with
the greatest key in this map, or null if the map is empty.
|
Object | put(Object key, Object value)
Associates the specified value with the specified key in this map.
|
Object | putIfAbsent(Object key, Object value)
{@inheritDoc }
|
Object | remove(Object key)
Removes the mapping for the specified key from this map if present.
|
boolean | remove(Object key, Object value)
{@inheritDoc }
|
boolean | replace(Object key, Object oldValue, Object newValue)
{@inheritDoc }
|
Object | replace(Object key, Object value)
{@inheritDoc }
|
int | size()
Returns the number of key-value mappings in this map. |
NavigableMap | subMap(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive) |
SortedMap | subMap(Object fromKey, Object toKey) |
NavigableMap | tailMap(Object fromKey, boolean inclusive) |
SortedMap | tailMap(Object fromKey) |
Collection | values()
Returns a Collection view of the values contained in this map.
|
Parameters: comparator the comparator that will be used to order this map. If null, the Comparable natural ordering of the keys will be used.
Parameters: m the map whose mappings are to be placed in this map
Throws: ClassCastException if the keys in m are not Comparable, or are not mutually comparable NullPointerException if the specified map or any of its keys or values are null
Parameters: m the sorted map whose mappings are to be placed in this map, and whose comparator is to be used to sort this map
Throws: NullPointerException if the specified sorted map or any of its keys or values are null
Throws: ClassCastException {@inheritDoc } NullPointerException if the specified key is null
Throws: ClassCastException {@inheritDoc } NullPointerException if the specified key is null
Returns: a shallow copy of this map
Parameters: key key whose presence in this map is to be tested
Returns: true if this map contains a mapping for the specified key
Throws: ClassCastException if the specified key cannot be compared with the keys currently in the map NullPointerException if the specified key is null
Parameters: value value whose presence in this map is to be tested
Returns: true if a mapping to value exists; false otherwise
Throws: NullPointerException if the specified value is null
The view's iterator is a "weakly consistent" iterator that will never throw java.util.ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.
The Map.Entry elements returned by iterator.next() do not support the setValue operation.
Returns: a set view of the mappings contained in this map, sorted in ascending key order
Parameters: o object to be compared for equality with this map
Returns: true if the specified object is equal to this map
Throws: NoSuchElementException {@inheritDoc }
Parameters: key the key
Throws: ClassCastException {@inheritDoc } NullPointerException if the specified key is null
Parameters: key the key
Throws: ClassCastException {@inheritDoc } NullPointerException if the specified key is null
More formally, if this map contains a mapping from a key {@code k} to a value {@code v} such that {@code key} compares equal to {@code k} according to the map's ordering, then this method returns {@code v}; otherwise it returns {@code null}. (There can be at most one such mapping.)
Throws: ClassCastException if the specified key cannot be compared with the keys currently in the map NullPointerException if the specified key is null
Throws: ClassCastException {@inheritDoc } NullPointerException if {@code toKey} is null IllegalArgumentException {@inheritDoc }
Throws: ClassCastException {@inheritDoc } NullPointerException if {@code toKey} is null IllegalArgumentException {@inheritDoc }
Parameters: key the key
Throws: ClassCastException {@inheritDoc } NullPointerException if the specified key is null
Parameters: key the key
Throws: ClassCastException {@inheritDoc } NullPointerException if the specified key is null
Returns: true if this map contains no key-value mappings
The view's {@code iterator} is a "weakly consistent" iterator that will never throw java.util.ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.
This method is equivalent to method {@code navigableKeySet}.
Returns: a navigable set view of the keys in this map
Throws: NoSuchElementException {@inheritDoc }
Throws: ClassCastException {@inheritDoc } NullPointerException if the specified key is null
Throws: ClassCastException {@inheritDoc } NullPointerException if the specified key is null
Parameters: key key with which the specified value is to be associated value value to be associated with the specified key
Returns: the previous value associated with the specified key, or null if there was no mapping for the key
Throws: ClassCastException if the specified key cannot be compared with the keys currently in the map NullPointerException if the specified key or value is null
Returns: the previous value associated with the specified key, or null if there was no mapping for the key
Throws: ClassCastException if the specified key cannot be compared with the keys currently in the map NullPointerException if the specified key or value is null
Parameters: key key for which mapping should be removed
Returns: the previous value associated with the specified key, or null if there was no mapping for the key
Throws: ClassCastException if the specified key cannot be compared with the keys currently in the map NullPointerException if the specified key is null
Throws: ClassCastException if the specified key cannot be compared with the keys currently in the map NullPointerException if the specified key is null
Throws: ClassCastException if the specified key cannot be compared with the keys currently in the map NullPointerException if any of the arguments are null
Returns: the previous value associated with the specified key, or null if there was no mapping for the key
Throws: ClassCastException if the specified key cannot be compared with the keys currently in the map NullPointerException if the specified key or value is null
Beware that, unlike in most collections, this method is NOT a constant-time operation. Because of the asynchronous nature of these maps, 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.
Returns: the number of elements in this map
Throws: ClassCastException {@inheritDoc } NullPointerException if {@code fromKey} or {@code toKey} is null IllegalArgumentException {@inheritDoc }
Throws: ClassCastException {@inheritDoc } NullPointerException if {@code fromKey} or {@code toKey} is null IllegalArgumentException {@inheritDoc }
Throws: ClassCastException {@inheritDoc } NullPointerException if {@code fromKey} is null IllegalArgumentException {@inheritDoc }
Throws: ClassCastException {@inheritDoc } NullPointerException if {@code fromKey} is null IllegalArgumentException {@inheritDoc }
The view's iterator is a "weakly consistent" iterator that will never throw java.util.ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.