Class NullSkippingTreeMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
java.util.TreeMap<K,V>
io.github.connellite.collections.NullSkippingTreeMap<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, NavigableMap<K,V>, SortedMap<K,V>

public class NullSkippingTreeMap<K,V> extends TreeMap<K,V>
TreeMap that ignores put / putAll / putIfAbsent / merge when the key is null (no-op; avoids throwing on insert).
See Also:
  • Constructor Details

    • NullSkippingTreeMap

      public NullSkippingTreeMap()
    • NullSkippingTreeMap

      public NullSkippingTreeMap(Comparator<? super K> comparator)
    • NullSkippingTreeMap

      public NullSkippingTreeMap(Map<? extends K,? extends V> m)
    • NullSkippingTreeMap

      public NullSkippingTreeMap(SortedMap<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 TreeMap<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 TreeMap<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 TreeMap<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 TreeMap<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