Class NullSkippingHashMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
io.github.connellite.collections.NullSkippingHashMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>

public class NullSkippingHashMap<K,V> extends HashMap<K,V>
HashMap that ignores put / putAll / putIfAbsent / merge when the key is null (no-op; null values are still stored).
See Also:
  • Constructor Details

    • NullSkippingHashMap

      public NullSkippingHashMap()
    • NullSkippingHashMap

      public NullSkippingHashMap(int initialCapacity)
    • NullSkippingHashMap

      public NullSkippingHashMap(int initialCapacity, float loadFactor)
    • NullSkippingHashMap

      public NullSkippingHashMap(Map<? extends K,? extends V> m)
  • Method Details

    • put

      public V put(K key, V value)
      Associates value with a non-null key.
      Specified by:
      put in interface Map<K,V>
      Overrides:
      put in class HashMap<K,V>
      Parameters:
      key - map key
      value - map value
      Returns:
      previous value, or current null-key value when key is null
    • putAll

      public void putAll(Map<? extends K,? extends V> m)
      Copies all entries with non-null keys from the input map.
      Specified by:
      putAll in interface Map<K,V>
      Overrides:
      putAll in class HashMap<K,V>
      Parameters:
      m - source map
    • putIfAbsent

      public V putIfAbsent(K key, V value)
      Stores value for a non-null key only when absent.
      Specified by:
      putIfAbsent in interface Map<K,V>
      Overrides:
      putIfAbsent in class HashMap<K,V>
      Parameters:
      key - map key
      value - map value
      Returns:
      existing value or null
    • merge

      public V merge(K key, V value, BiFunction<? super V,? super V,? extends V> remappingFunction)
      Merges value for a non-null key.
      Specified by:
      merge in interface Map<K,V>
      Overrides:
      merge in class HashMap<K,V>
      Parameters:
      key - map key
      value - value to merge
      remappingFunction - merge callback
      Returns:
      merged value, or current null-key value when key is null