Package org.apache.mina.util
Class CopyOnWriteMap<K,V>
- java.lang.Object
-
- org.apache.mina.util.CopyOnWriteMap<K,V>
-
- Type Parameters:
K
- The key typeV
- The value type
public class CopyOnWriteMap<K,V> extends Object implements Map<K,V>, Cloneable
A thread-safe version ofMap
in which all operations that change the Map are implemented by making a new copy of the underlying Map. While the creation of a new Map can be expensive, this class is designed for cases in which the primary function is to read data from the Map, not to modify the Map. Therefore the operations that do not cause a change to this class happen quickly and concurrently.- Author:
- Apache MINA Project
-
-
Constructor Summary
Constructors Constructor Description CopyOnWriteMap()
Creates a new instance of CopyOnWriteMap.CopyOnWriteMap(int initialCapacity)
Creates a new instance of CopyOnWriteMap with the specified initial sizeCopyOnWriteMap(Map<K,V> data)
Creates a new instance of CopyOnWriteMap in which the initial data being held by this map is contained in the supplied map.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all entries in this map.Object
clone()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<K,V>>
entrySet()
This method will return a read-onlySet
.V
get(Object key)
boolean
isEmpty()
Set<K>
keySet()
This method will return a read-onlySet
.V
put(K key, V value)
Adds the provided key and value to this map.void
putAll(Map<? extends K,? extends V> newData)
Inserts all the keys and values contained in the provided map to this map.V
remove(Object key)
Removed the value and key from this map based on the provided key.int
size()
Collection<V>
values()
This method will return a read-onlyCollection
.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
put
public V put(K key, V value)
Adds the provided key and value to this map.- Specified by:
put
in interfaceMap<K,V>
- See Also:
Map.put(java.lang.Object, java.lang.Object)
-
remove
public V remove(Object key)
Removed the value and key from this map based on the provided key.- Specified by:
remove
in interfaceMap<K,V>
- See Also:
Map.remove(java.lang.Object)
-
putAll
public void putAll(Map<? extends K,? extends V> newData)
Inserts all the keys and values contained in the provided map to this map.- Specified by:
putAll
in interfaceMap<K,V>
- See Also:
Map.putAll(java.util.Map)
-
clear
public void clear()
Removes all entries in this map.- Specified by:
clear
in interfaceMap<K,V>
- See Also:
Map.clear()
-
size
public int size()
- Specified by:
size
in interfaceMap<K,V>
- Returns:
- the number of key/value pairs in this map.
- See Also:
Map.size()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceMap<K,V>
- Returns:
- true if this map is empty, otherwise false.
- See Also:
Map.isEmpty()
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<K,V>
- Returns:
- true if this map contains the provided key, otherwise this method return false.
- See Also:
Map.containsKey(java.lang.Object)
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<K,V>
- Returns:
- true if this map contains the provided value, otherwise this method returns false.
- See Also:
Map.containsValue(java.lang.Object)
-
get
public V get(Object key)
- Specified by:
get
in interfaceMap<K,V>
- Returns:
- the value associated with the provided key from this map.
- See Also:
Map.get(java.lang.Object)
-
values
public Collection<V> values()
This method will return a read-onlyCollection
.
-
-