|
JBoss Common Classes 2.2.17.GA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
org.jboss.util.collection.ConcurrentSkipListMap<K,V>
K
- the type of keys maintained by this mapV
- the type of mapped valuespublic class ConcurrentSkipListMap<K,V>
A scalable 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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V> |
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Constructor Summary | |
---|---|
ConcurrentSkipListMap()
Constructs a new empty map, sorted according to the keys' natural order. |
|
ConcurrentSkipListMap(Comparator<? super K> c)
Constructs a new empty map, sorted according to the given comparator. |
|
ConcurrentSkipListMap(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(SortedMap<K,? extends V> m)
Constructs a new map containing the same mappings as the given SortedMap, sorted according to the same ordering. |
Method Summary | |
---|---|
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. |
Object |
clone()
Returns a shallow copy of this Map instance. |
Comparator<? super K> |
comparator()
Returns the comparator used to order this map, or null if this map uses its keys' natural order. |
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. |
Set<Map.Entry<K,V>> |
descendingEntrySet()
Returns a collection view of the mappings contained in this map, in descending order. |
Set<K> |
descendingKeySet()
Returns a set view of the keys contained in this map in descending order. |
Set<Map.Entry<K,V>> |
entrySet()
Returns a collection view of the mappings contained in this map. |
boolean |
equals(Object o)
Compares the specified object with this map for equality. |
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. |
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(Object key)
Returns the value to which this map maps the specified key. |
ConcurrentNavigableMap<K,V> |
headMap(K toKey)
Returns a view of the portion of this map whose keys are strictly less than toKey. |
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. |
boolean |
isEmpty()
Returns true if this map contains no key-value mappings. |
Set<K> |
keySet()
Returns a set view of the keys contained in this map. |
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. |
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. |
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. |
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. |
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. |
V |
remove(Object key)
Removes the mapping for this key from this Map if present. |
boolean |
remove(Object key,
Object value)
Remove entry for key only if currently mapped to given value. |
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. |
ConcurrentNavigableMap<K,V> |
tailMap(K fromKey)
Returns a view of the portion of this map whose keys are greater than or equal to fromKey. |
Collection<V> |
values()
Returns a collection view of the values contained in this map. |
Methods inherited from class java.util.AbstractMap |
---|
hashCode, putAll, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
hashCode, putAll |
Constructor Detail |
---|
public ConcurrentSkipListMap()
public ConcurrentSkipListMap(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(Map<? extends K,? extends V> m)
m
- the map whose mappings are to be placed in this map.
ClassCastException
- if the keys in m are not Comparable, or
are not mutually comparable.
NullPointerException
- if the specified map is null.public ConcurrentSkipListMap(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.
NullPointerException
- if the specified sorted map is
null.Method Detail |
---|
public Object clone()
clone
in class AbstractMap<K,V>
public boolean containsKey(Object key)
containsKey
in interface Map<K,V>
containsKey
in class AbstractMap<K,V>
key
- key whose presence in this map is to be tested.
ClassCastException
- if the key cannot be compared with the keys
currently in the map.
NullPointerException
- if the key is null.public V get(Object key)
get
in interface Map<K,V>
get
in class AbstractMap<K,V>
key
- key whose associated value is to be returned.
ClassCastException
- if the key cannot be compared with the keys
currently in the map.
NullPointerException
- if the key is null.public V put(K key, V value)
put
in interface Map<K,V>
put
in class AbstractMap<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
ClassCastException
- if the key cannot be compared with the keys
currently in the map.
NullPointerException
- if the key or value are null.public V remove(Object key)
remove
in interface Map<K,V>
remove
in class AbstractMap<K,V>
key
- key for which mapping should be removed
ClassCastException
- if the key cannot be compared with the keys
currently in the map.
NullPointerException
- if the key is null.public boolean containsValue(Object value)
containsValue
in interface Map<K,V>
containsValue
in class AbstractMap<K,V>
value
- value whose presence in this Map is to be tested.
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.
size
in interface Map<K,V>
size
in class AbstractMap<K,V>
public boolean isEmpty()
isEmpty
in interface Map<K,V>
isEmpty
in class AbstractMap<K,V>
public void clear()
clear
in interface Map<K,V>
clear
in class AbstractMap<K,V>
public 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.
keySet
in interface Map<K,V>
keySet
in interface SortedMap<K,V>
keySet
in class AbstractMap<K,V>
public 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 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.
values
in interface Map<K,V>
values
in interface SortedMap<K,V>
values
in class AbstractMap<K,V>
public Set<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.
entrySet
in interface Map<K,V>
entrySet
in interface SortedMap<K,V>
entrySet
in class AbstractMap<K,V>
public Set<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(Object o)
equals
in interface Map<K,V>
equals
in class AbstractMap<K,V>
o
- object to be compared for equality with this map.
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 ConcurrentMap<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
ClassCastException
- if the key cannot be compared with the keys
currently in the map.
NullPointerException
- if the key or value are null.public boolean remove(Object key, 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 ConcurrentMap<K,V>
key
- key with which the specified value is associated.value
- value associated with the specified key.
ClassCastException
- if the key cannot be compared with the keys
currently in the map.
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 ConcurrentMap<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.
ClassCastException
- if the key cannot be compared with the keys
currently in the map.
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 ConcurrentMap<K,V>
key
- key with which the specified value is associated.value
- value to be associated with the specified key.
ClassCastException
- if the key cannot be compared with the keys
currently in the map.
NullPointerException
- if the key or value are null.public Comparator<? super K> comparator()
comparator
in interface SortedMap<K,V>
public K firstKey()
firstKey
in interface SortedMap<K,V>
NoSuchElementException
- Map is empty.public K lastKey()
lastKey
in interface SortedMap<K,V>
NoSuchElementException
- Map is empty.public ConcurrentNavigableMap<K,V> subMap(K fromKey, K toKey)
subMap
in interface 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.
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).
IllegalArgumentException
- if fromKey is greater than
toKey.
NullPointerException
- if fromKey or toKey is
null.public ConcurrentNavigableMap<K,V> headMap(K toKey)
headMap
in interface SortedMap<K,V>
headMap
in interface ConcurrentNavigableMap<K,V>
headMap
in interface NavigableMap<K,V>
toKey
- high endpoint (exclusive) of the headMap.
ClassCastException
- if toKey is not compatible
with this map's comparator (or, if the map has no comparator,
if toKey does not implement Comparable).
NullPointerException
- if toKey is null.public ConcurrentNavigableMap<K,V> tailMap(K fromKey)
tailMap
in interface SortedMap<K,V>
tailMap
in interface ConcurrentNavigableMap<K,V>
tailMap
in interface NavigableMap<K,V>
fromKey
- low endpoint (inclusive) of the tailMap.
ClassCastException
- if fromKey is not
compatible with this map's comparator (or, if the map has no
comparator, if fromKey does not implement
Comparable).
NullPointerException
- if fromKey is null.public Map.Entry<K,V> ceilingEntry(K key)
ceilingEntry
in interface NavigableMap<K,V>
key
- the key.
ClassCastException
- if key cannot be compared with the
keys currently in the map.
NullPointerException
- if key is null.public K ceilingKey(K key)
ceilingKey
in interface NavigableMap<K,V>
key
- the key.
ClassCastException
- if key cannot be compared with the keys
currently in the map.
NullPointerException
- if key is null.public Map.Entry<K,V> lowerEntry(K key)
lowerEntry
in interface NavigableMap<K,V>
key
- the key.
ClassCastException
- if key cannot be compared with the keys
currently in the map.
NullPointerException
- if key is null.public K lowerKey(K key)
lowerKey
in interface NavigableMap<K,V>
key
- the key.
ClassCastException
- if key cannot be compared with the keys
currently in the map.
NullPointerException
- if key is null.public Map.Entry<K,V> floorEntry(K key)
floorEntry
in interface NavigableMap<K,V>
key
- the key.
ClassCastException
- if key cannot be compared with the keys
currently in the map.
NullPointerException
- if key is null.public K floorKey(K key)
floorKey
in interface NavigableMap<K,V>
key
- the key.
ClassCastException
- if key cannot be compared with the keys
currently in the map.
NullPointerException
- if key is null.public Map.Entry<K,V> higherEntry(K key)
higherEntry
in interface NavigableMap<K,V>
key
- the key.
ClassCastException
- if key cannot be compared with the keys
currently in the map.
NullPointerException
- if key is null.public K higherKey(K key)
higherKey
in interface NavigableMap<K,V>
key
- the key.
ClassCastException
- if key cannot be compared with the keys
currently in the map.
NullPointerException
- if key is null.public Map.Entry<K,V> firstEntry()
firstEntry
in interface NavigableMap<K,V>
public Map.Entry<K,V> lastEntry()
lastEntry
in interface NavigableMap<K,V>
public Map.Entry<K,V> pollFirstEntry()
pollFirstEntry
in interface NavigableMap<K,V>
public Map.Entry<K,V> pollLastEntry()
pollLastEntry
in interface NavigableMap<K,V>
|
JBoss Common Classes 2.2.17.GA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |