Package com.tangosol.util
Class CopyOnWriteMap<K,V>
java.lang.Object
com.tangosol.util.CopyOnWriteMap<K,V>
- All Implemented Interfaces:
Map<K,
V>
A thread-safe variant of
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.
- Since:
- Coherence 3.7.2
- Author:
- pp 2011.09.17, rhl 2010.09.09 (from CopyOnWriteLongArray)
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
A set of entries backed by this map.protected class
A set of keys backed by this map. -
Constructor Summary
ConstructorDescriptionCopyOnWriteMap
(Class clazz) CopyOnWriteMap
(Map<K, V> map) Construct a CopyOnWriteMap, initialized with the contents of the specified map. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Object oKey) boolean
containsValue
(Object oValue) Create an instance ofMap
based on the contents of the provided map.entrySet()
Return a set view of the underlying map.boolean
Return the internal map.int
hashCode()
instantiateMap
(Class clazz) boolean
isEmpty()
keySet()
Returns a Set view of the keys contained in the underlying map.void
protected void
setInternalMap
(Map<K, V> map) Set the internal map.int
size()
toString()
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
-
Constructor Details
-
CopyOnWriteMap
-
CopyOnWriteMap
Construct a CopyOnWriteMap, initialized with the contents of the specified map.- Parameters:
map
- the initial map
-
-
Method Details
-
getInternalMap
Return the internal map.- Returns:
- the internal map
-
setInternalMap
Set the internal map.- Parameters:
map
- the new internal map
-
instantiateMap
- Parameters:
clazz
- the type ofMap
to instantiate- Returns:
- a new empty instance of
Map
- Throws:
IllegalArgumentException
- if the providedClass
does not implementMap
.
-
copyMap
Create an instance ofMap
based on the contents of the provided map.- Parameters:
map
- the map to copy- Returns:
- an instance of
Map
populated with the contents of the provided map
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
Returns a Set view of the keys contained in the underlying map. -
entrySet
Return a set view of the underlying map. -
values
-
equals
-
hashCode
public int hashCode() -
toString
-