K - the type of keys maintained by this mapV - the type of mapped valuespublic class ConcurrentSkipListMap<K,V> extends java.util.AbstractMap<K,V> implements ConcurrentNavigableMap<K,V>, java.lang.Cloneable, java.io.Serializable
ConcurrentNavigableMap implementation. This
class maintains a map in ascending key order, sorted according to
the natural order for the key's class (see Comparable), or by the Comparator provided at creation
time, depending on which constructor is used.
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 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.
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
ConcurrentSkipListMap.ComparableUsingComparator<K>
Represents a key with a comparator as a Comparable.
|
(package private) static class |
ConcurrentSkipListMap.ConcurrentSkipListSubMap<K,V>
Submaps returned by
ConcurrentSkipListMap submap operations
represent a subrange of mappings of their underlying
maps. |
(package private) class |
ConcurrentSkipListMap.DescendingEntryIterator |
(package private) class |
ConcurrentSkipListMap.DescendingEntrySet |
(package private) class |
ConcurrentSkipListMap.DescendingKeyIterator |
(package private) class |
ConcurrentSkipListMap.DescendingKeySet |
(package private) class |
ConcurrentSkipListMap.DescendingSubMapEntryIterator |
(package private) class |
ConcurrentSkipListMap.DescendingSubMapKeyIterator |
(package private) class |
ConcurrentSkipListMap.EntryIter
Entry iterators use the same trick as in ConcurrentHashMap and
elsewhere of using the iterator itself to represent entries,
thus avoiding having to create entry objects in next().
|
(package private) class |
ConcurrentSkipListMap.EntryIterator |
(package private) class |
ConcurrentSkipListMap.EntrySet |
(package private) static class |
ConcurrentSkipListMap.HeadIndex<K,V>
Nodes heading each level keep track of their level.
|
(package private) static class |
ConcurrentSkipListMap.Index<K,V>
Index nodes represent the levels of the skip list.
|
(package private) class |
ConcurrentSkipListMap.Iter
Base of ten kinds of iterator classes:
ascending: {map, submap} X {key, value, entry}
descending: {map, submap} X {key, entry}
|
(package private) class |
ConcurrentSkipListMap.KeyIterator |
(package private) class |
ConcurrentSkipListMap.KeySet |
(package private) static class |
ConcurrentSkipListMap.Node<K,V>
Nodes hold keys and values, and are singly linked in sorted
order, possibly with some intervening marker nodes.
|
(package private) static class |
ConcurrentSkipListMap.SnapshotEntry<K,V>
An immutable representation of a key-value mapping as it
existed at some point in time.
|
(package private) class |
ConcurrentSkipListMap.SubMapEntryIterator |
(package private) class |
ConcurrentSkipListMap.SubMapKeyIterator |
(package private) class |
ConcurrentSkipListMap.SubMapValueIterator |
(package private) class |
ConcurrentSkipListMap.ValueIterator |
(package private) class |
ConcurrentSkipListMap.Values |
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.Object |
BASE_HEADER
Special value used to identify base-level header
|
private java.util.Comparator<? super K> |
comparator
The Comparator used to maintain order in this Map, or null
if using natural order.
|
private ConcurrentSkipListMap.DescendingEntrySet |
descendingEntrySet
Lazily initialized descending entry set
|
private ConcurrentSkipListMap.DescendingKeySet |
descendingKeySet
Lazily initialized descending key set
|
private ConcurrentSkipListMap.EntrySet |
entrySet
Lazily initialized entry set
|
private static int |
EQ |
private static int |
GT |
(package private) ConcurrentSkipListMap.HeadIndex<K,V> |
head
The topmost head index of the skiplist.
|
private static java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ConcurrentSkipListMap,ConcurrentSkipListMap.HeadIndex> |
headUpdater
Updater for casHead
|
private ConcurrentSkipListMap.KeySet |
keySet
Lazily initialized key set
|
private static int |
LT |
private int |
randomSeed
Seed for simple random number generator.
|
private static long |
serialVersionUID |
private ConcurrentSkipListMap.Values |
values
Lazily initialized values collection
|
| Constructor and Description |
|---|
ConcurrentSkipListMap()
Constructs a new empty map, sorted according to the keys' natural
order.
|
ConcurrentSkipListMap(java.util.Comparator<? super K> c)
Constructs a new empty map, sorted according to the given comparator.
|
ConcurrentSkipListMap(java.util.Map<? extends K,? extends V> m)
Constructs a new map containing the same mappings as the given map,
sorted according to the keys' natural order.
|
ConcurrentSkipListMap(java.util.SortedMap<K,? extends V> m)
Constructs a new map containing the same mappings as the given
SortedMap, sorted according to the same ordering.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
addIndex(ConcurrentSkipListMap.Index<K,V> idx,
ConcurrentSkipListMap.HeadIndex<K,V> h,
int indexLevel)
Add given index nodes from given level down to 1.
|
private void |
buildFromSorted(java.util.SortedMap<K,? extends V> map)
Streamlined bulk insertion to initialize from elements of
given sorted map.
|
private boolean |
casHead(ConcurrentSkipListMap.HeadIndex<K,V> cmp,
ConcurrentSkipListMap.HeadIndex<K,V> val)
compareAndSet head node
|
java.util.Map.Entry<K,V> |
ceilingEntry(K 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.
|
K |
ceilingKey(K key)
Returns least key greater than or equal to the given key, or
null if there is no such key.
|
void |
clear()
Removes all mappings from this map.
|
private void |
clearIndexToFirst()
Clear out index nodes associated with deleted first entry.
|
java.lang.Object |
clone()
Returns a shallow copy of this Map instance.
|
private java.lang.Comparable<K> |
comparable(java.lang.Object key)
If using comparator, return a ComparableUsingComparator, else
cast key as Comparator, which may cause ClassCastException,
which is propagated back to caller.
|
java.util.Comparator<? super K> |
comparator()
Returns the comparator used to order this map, or null
if this map uses its keys' natural order.
|
(package private) int |
compare(K k1,
K k2)
Compare using comparator or natural ordering.
|
(package private) static <K,V> boolean |
containsAllMappings(java.util.Map<K,V> a,
java.util.Map<K,V> b)
Helper for equals -- check for containment, avoiding nulls.
|
boolean |
containsKey(java.lang.Object key)
Returns true if this map contains a mapping for the specified
key.
|
boolean |
containsValue(java.lang.Object value)
Returns true if this map maps one or more keys to the
specified value.
|
java.util.Set<java.util.Map.Entry<K,V>> |
descendingEntrySet()
Returns a collection view of the mappings contained in this
map, in descending order.
|
(package private) java.util.Iterator<K> |
descendingKeyIterator() |
java.util.Set<K> |
descendingKeySet()
Returns a set view of the keys contained in this map in
descending order.
|
(package private) ConcurrentSkipListMap.DescendingSubMapEntryIterator |
descendingSubMapEntryIterator(K least,
K fence) |
(package private) ConcurrentSkipListMap.DescendingSubMapKeyIterator |
descendingSubMapKeyIterator(K least,
K fence) |
private V |
doGet(java.lang.Object okey)
Specialized variant of findNode to perform Map.get.
|
private V |
doPut(K kkey,
V value,
boolean onlyIfAbsent)
Main insertion method.
|
private V |
doRemove(java.lang.Object okey,
java.lang.Object value)
Main deletion method.
|
(package private) java.lang.Object |
doRemoveFirst(boolean keyOnly)
Remove first entry; return either its key or a snapshot.
|
(package private) java.lang.Object |
doRemoveLast(boolean keyOnly)
Specialized version of doRemove for last entry.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
Returns a collection view of the mappings contained in this
map.
|
boolean |
equals(java.lang.Object o)
Compares the specified object with this map for equality.
|
(package private) ConcurrentSkipListMap.Node<K,V> |
findCeiling(K key)
Return ceiling, or first node if key is null
|
(package private) ConcurrentSkipListMap.Node<K,V> |
findFirst()
Specialized variant of findNode to get first valid node
|
(package private) ConcurrentSkipListMap.Node<K,V> |
findLast()
Specialized version of find to get last valid node
|
(package private) ConcurrentSkipListMap.Node<K,V> |
findLower(K key)
Return lower node, or last node if key is null
|
(package private) ConcurrentSkipListMap.Node<K,V> |
findNear(K kkey,
int rel)
Utility for ceiling, floor, lower, higher methods.
|
private ConcurrentSkipListMap.Node<K,V> |
findNode(java.lang.Comparable<K> key)
Return node holding key or null if no such, clearing out any
deleted nodes seen along the way.
|
private ConcurrentSkipListMap.Node<K,V> |
findPredecessor(java.lang.Comparable<K> key)
Return a base-level node with key strictly less than given key,
or the base-level header if there is no such node.
|
private ConcurrentSkipListMap.Node<K,V> |
findPredecessorOfLast()
Specialized variant of findPredecessor to get predecessor of
last valid node.
|
java.util.Map.Entry<K,V> |
firstEntry()
Returns a key-value mapping associated with the least
key in this map, or null if the map is empty.
|
K |
firstKey()
Returns the first (lowest) key currently in this map.
|
java.util.Map.Entry<K,V> |
floorEntry(K 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 entry.
|
K |
floorKey(K key)
Returns the greatest key
less than or equal to the given key, or null if there
is no such key.
|
V |
get(java.lang.Object key)
Returns the value to which this map maps the specified key.
|
(package private) ConcurrentSkipListMap.SnapshotEntry<K,V> |
getNear(K kkey,
int rel)
Return SnapshotEntry for results of findNear.
|
(package private) java.lang.Object |
getNear(K kkey,
int rel,
K least,
K fence,
boolean keyOnly)
Return SnapshotEntry or key for results of findNear ofter screening
to ensure result is in given range.
|
private V |
getUsingFindNode(java.lang.Comparable<K> key)
Perform map.get via findNode.
|
ConcurrentNavigableMap<K,V> |
headMap(K toKey)
Returns a view of the portion of this map whose keys are
strictly less than toKey.
|
java.util.Map.Entry<K,V> |
higherEntry(K key)
Returns a key-value mapping associated with the least key
strictly greater than the given key, or null if there
is no such entry.
|
K |
higherKey(K key)
Returns the least key strictly greater than the given key, or
null if there is no such key.
|
(package private) boolean |
inHalfOpenRange(K key,
K least,
K fence)
Return true if given key greater than or equal to least and
strictly less than fence, bypassing either test if least or
fence oare null.
|
(package private) void |
initialize()
Initialize or reset state.
|
(package private) boolean |
inOpenRange(K key,
K least,
K fence)
Return true if given key greater than or equal to least and less
or equal to fence.
|
private void |
insertIndex(ConcurrentSkipListMap.Node<K,V> z,
int level)
Create and add index nodes for given node.
|
boolean |
isEmpty()
Returns true if this map contains no key-value mappings.
|
(package private) java.util.Iterator<K> |
keyIterator() |
java.util.Set<K> |
keySet()
Returns a set view of the keys contained in this map.
|
java.util.Map.Entry<K,V> |
lastEntry()
Returns a key-value mapping associated with the greatest
key in this map, or null if the map is empty.
|
K |
lastKey()
Returns the last (highest) key currently in this map.
|
java.util.Map.Entry<K,V> |
lowerEntry(K key)
Returns a key-value mapping associated with the greatest
key strictly less than the given key, or null if there is no
such entry.
|
K |
lowerKey(K key)
Returns the greatest key strictly less than the given key, or
null if there is no such key.
|
java.util.Map.Entry<K,V> |
pollFirstEntry()
Removes and returns a key-value mapping associated with
the least key in this map, or null if the map is empty.
|
(package private) K |
pollFirstKey()
Remove first entry; return key or null if empty.
|
java.util.Map.Entry<K,V> |
pollLastEntry()
Removes and returns a key-value mapping associated with
the greatest key in this map, or null if the map is empty.
|
(package private) K |
pollLastKey()
Remove last entry; return key or null if empty.
|
V |
put(K key,
V value)
Associates the specified value with the specified key in this map.
|
V |
putIfAbsent(K key,
V value)
If the specified key is not already associated
with a value, associate it with the given value.
|
private int |
randomLevel()
Return a random level for inserting a new node.
|
private void |
readObject(java.io.ObjectInputStream s)
Reconstitute the Map instance from a stream.
|
V |
remove(java.lang.Object key)
Removes the mapping for this key from this Map if present.
|
boolean |
remove(java.lang.Object key,
java.lang.Object value)
Remove entry for key only if currently mapped to given value.
|
(package private) java.lang.Object |
removeFirstEntryOfSubrange(K least,
K fence,
boolean keyOnly)
Find and remove least element of subrange.
|
(package private) java.lang.Object |
removeLastEntryOfSubrange(K least,
K fence,
boolean keyOnly)
Find and remove greatest element of subrange.
|
(package private) boolean |
removep(java.lang.Object key)
Version of remove with boolean return.
|
V |
replace(K key,
V value)
Replace entry for key only if currently mapped to some value.
|
boolean |
replace(K key,
V oldValue,
V newValue)
Replace entry for key only if currently mapped to given value.
|
int |
size()
Returns the number of elements in this map.
|
ConcurrentNavigableMap<K,V> |
subMap(K fromKey,
K toKey)
Returns a view of the portion of this map whose keys range from
fromKey, inclusive, to toKey, exclusive.
|
(package private) ConcurrentSkipListMap.SubMapEntryIterator |
subMapEntryIterator(K least,
K fence) |
(package private) ConcurrentSkipListMap.SubMapKeyIterator |
subMapKeyIterator(K least,
K fence) |
(package private) ConcurrentSkipListMap.SubMapValueIterator |
subMapValueIterator(K least,
K fence) |
ConcurrentNavigableMap<K,V> |
tailMap(K fromKey)
Returns a view of the portion of this map whose keys are
greater than or equal to fromKey.
|
private void |
tryReduceLevel()
Possibly reduce head level if it has no nodes.
|
java.util.Collection<V> |
values()
Returns a collection view of the values contained in this map.
|
private void |
writeObject(java.io.ObjectOutputStream s)
Save the state of the Map instance to a stream.
|
finalize, getClass, notify, notifyAll, wait, wait, waitprivate static final long serialVersionUID
private static final java.lang.Object BASE_HEADER
transient volatile ConcurrentSkipListMap.HeadIndex<K,V> head
private final java.util.Comparator<? super K> comparator
private transient int randomSeed
private transient ConcurrentSkipListMap.KeySet keySet
private transient ConcurrentSkipListMap.EntrySet entrySet
private transient ConcurrentSkipListMap.Values values
private transient ConcurrentSkipListMap.DescendingKeySet descendingKeySet
private transient ConcurrentSkipListMap.DescendingEntrySet descendingEntrySet
private static final java.util.concurrent.atomic.AtomicReferenceFieldUpdater<ConcurrentSkipListMap,ConcurrentSkipListMap.HeadIndex> headUpdater
private static final int EQ
private static final int LT
private static final int GT
public ConcurrentSkipListMap()
public ConcurrentSkipListMap(java.util.Comparator<? super K> c)
c - the comparator that will be used to sort this map. A
null value indicates that the keys' natural
ordering should be used.public ConcurrentSkipListMap(java.util.Map<? extends K,? extends V> m)
m - the map whose mappings are to be placed in this map.java.lang.ClassCastException - if the keys in m are not Comparable, or
are not mutually comparable.java.lang.NullPointerException - if the specified map is null.public ConcurrentSkipListMap(java.util.SortedMap<K,? extends V> m)
m - the sorted map whose mappings are to be placed in this
map, and whose comparator is to be used to sort this map.java.lang.NullPointerException - if the specified sorted map is
null.final void initialize()
private boolean casHead(ConcurrentSkipListMap.HeadIndex<K,V> cmp, ConcurrentSkipListMap.HeadIndex<K,V> val)
private java.lang.Comparable<K> comparable(java.lang.Object key) throws java.lang.ClassCastException
java.lang.ClassCastExceptionint compare(K k1, K k2) throws java.lang.ClassCastException
java.lang.ClassCastExceptionboolean inHalfOpenRange(K key, K least, K fence)
boolean inOpenRange(K key, K least, K fence)
private ConcurrentSkipListMap.Node<K,V> findPredecessor(java.lang.Comparable<K> key)
key - the keyprivate ConcurrentSkipListMap.Node<K,V> findNode(java.lang.Comparable<K> key)
key - the keyprivate V doGet(java.lang.Object okey)
okey - the keyprivate V getUsingFindNode(java.lang.Comparable<K> key)
key - the keyprivate V doPut(K kkey, V value, boolean onlyIfAbsent)
kkey - the keyvalue - the value that must be associated with keyonlyIfAbsent - if should not insert if already presentprivate int randomLevel()
private void insertIndex(ConcurrentSkipListMap.Node<K,V> z, int level)
z - the nodelevel - the level of the indexprivate void addIndex(ConcurrentSkipListMap.Index<K,V> idx, ConcurrentSkipListMap.HeadIndex<K,V> h, int indexLevel)
idx - the topmost index node being insertedh - the value of head to use to insert. This must be
snapshotted by callers to provide correct insertion levelindexLevel - the level of the indexprivate V doRemove(java.lang.Object okey, java.lang.Object value)
okey - the keyvalue - if non-null, the value that must be
associated with keyprivate void tryReduceLevel()
boolean removep(java.lang.Object key)
ConcurrentSkipListMap.Node<K,V> findFirst()
java.lang.Object doRemoveFirst(boolean keyOnly)
keyOnly - if true return key, else return SnapshotEntry
(This is a little ugly, but avoids code duplication.)private void clearIndexToFirst()
K pollFirstKey()
ConcurrentSkipListMap.Node<K,V> findLast()
java.lang.Object doRemoveLast(boolean keyOnly)
keyOnly - if true return key, else return SnapshotEntryprivate ConcurrentSkipListMap.Node<K,V> findPredecessorOfLast()
K pollLastKey()
ConcurrentSkipListMap.Node<K,V> findNear(K kkey, int rel)
kkey - the keyrel - the relation -- OR'ed combination of EQ, LT, GTConcurrentSkipListMap.SnapshotEntry<K,V> getNear(K kkey, int rel)
kkey - the keyrel - the relation -- OR'ed combination of EQ, LT, GTConcurrentSkipListMap.Node<K,V> findCeiling(K key)
ConcurrentSkipListMap.Node<K,V> findLower(K key)
java.lang.Object getNear(K kkey, int rel, K least, K fence, boolean keyOnly)
kkey - the keyrel - the relation -- OR'ed combination of EQ, LT, GTleast - minimum allowed key valuefence - key greater than maximum allowed key valuekeyOnly - if true return key, else return SnapshotEntryjava.lang.Object removeFirstEntryOfSubrange(K least, K fence, boolean keyOnly)
least - minimum allowed key valuefence - key greater than maximum allowed key valuekeyOnly - if true return key, else return SnapshotEntryjava.lang.Object removeLastEntryOfSubrange(K least, K fence, boolean keyOnly)
least - minimum allowed key valuefence - key greater than maximum allowed key valuekeyOnly - if true return key, else return SnapshotEntrypublic java.lang.Object clone()
private void buildFromSorted(java.util.SortedMap<K,? extends V> map)
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException
java.io.IOExceptionprivate void readObject(java.io.ObjectInputStream s)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<K,V>containsKey in class java.util.AbstractMap<K,V>key - key whose presence in this map is to be tested.java.lang.ClassCastException - if the key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if the key is null.public V get(java.lang.Object key)
get in interface java.util.Map<K,V>get in class java.util.AbstractMap<K,V>key - key whose associated value is to be returned.java.lang.ClassCastException - if the key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if the key is null.public V put(K key, V value)
put in interface java.util.Map<K,V>put in class java.util.AbstractMap<K,V>key - key with which the specified value is to be associated.value - value to be associated with the specified key.java.lang.ClassCastException - if the key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if the key or value are null.public V remove(java.lang.Object key)
remove in interface java.util.Map<K,V>remove in class java.util.AbstractMap<K,V>key - key for which mapping should be removedjava.lang.ClassCastException - if the key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if the key is null.public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<K,V>containsValue in class java.util.AbstractMap<K,V>value - value whose presence in this Map is to be tested.java.lang.NullPointerException - if the value is null.public int size()
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.
public boolean isEmpty()
public void clear()
public java.util.Set<K> keySet()
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.public java.util.Set<K> descendingKeySet()
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.descendingKeySet in interface NavigableMap<K,V>public java.util.Collection<V> values()
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.public java.util.Set<java.util.Map.Entry<K,V>> entrySet()
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.public java.util.Set<java.util.Map.Entry<K,V>> descendingEntrySet()
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.descendingEntrySet in interface NavigableMap<K,V>public boolean equals(java.lang.Object o)
static <K,V> boolean containsAllMappings(java.util.Map<K,V> a,
java.util.Map<K,V> b)
public V putIfAbsent(K key, V value)
if (!map.containsKey(key))
return map.put(key, value);
else
return map.get(key);
except that the action is performed atomically.putIfAbsent in interface java.util.concurrent.ConcurrentMap<K,V>putIfAbsent in interface java.util.Map<K,V>key - key with which the specified value is to be associated.value - value to be associated with the specified key.java.lang.ClassCastException - if the key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if the key or value are null.public boolean remove(java.lang.Object key,
java.lang.Object value)
if ((map.containsKey(key) && map.get(key).equals(value)) {
map.remove(key);
return true;
} else return false;
except that the action is performed atomically.remove in interface java.util.concurrent.ConcurrentMap<K,V>remove in interface java.util.Map<K,V>key - key with which the specified value is associated.value - value associated with the specified key.java.lang.ClassCastException - if the key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if the key or value are null.public boolean replace(K key, V oldValue, V newValue)
if ((map.containsKey(key) && map.get(key).equals(oldValue)) {
map.put(key, newValue);
return true;
} else return false;
except that the action is performed atomically.replace in interface java.util.concurrent.ConcurrentMap<K,V>replace in interface java.util.Map<K,V>key - key with which the specified value is associated.oldValue - value expected to be associated with the specified key.newValue - value to be associated with the specified key.java.lang.ClassCastException - if the key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if key, oldValue or newValue are
null.public V replace(K key, V value)
if ((map.containsKey(key)) {
return map.put(key, value);
} else return null;
except that the action is performed atomically.replace in interface java.util.concurrent.ConcurrentMap<K,V>replace in interface java.util.Map<K,V>key - key with which the specified value is associated.value - value to be associated with the specified key.java.lang.ClassCastException - if the key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if the key or value are null.public java.util.Comparator<? super K> comparator()
public K firstKey()
public K lastKey()
public ConcurrentNavigableMap<K,V> subMap(K fromKey, K toKey)
subMap in interface java.util.SortedMap<K,V>subMap in interface ConcurrentNavigableMap<K,V>subMap in interface NavigableMap<K,V>fromKey - low endpoint (inclusive) of the subMap.toKey - high endpoint (exclusive) of the subMap.java.lang.ClassCastException - if fromKey and toKey
cannot be compared to one another using this map's comparator
(or, if the map has no comparator, using natural ordering).java.lang.IllegalArgumentException - if fromKey is greater than
toKey.java.lang.NullPointerException - if fromKey or toKey is
null.public ConcurrentNavigableMap<K,V> headMap(K toKey)
headMap in interface java.util.SortedMap<K,V>headMap in interface ConcurrentNavigableMap<K,V>headMap in interface NavigableMap<K,V>toKey - high endpoint (exclusive) of the headMap.java.lang.ClassCastException - if toKey is not compatible
with this map's comparator (or, if the map has no comparator,
if toKey does not implement Comparable).java.lang.NullPointerException - if toKey is null.public ConcurrentNavigableMap<K,V> tailMap(K fromKey)
tailMap in interface java.util.SortedMap<K,V>tailMap in interface ConcurrentNavigableMap<K,V>tailMap in interface NavigableMap<K,V>fromKey - low endpoint (inclusive) of the tailMap.java.lang.ClassCastException - if fromKey is not
compatible with this map's comparator (or, if the map has no
comparator, if fromKey does not implement
Comparable).java.lang.NullPointerException - if fromKey is null.public java.util.Map.Entry<K,V> ceilingEntry(K key)
ceilingEntry in interface NavigableMap<K,V>key - the key.java.lang.ClassCastException - if key cannot be compared with the
keys currently in the map.java.lang.NullPointerException - if key is null.public K ceilingKey(K key)
ceilingKey in interface NavigableMap<K,V>key - the key.java.lang.ClassCastException - if key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if key is null.public java.util.Map.Entry<K,V> lowerEntry(K key)
lowerEntry in interface NavigableMap<K,V>key - the key.java.lang.ClassCastException - if key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if key is null.public K lowerKey(K key)
lowerKey in interface NavigableMap<K,V>key - the key.java.lang.ClassCastException - if key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if key is null.public java.util.Map.Entry<K,V> floorEntry(K key)
floorEntry in interface NavigableMap<K,V>key - the key.java.lang.ClassCastException - if key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if key is null.public K floorKey(K key)
floorKey in interface NavigableMap<K,V>key - the key.java.lang.ClassCastException - if key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if key is null.public java.util.Map.Entry<K,V> higherEntry(K key)
higherEntry in interface NavigableMap<K,V>key - the key.java.lang.ClassCastException - if key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if key is null.public K higherKey(K key)
higherKey in interface NavigableMap<K,V>key - the key.java.lang.ClassCastException - if key cannot be compared with the keys
currently in the map.java.lang.NullPointerException - if key is null.public java.util.Map.Entry<K,V> firstEntry()
firstEntry in interface NavigableMap<K,V>public java.util.Map.Entry<K,V> lastEntry()
lastEntry in interface NavigableMap<K,V>public java.util.Map.Entry<K,V> pollFirstEntry()
pollFirstEntry in interface NavigableMap<K,V>public java.util.Map.Entry<K,V> pollLastEntry()
pollLastEntry in interface NavigableMap<K,V>java.util.Iterator<K> keyIterator()
java.util.Iterator<K> descendingKeyIterator()
ConcurrentSkipListMap.SubMapEntryIterator subMapEntryIterator(K least, K fence)
ConcurrentSkipListMap.DescendingSubMapEntryIterator descendingSubMapEntryIterator(K least, K fence)
ConcurrentSkipListMap.SubMapKeyIterator subMapKeyIterator(K least, K fence)
ConcurrentSkipListMap.DescendingSubMapKeyIterator descendingSubMapKeyIterator(K least, K fence)
ConcurrentSkipListMap.SubMapValueIterator subMapValueIterator(K least, K fence)