Package com.yahoo.collections
Class CopyOnWriteHashMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- com.yahoo.collections.CopyOnWriteHashMap<K,V>
-
public class CopyOnWriteHashMap<K,V> extends AbstractMap<K,V> implements Cloneable
A hashmap wrapper which defers cloning of the enclosed map until it is written to. 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description CopyOnWriteHashMap()
CopyOnWriteHashMap(int capacity)
CopyOnWriteHashMap(Map<K,V> map)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CopyOnWriteHashMap<K,V>
clone()
protected Map<K,V>
copyMap(Map<K,V> original)
Make a copy of the given map with the requisite deepness.Set<Map.Entry<K,V>>
entrySet()
boolean
equals(Object other)
int
hashCode()
V
put(K key, V value)
V
remove(Object key)
Override to avoid using iterator.remove-
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, get, isEmpty, keySet, putAll, size, toString, values
-
Methods inherited from class java.lang.Object
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
-
copyMap
protected Map<K,V> copyMap(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()
- Overrides:
clone
in classAbstractMap<K,V>
-
equals
public boolean equals(Object other)
-
-