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 class
V - 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

    Nested classes/interfaces inherited from class java.util.AbstractMap

    java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>

    Nested classes/interfaces inherited from interface java.util.Map

    java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
  • 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)
    When AbstractDefaultingHashMap.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

    Methods inherited from class java.util.AbstractMap

    equals, hashCode, toString

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Map

    equals, hashCode
  • Constructor Details

    • DefaultingHashMap

      public DefaultingHashMap​(java.lang.Class<?> valueClass)
      Parameters:
      valueClass - this Class' default constructor will be instantiated from newDefaultValue(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

      public DefaultingHashMap​(java.util.function.Function<K,​V> defaultFn)
  • Method Details