|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.atlassian.util.concurrent.CopyOnWriteSortedMap<K,V>
K
- the key typeV
- the value type@ThreadSafe public class CopyOnWriteSortedMap<K,V>
/** A thread-safe variant of SortedMap
in which all mutative operations (the
"destructive" operations described by SortedMap
put, remove and so on) are implemented by
making a fresh copy of the underlying map.
This is ordinarily too costly, but may be more efficient than alternatives when
traversal operations vastly out-number mutations, and is useful when you cannot or don't want to
synchronize traversals, yet need to preclude interference among concurrent threads. The
"snapshot" style iterators on the collections returned by entrySet()
, keySet()
and values()
use a reference to the internal map at the point that the iterator was
created. This map never changes during the lifetime of the iterator, so interference is
impossible and the iterator is guaranteed not to throw ConcurrentModificationException.
The iterators will not reflect additions, removals, or changes to the list since the iterator was
created. Removing elements via these iterators is not supported. The mutable operations on these
collections (remove, retain etc.) are supported but as with the Map
interface, add and
addAll are not and throw UnsupportedOperationException
.
The actual copy is performed by a supplied CopyOnWriteSortedMap.CopyFunction
object. The Factory is
responsible for the underlying SortedMap
implementation (for instance a TreeMap
)
and therefore the semantics of what this map will cope with as far as null keys and values,
iteration ordering etc.
There are supplied CopyOnWriteSortedMap.Functions
for the Java Collections SortedMap
implementation.
Views of the keys, values and entries are modifiable and will cause a copy. Views taken using
subMap(Object, Object)
, headMap(Object)
and tailMap(Object)
are
unmodifiable.
Please note that the thread-safety guarantees are limited to the thread-safety
of the non-mutative (non-destructive) operations of the underlying map implementation. For
instance implementations with access ordering are actually structurally modified by the
get(Object)
method and are therefore not suitable candidates as delegates for this
class.
Nested Class Summary | |
---|---|
protected static class |
AbstractCopyOnWriteMap.CollectionView<E>
|
static interface |
CopyOnWriteSortedMap.CopyFunction<M extends java.util.SortedMap<?,?>>
|
static class |
CopyOnWriteSortedMap.Functions
Factories that create the standard Collections Map implementations. |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Constructor Summary | |
---|---|
CopyOnWriteSortedMap(CopyOnWriteSortedMap.CopyFunction<java.util.SortedMap<K,V>> factory)
Create a new empty CopyOnWriteMap with the CopyOnWriteSortedMap.CopyFunction for creating our
actual delegate instances. |
|
CopyOnWriteSortedMap(java.util.SortedMap<K,V> map,
CopyOnWriteSortedMap.CopyFunction<java.util.SortedMap<K,V>> factory)
Create a new CopyOnWriteMap with the supplied Map to initialize the values
and the CopyOnWriteSortedMap.CopyFunction for creating our actual delegate instances. |
Method Summary | |
---|---|
void |
clear()
|
java.util.Comparator<? super K> |
comparator()
|
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
protected M |
copy()
|
java.util.Set<java.util.Map.Entry<K,V>> |
entrySet()
|
boolean |
equals(java.lang.Object o)
|
K |
firstKey()
|
V |
get(java.lang.Object key)
|
protected M |
getDelegate()
|
int |
hashCode()
|
java.util.SortedMap<K,V> |
headMap(K toKey)
|
boolean |
isEmpty()
|
java.util.Set<K> |
keySet()
|
K |
lastKey()
|
V |
put(K key,
V value)
|
void |
putAll(java.util.Map<? extends K,? extends V> t)
|
V |
remove(java.lang.Object key)
|
protected void |
removeAll(java.util.Collection<K> keys)
|
protected void |
set(M map)
|
int |
size()
|
java.util.SortedMap<K,V> |
subMap(K fromKey,
K toKey)
|
java.util.SortedMap<K,V> |
tailMap(K fromKey)
|
java.lang.String |
toString()
|
java.util.Collection<V> |
values()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
Constructor Detail |
---|
public CopyOnWriteSortedMap(java.util.SortedMap<K,V> map, CopyOnWriteSortedMap.CopyFunction<java.util.SortedMap<K,V>> factory)
CopyOnWriteMap
with the supplied Map
to initialize the values
and the CopyOnWriteSortedMap.CopyFunction
for creating our actual delegate instances.
map
- the initial map to initialize withfactory
- the copy functionpublic CopyOnWriteSortedMap(CopyOnWriteSortedMap.CopyFunction<java.util.SortedMap<K,V>> factory)
CopyOnWriteMap
with the CopyOnWriteSortedMap.CopyFunction
for creating our
actual delegate instances.
factory
- the copy functionMethod Detail |
---|
public java.util.Comparator<? super K> comparator()
comparator
in interface java.util.SortedMap<K,V>
public K firstKey()
firstKey
in interface java.util.SortedMap<K,V>
public K lastKey()
lastKey
in interface java.util.SortedMap<K,V>
public java.util.SortedMap<K,V> headMap(K toKey)
headMap
in interface java.util.SortedMap<K,V>
public java.util.SortedMap<K,V> tailMap(K fromKey)
tailMap
in interface java.util.SortedMap<K,V>
public java.util.SortedMap<K,V> subMap(K fromKey, K toKey)
subMap
in interface java.util.SortedMap<K,V>
public final void clear()
clear
in interface java.util.Map<K,V>
public final V remove(java.lang.Object key)
remove
in interface java.util.Map<K,V>
public final V put(K key, V value)
put
in interface java.util.Map<K,V>
public final void putAll(java.util.Map<? extends K,? extends V> t)
putAll
in interface java.util.Map<K,V>
protected void removeAll(java.util.Collection<K> keys)
protected M copy()
protected void set(M map)
public final java.util.Set<java.util.Map.Entry<K,V>> entrySet()
entrySet
in interface java.util.Map<K,V>
public final java.util.Set<K> keySet()
keySet
in interface java.util.Map<K,V>
public final java.util.Collection<V> values()
values
in interface java.util.Map<K,V>
public final boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<K,V>
public final boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<K,V>
public final V get(java.lang.Object key)
get
in interface java.util.Map<K,V>
public final boolean isEmpty()
isEmpty
in interface java.util.Map<K,V>
public final int size()
size
in interface java.util.Map<K,V>
public final boolean equals(java.lang.Object o)
equals
in interface java.util.Map<K,V>
equals
in class java.lang.Object
public final int hashCode()
hashCode
in interface java.util.Map<K,V>
hashCode
in class java.lang.Object
protected final M getDelegate()
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |