Package com.yahoo.collections
Class CopyOnWriteHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- com.yahoo.collections.CopyOnWriteHashMap<K,V>
-
- All Implemented Interfaces:
java.lang.Cloneable
,java.util.Map<K,V>
public class CopyOnWriteHashMap<K,V> extends java.util.AbstractMap<K,V> implements java.lang.Cloneable
A hashmap wrapper which defers cloning of the enclosed map until it is written. Use this to make clones cheap in maps which are often not further modified.As with regular maps, this can only be used safely if the content of the map is immutable. If not, the
copyMap(java.util.Map<K, V>)
method can be overridden to perform a deep clone.- Author:
- bratseth
-
-
Constructor Summary
Constructors Constructor Description CopyOnWriteHashMap()
CopyOnWriteHashMap(int capacity)
CopyOnWriteHashMap(java.util.Map<K,V> map)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CopyOnWriteHashMap<K,V>
clone()
protected java.util.Map<K,V>
copyMap(java.util.Map<K,V> original)
Make a copy of the given map with the requisite deepness.java.util.Set<java.util.Map.Entry<K,V>>
entrySet()
V
put(K key, V value)
V
remove(java.lang.Object key)
Override to avoid using iterator.remove-
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, size, toString, values
-
-
-
-
Method Detail
-
copyMap
protected java.util.Map<K,V> copyMap(java.util.Map<K,V> original)
Make a copy of the given map with the requisite deepness. This default implementation does return new HashMap<>(original);
-
clone
public CopyOnWriteHashMap<K,V> clone()
-
-