public class CopyOnWriteMap<K,V> extends Object implements Map<K,V>
Map in which all mutating operations (e.g. put, putAll) are implemented by making a fresh copy of the underlying map.
Iterators over this map are guaranteed to produce a safe-iteration and not to throw ConcurrentModificationException. The iterator will not reflect concurrent additions, removals, or changes to this map.
Note: mutations on this map are costly, but may be more efficient than alternatives when "get" operations vastly outnumber mutations. All mutating operations are synchronized, so concurrent mutation can be prevented by holding synchronization on this object.
| Modifier and Type | Class and Description |
|---|---|
protected class |
CopyOnWriteMap.EntrySet
A set of entries backed by this map.
|
protected class |
CopyOnWriteMap.KeySet
A set of keys backed by this map.
|
| Constructor and Description |
|---|
CopyOnWriteMap(Class clazz) |
CopyOnWriteMap(Map<K,V> map)
Construct a CopyOnWriteMap, initialized with the contents of the specified map.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
containsKey(Object oKey) |
boolean |
containsValue(Object oValue) |
protected Map<K,V> |
copyMap(Map<K,V> map)
Create an instance of
Map based on the contents of the provided map. |
Set<Map.Entry<K,V>> |
entrySet()
Return a set view of the underlying map.
|
boolean |
equals(Object o) |
V |
get(Object oKey) |
protected Map<K,V> |
getInternalMap()
Return the internal map.
|
int |
hashCode() |
protected Map<K,V> |
instantiateMap(Class clazz)
|
boolean |
isEmpty() |
Set<K> |
keySet()
Returns a Set view of the keys contained in the underlying map.
|
V |
put(K oKey, V oValue) |
void |
putAll(Map<? extends K,? extends V> map) |
V |
remove(Object oKey) |
protected void |
setInternalMap(Map<K,V> map)
Set the internal map.
|
int |
size() |
String |
toString() |
Collection<V> |
values() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAllpublic CopyOnWriteMap(Class clazz)
protected Map<K,V> getInternalMap()
protected void setInternalMap(Map<K,V> map)
map - the new internal mapprotected Map<K,V> instantiateMap(Class clazz)
clazz - the type of Map to instantiateMapIllegalArgumentException - if the provided Class does not implement Map.protected Map<K,V> copyMap(Map<K,V> map)
Map based on the contents of the provided map.map - the map to copyMap populated with the contents of the provided mappublic boolean containsKey(Object oKey)
containsKey in interface Map<K,V>public boolean containsValue(Object oValue)
containsValue in interface Map<K,V>public boolean equals(Object o)
public int hashCode()