Class DefaultingHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
com.onenetwork.platform.tools.collections.AbstractDefaultingHashMap<K,V>
com.onenetwork.platform.tools.collections.DefaultingHashMap<K,V>
- Type Parameters:
K
- key classV
- value class
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<K,V>
public class DefaultingHashMap<K,V> extends AbstractDefaultingHashMap<K,V>
Default implementation of
AbstractDefaultingHashMap
which will create
a new Value object using the default constructor of a given class.- See Also:
- Serialized Form
-
Nested Class Summary
-
Constructor Summary
Constructors Constructor Description DefaultingHashMap(java.lang.Class<?> valueClass)
DefaultingHashMap(java.util.function.Function<K,V> defaultFn)
-
Method Summary
Modifier and Type Method Description protected V
newDefaultValue(java.lang.Object key)
WhenAbstractDefaultingHashMap.get(Object)
is called for a nonexistent key, this method will be called to initialize a default value for that key and put() it in the Map.Methods inherited from class com.onenetwork.platform.tools.collections.AbstractDefaultingHashMap
get
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Constructor Details
-
DefaultingHashMap
public DefaultingHashMap(java.lang.Class<?> valueClass)- Parameters:
valueClass
- this Class' default constructor will be instantiated fromnewDefaultValue(Object)
. To faciliate usage with class literals like ArrayList.class, HashMap.class, etc., this parameter takes the Class wildcard type, and a runtime downcast is made during newDefaultValue; as a result, the client is expected to give the correct Class to this constructor, otherwise he will face a RuntimeException (rather than a compile-time exception)
-
DefaultingHashMap
-
-
Method Details
-
newDefaultValue
Description copied from class:AbstractDefaultingHashMap
WhenAbstractDefaultingHashMap.get(Object)
is called for a nonexistent key, this method will be called to initialize a default value for that key and put() it in the Map.- Specified by:
newDefaultValue
in classAbstractDefaultingHashMap<K,V>
- Returns:
-