Package org.spiderwiz.zutils
Class ZHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
org.spiderwiz.zutils.ZHashMap<K,V>
- Type Parameters:
K- type of keyV- type of value
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,V>
- Direct Known Subclasses:
ZDictionary
public class ZHashMap<K,V> extends HashMap<K,V>
A synchronized implementation of
HashMap.
The Java implementation of HashMap is unsynchronized. This class extends the implementation to provide
synchronization.
- See Also:
- Serialized Form
-
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
-
Method Summary
Modifier and Type Method Description voidclear()Synchronized implementation ofHashMap.clear().VcomputeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)Synchronized implementation ofHashMap.computeIfAbsent(java.lang.Object, java.util.function.Function).booleancontainsKey(Object key)Synchronized implementation ofHashMap.containsKey(java.lang.Object).voidforEach(BiConsumer<? super K,? super V> action)Synchronized implementation ofHashMap.forEach(java.util.function.BiConsumer)Vget(Object key)Synchronized implementation ofHashMap.get(java.lang.Object).voidlockRead()Locks the map for reading.voidlockWrite()Locks the map for writing.Vput(K key, V value)Synchronized implementation ofHashMap.put(java.lang.Object, java.lang.Object).voidputAll(Map<? extends K,? extends V> m)Synchronized implementation ofHashMap.putAll(java.util.Map).VputIfAbsent(K key, V value)Synchronized implementation ofHashMap.putIfAbsent(java.lang.Object, java.lang.Object).VputIfAbsentReturnNew(K key, V value)This does whatHashMap.putIfAbsent(java.lang.Object, java.lang.Object)does (plus synchronization), but it always returns the newly stored value.Vremove(Object key)Synchronized implementation ofHashMap.remove(java.lang.Object).booleanremoveAll(Collection<V> c)Removes a collection of values from the map.booleanremoveIf(BiFunction<? super K,? super V,Boolean> filter)Removes all of the elements of this map that satisfy the given two-argument predicate, assuming the first argument is the element key and the second is the element value.intsize()Synchronized implementation ofHashMap.size().voidunlockRead()Unlocks the map after reading.voidunlockWrite()Unlocks the map after writing.Methods inherited from class java.util.HashMap
clone, compute, computeIfPresent, containsValue, entrySet, getOrDefault, isEmpty, keySet, merge, remove, replace, replace, replaceAll, values
-
Constructor Details
-
Method Details
-
lockRead
public final void lockRead()Locks the map for reading.This method is used by the class internally to provide synchronization, but you can use it directly when you need to perform a synchronized bulk read operation on the map.
-
lockWrite
public final void lockWrite()Locks the map for writing.This method is used by the class internally to provide synchronization, but you can use it directly when you need to perform a synchronized bulk write operation on the map.
-
unlockRead
public final void unlockRead()Unlocks the map after reading.This method is used by the class internally, but you should use it directly if you use
lockRead()directly. -
unlockWrite
public final void unlockWrite()Unlocks the map after writing.This method is used by the class internally, but you should use it directly if you use
lockWrite()directly. -
get
Synchronized implementation ofHashMap.get(java.lang.Object). -
put
Synchronized implementation ofHashMap.put(java.lang.Object, java.lang.Object). -
putAll
Synchronized implementation ofHashMap.putAll(java.util.Map). -
putIfAbsent
Synchronized implementation ofHashMap.putIfAbsent(java.lang.Object, java.lang.Object).- Specified by:
putIfAbsentin interfaceMap<K,V>- Overrides:
putIfAbsentin classHashMap<K,V>- Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Returns:
- the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)
-
computeIfAbsent
Synchronized implementation ofHashMap.computeIfAbsent(java.lang.Object, java.util.function.Function).- Specified by:
computeIfAbsentin interfaceMap<K,V>- Overrides:
computeIfAbsentin classHashMap<K,V>- Parameters:
key- key with which the specified value is to be associatedmappingFunction- the mapping function to compute a value- Returns:
- the current (existing or computed) value associated with the specified key, or null if the computed value is null
-
putIfAbsentReturnNew
This does whatHashMap.putIfAbsent(java.lang.Object, java.lang.Object)does (plus synchronization), but it always returns the newly stored value.- Parameters:
key- key with which the specified value is to be associated.value- value to be associated with the specified key.- Returns:
- the newly stored value.
-
remove
Synchronized implementation ofHashMap.remove(java.lang.Object). -
removeAll
Removes a collection of values from the map.- Parameters:
c- collection containing values to be removed from this map.- Returns:
- true if this map changed as a result of the call.
-
removeIf
Removes all of the elements of this map that satisfy the given two-argument predicate, assuming the first argument is the element key and the second is the element value.- Parameters:
filter- a two-argument predicate which returnstruefor elements whose key matches the first argument and value matches the second argument to be removed- Returns:
trueif any elements were removed
-
size
public int size()Synchronized implementation ofHashMap.size(). -
containsKey
Synchronized implementation ofHashMap.containsKey(java.lang.Object).- Specified by:
containsKeyin interfaceMap<K,V>- Overrides:
containsKeyin classHashMap<K,V>- Parameters:
key- the key whose presence in this map is to be tested.- Returns:
- true if this map contains a mapping for the specified key.
-
clear
public void clear()Synchronized implementation ofHashMap.clear(). -
forEach
Synchronized implementation ofHashMap.forEach(java.util.function.BiConsumer)
-