Class SupplyingMap<K,​V>

java.lang.Object
java.util.AbstractMap<K,​V>
java.util.HashMap<K,​V>
bayern.steinbrecher.javaUtility.SupplyingMap<K,​V>
Type Parameters:
K - The type of the key values.
V - The type of values.
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<K,​V>

public class SupplyingMap<K,​V>
extends java.util.HashMap<K,​V>
Represents a HashMap which creates an empty entry fro a key whenever it is accessed over HashMap.get(java.lang.Object).
Since:
0.1
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
    SupplyingMap​(java.util.function.Function<K,​V> entrySupplier)
    Creates a SupplyingMap which generates empty entries when accessing them using the passed Function.
  • Method Summary

    Modifier and Type Method Description
    V get​(java.lang.Object key)
    Returns the value associated with the given key or generates an empty entry, associates it with the key and returns it.
    java.util.function.Function<K,​V> getEntrySupplier()
    Returns the Function used for generating new empty entries.

    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

    • SupplyingMap

      public SupplyingMap​(java.util.function.Function<K,​V> entrySupplier)
      Creates a SupplyingMap which generates empty entries when accessing them using the passed Function.
      Parameters:
      entrySupplier - The supplier for generating new empty entries. Its input is the key to generate an empty entry for.
  • Method Details

    • get

      public V get​(java.lang.Object key)
      Returns the value associated with the given key or generates an empty entry, associates it with the key and returns it. This method returns null if and only if the Function for generating empty entries returns null.
      Specified by:
      get in interface java.util.Map<K,​V>
      Overrides:
      get in class java.util.HashMap<K,​V>
      Parameters:
      key - The key to get an associated value for.
      Returns:
      The value assocated with the given key.
      Throws:
      java.lang.ClassCastException - Thrown only if no value is associated with the key and the key is not of type SupplyingMap.
      See Also:
      getEntrySupplier(), HashMap.get(java.lang.Object), HashMap.containsKey(java.lang.Object)
    • getEntrySupplier

      public java.util.function.Function<K,​V> getEntrySupplier()
      Returns the Function used for generating new empty entries.
      Returns:
      The Function used for generating new empty entries. Its input is the key to generate an empty entry for.I