Package com.tangosol.util
Class CopyOnWriteMap<K,V>
- java.lang.Object
-
- com.tangosol.util.CopyOnWriteMap<K,V>
-
- All Implemented Interfaces:
Map<K,V>
public class CopyOnWriteMap<K,V> extends Object implements Map<K,V>
A thread-safe variant ofMapin 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.
- Since:
- Coherence 3.7.2
- Author:
- pp 2011.09.17, rhl 2010.09.09 (from CopyOnWriteLongArray)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classCopyOnWriteMap.EntrySetA set of entries backed by this map.protected classCopyOnWriteMap.KeySetA set of keys backed by this map.
-
Constructor Summary
Constructors Constructor Description CopyOnWriteMap(Class clazz)CopyOnWriteMap(Map<K,V> map)Construct a CopyOnWriteMap, initialized with the contents of the specified map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object oKey)booleancontainsValue(Object oValue)protected Map<K,V>copyMap(Map<K,V> map)Create an instance ofMapbased on the contents of the provided map.Set<Map.Entry<K,V>>entrySet()Return a set view of the underlying map.booleanequals(Object o)Vget(Object oKey)protected Map<K,V>getInternalMap()Return the internal map.inthashCode()protected Map<K,V>instantiateMap(Class clazz)booleanisEmpty()Set<K>keySet()Returns a Set view of the keys contained in the underlying map.Vput(K oKey, V oValue)voidputAll(Map<? extends K,? extends V> map)Vremove(Object oKey)protected voidsetInternalMap(Map<K,V> map)Set the internal map.intsize()StringtoString()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
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
getInternalMap
protected Map<K,V> getInternalMap()
Return the internal map.- Returns:
- the internal map
-
setInternalMap
protected void setInternalMap(Map<K,V> map)
Set the internal map.- Parameters:
map- the new internal map
-
instantiateMap
protected Map<K,V> instantiateMap(Class clazz)
- Parameters:
clazz- the type ofMapto instantiate- Returns:
- a new empty instance of
Map - Throws:
IllegalArgumentException- if the providedClassdoes not implementMap.
-
copyMap
protected Map<K,V> copyMap(Map<K,V> map)
Create an instance ofMapbased on the contents of the provided map.- Parameters:
map- the map to copy- Returns:
- an instance of
Mappopulated with the contents of the provided map
-
containsKey
public boolean containsKey(Object oKey)
- Specified by:
containsKeyin interfaceMap<K,V>
-
containsValue
public boolean containsValue(Object oValue)
- Specified by:
containsValuein interfaceMap<K,V>
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
-