|
||||||||||
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 abstract 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.)
may be supported if the views are live but as with the Map
interface,
add and addAll are not and throw UnsupportedOperationException
.
The actual copy is performed by the abstract copy(Map)
method. This
implementation of this method 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. Standard j.u.c Map
implementation
versions are available from the CopyOnWriteSortedMap.Builder
.
Collection views of the keys, values and entries are optionally
live
or stable
. Live views
are modifiable will cause a copy if a modifying method is called on them.
Methods on these will reflect the current state of the collection, although
iterators will be snapshot style. If the collection views are stable they are
unmodifiable, and will be a snapshot of the state of the map at the time the
collection was asked for. Regardless of the View policy though, all 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. If the underlying map implementation does not
support concurrent get(Object)
calls for instance then it is
unsuitable as a candidate.
Nested Class Summary | |
---|---|
protected static class |
AbstractCopyOnWriteMap.CollectionView<E>
|
static class |
AbstractCopyOnWriteMap.View<K,V>
Provides access to the views of the underlying key, value and entry collections. |
static class |
CopyOnWriteSortedMap.Builder<K,V>
Build a CopyOnWriteSortedMap and specify all the options. |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Constructor Summary | |
---|---|
protected |
CopyOnWriteSortedMap(AbstractCopyOnWriteMap.View.Type viewType)
Create a new empty CopyOnWriteMap . |
protected |
CopyOnWriteSortedMap(java.util.Map<? extends K,? extends V> map,
AbstractCopyOnWriteMap.View.Type viewType)
Create a new CopyOnWriteMap with the supplied Map to
initialize the values. |
Method Summary | ||
---|---|---|
static
|
builder()
Get a CopyOnWriteSortedMap.Builder for a CopyOnWriteSortedMap instance. |
|
void |
clear()
|
|
java.util.Comparator<? super K> |
comparator()
|
|
boolean |
containsKey(java.lang.Object key)
|
|
boolean |
containsValue(java.lang.Object value)
|
|
protected M |
copy()
|
|
protected abstract
|
copy(N map)
Copy function, implemented by sub-classes. |
|
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()
|
|
static
|
newTreeMap()
Create a new CopyOnWriteSortedMap where the underlying map
instances are TreeMap and the sort uses the key's natural order. |
|
static
|
newTreeMap(java.util.Comparator<? super K> comparator)
Create a new CopyOnWriteSortedMap where the underlying map
instances are TreeMap . |
|
static
|
newTreeMap(java.util.Map<? extends K,? extends V> map)
Create a new CopyOnWriteSortedMap where the underlying map
instances are TreeMap , the sort uses the key's natural order and
the initial values are supplied. |
|
static
|
newTreeMap(java.util.Map<? extends K,? extends V> map,
java.util.Comparator<? super K> comparator)
Create a new CopyOnWriteSortedMap where the underlying map
instances are TreeMap , the sort uses the key's natural order and
the initial values are supplied. |
|
V |
put(K key,
V value)
|
|
void |
putAll(java.util.Map<? extends K,? extends V> t)
|
|
V |
putIfAbsent(K key,
V value)
|
|
V |
remove(java.lang.Object key)
|
|
boolean |
remove(java.lang.Object key,
java.lang.Object value)
|
|
V |
replace(K key,
V value)
|
|
boolean |
replace(K key,
V oldValue,
V newValue)
|
|
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.SortedMap |
---|
entrySet, keySet, values |
Methods inherited from interface java.util.Map |
---|
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size |
Constructor Detail |
---|
protected CopyOnWriteSortedMap(AbstractCopyOnWriteMap.View.Type viewType)
CopyOnWriteMap
.
protected CopyOnWriteSortedMap(java.util.Map<? extends K,? extends V> map, AbstractCopyOnWriteMap.View.Type viewType)
CopyOnWriteMap
with the supplied Map
to
initialize the values.
map
- the initial map to initialize withMethod Detail |
---|
public static <K,V> CopyOnWriteSortedMap.Builder<K,V> builder()
CopyOnWriteSortedMap.Builder
for a CopyOnWriteSortedMap
instance.
K
- key typeV
- value type
public static <K,V> CopyOnWriteSortedMap<K,V> newTreeMap()
CopyOnWriteSortedMap
where the underlying map
instances are TreeMap
and the sort uses the key's natural order.
This map has stable
views.
public static <K,V> CopyOnWriteSortedMap<K,V> newTreeMap(@NotNull java.util.Map<? extends K,? extends V> map)
CopyOnWriteSortedMap
where the underlying map
instances are TreeMap
, the sort uses the key's natural order and
the initial values are supplied.
This map has stable
views.
map
- the map to use as the initial values.public static <K,V> CopyOnWriteSortedMap<K,V> newTreeMap(@NotNull java.util.Comparator<? super K> comparator)
CopyOnWriteSortedMap
where the underlying map
instances are TreeMap
.
This map has stable
views.
comparator
- the Comparator to use for ordering the keys. Note,
should be serializable if this map is to be serialized.public static <K,V> CopyOnWriteSortedMap<K,V> newTreeMap(@NotNull java.util.Map<? extends K,? extends V> map, @NotNull java.util.Comparator<? super K> comparator)
CopyOnWriteSortedMap
where the underlying map
instances are TreeMap
, the sort uses the key's natural order and
the initial values are supplied.
This map has stable
views.
map
- to use as the initial values.comparator
- for ordering.protected abstract <N extends java.util.Map<? extends K,? extends V>> java.util.SortedMap<K,V> copy(N map)
N
- the map to copy and return.map
- the initial values of the newly created map.
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 boolean remove(java.lang.Object key, java.lang.Object value)
remove
in interface java.util.concurrent.ConcurrentMap<K,V>
public boolean replace(K key, V oldValue, V newValue)
replace
in interface java.util.concurrent.ConcurrentMap<K,V>
public V replace(K key, V value)
replace
in interface java.util.concurrent.ConcurrentMap<K,V>
public final V put(K key, V value)
put
in interface java.util.Map<K,V>
public V putIfAbsent(K key, V value)
putIfAbsent
in interface java.util.concurrent.ConcurrentMap<K,V>
public final void putAll(java.util.Map<? extends K,? extends V> t)
putAll
in interface java.util.Map<K,V>
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 |