| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ConcurrentSkipListMap empty = new ConcurrentSkipListMap();
Based on 77 examples
public class ConcurrentSkipListMap extends AbstractMap implements ConcurrentNavigableMap, Cloneable, Serializable
A scalable concurrent {@link ConcurrentNavigableMap} implementation. The map is sorted according to the {@linkplain Comparable natural ordering} of its keys, or by a {@link Comparator} provided at map 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 {@link 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 {@link Map} and {@link 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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
AbstractMap.SimpleEntry, AbstractMap.SimpleImmutableEntry |
Constructor Summary | |
---|---|
Constructs a new, empty map, sorted according to the java.lang.Comparable of the keys. |
|
ConcurrentSkipListMap(Comparator comparator) Constructs a new, empty map, sorted according to the specified comparator. |
|
Constructs a new map containing the same mappings as the given map, sorted according to the java.lang.Comparable of the keys. |
|
Constructs a new map containing the same mappings and using the same ordering as the specified sorted map. |
Method Summary | |
---|---|
Map.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. |
ConcurrentSkipListMap |
clone() Returns a shallow copy of this ConcurrentSkipListMap instance. |
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 |
|
ConcurrentNavigableMap |
|
Set |
entrySet() Returns a java.util.Set view of the mappings contained in this map. |
boolean |
Compares the specified object with this map for equality. |
Map.Entry |
Returns a key-value mapping associated with the least key in this map, or null if the map is empty. |
Object |
firstKey() |
Map.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 |
|
Object |
Returns the value to which the specified key is mapped, or if this map contains no mapping for the key. |
ConcurrentNavigableMap |
|
ConcurrentNavigableMap |
|
Map.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 |
|
boolean |
isEmpty() Returns true if this map contains no key-value mappings. |
NavigableSet |
keySet() Returns a java.util.NavigableSet view of the keys contained in this map. |
Map.Entry |
Returns a key-value mapping associated with the greatest key in this map, or null if the map is empty. |
Object |
lastKey() |
Map.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 |
|
NavigableSet |
|
Map.Entry |
Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty. |
Map.Entry |
Removes and returns a key-value mapping associated with the greatest key in this map, or null if the map is empty. |
Object |
Associates the specified value with the specified key in this map. |
Object |
putIfAbsent(Object key, Object value) |
Object |
Removes the mapping for the specified key from this map if present. |
boolean |
|
Object |
|
boolean |
|
int |
size() Returns the number of key-value mappings in this map. |
ConcurrentNavigableMap |
|
ConcurrentNavigableMap |
|
ConcurrentNavigableMap |
|
ConcurrentNavigableMap |
|
Collection |
values() Returns a java.util.Collection view of the values contained in this map. |
Methods inherited from class java.util.AbstractMap |
---|
clear, clone, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ConcurrentSkipListMap()
public ConcurrentSkipListMap(Comparator comparator)
comparator
- the comparator that will be used to order this map.
If null, the {@linkplain Comparable natural
ordering} of the keys will be used.public ConcurrentSkipListMap(Map m)
m
- the map whose mappings are to be placed in this mappublic ConcurrentSkipListMap(SortedMap m)
m
- the sorted map whose mappings are to be placed in this
map, and whose comparator is to be used to sort this mapMethod Detail |
---|
public Map.Entry ceilingEntry(Object key)
key
public Object ceilingKey(Object key)
key
public void clear()
clear
in class AbstractMap
public ConcurrentSkipListMap clone()
clone
in class AbstractMap
public Comparator comparator()
public boolean containsKey(Object key)
containsKey
in class AbstractMap
key
- key whose presence in this map is to be testedpublic boolean containsValue(Object value)
containsValue
in class AbstractMap
value
- value whose presence in this map is to be testedpublic NavigableSet descendingKeySet()
public ConcurrentNavigableMap descendingMap()
public Set entrySet()
The view's iterator is a "weakly consistent" iterator that will never throw {@link 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 class AbstractMap
public boolean equals(Object o)
equals
in class AbstractMap
o
- object to be compared for equality with this mappublic Map.Entry firstEntry()
public Object firstKey()
public Map.Entry floorEntry(Object key)
key
- the keypublic Object floorKey(Object key)
key
- the keypublic Object get(Object key)
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.)
get
in class AbstractMap
key
public ConcurrentNavigableMap headMap(Object toKey)
toKey
public ConcurrentNavigableMap headMap(Object toKey, boolean inclusive)
toKey
inclusive
public Map.Entry higherEntry(Object key)
key
- the keypublic Object higherKey(Object key)
key
- the keypublic boolean isEmpty()
isEmpty
in class AbstractMap
public NavigableSet keySet()
The view's {@code iterator} is a "weakly consistent" iterator that will never throw {@link 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}.
keySet
in class AbstractMap
public Map.Entry lastEntry()
public Object lastKey()
public Map.Entry lowerEntry(Object key)
key
public Object lowerKey(Object key)
key
public NavigableSet navigableKeySet()
public Map.Entry pollFirstEntry()
public Map.Entry pollLastEntry()
public Object put(Object key, Object value)
put
in class AbstractMap
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keypublic Object putIfAbsent(Object key, Object value)
key
value
public Object remove(Object key)
remove
in class AbstractMap
key
- key for which mapping should be removedpublic boolean remove(Object key, Object value)
key
value
public Object replace(Object key, Object value)
key
value
public boolean replace(Object key, Object oldValue, Object newValue)
key
oldValue
newValue
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 class AbstractMap
public ConcurrentNavigableMap subMap(Object fromKey, boolean fromInclusive, Object toKey, boolean toInclusive)
fromKey
fromInclusive
toKey
toInclusive
public ConcurrentNavigableMap subMap(Object fromKey, Object toKey)
fromKey
toKey
public ConcurrentNavigableMap tailMap(Object fromKey)
fromKey
public ConcurrentNavigableMap tailMap(Object fromKey, boolean inclusive)
fromKey
inclusive
public Collection values()
The view's iterator is a "weakly consistent" iterator that will never throw {@link 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 class AbstractMap
| |||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |