Class CollectionUtil.DefaultingMap<K,V>

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
htsjdk.samtools.util.CollectionUtil.DefaultingMap<K,V>
Type Parameters:
K -
V -
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>
Enclosing class:
CollectionUtil

public static class CollectionUtil.DefaultingMap<K,V> extends HashMap<K,V>
A defaulting map, which returns a default value when a value that does not exist in the map is looked up. This map supports two modes: injecting-on-default, and not injecting-on-default. When injecting on default, when a lookup is performed and a default value is returned, the default value is injected at that key, so that it now lives in the underlying map. Without this mode, the value is simply returned and the underlying map is unaffected. Note: When using injecting-on-default mode, and performing a lookup with a non-key type (the get method accepts any object), a class cast exception will be thrown because a non-key type cannot be added to the map.
See Also:
  • Constructor Details

    • DefaultingMap

      public DefaultingMap(V defaultValue)
      Creates a defaulting map which defaults to the provided value and with injecting-on-default disabled.
    • DefaultingMap

      public DefaultingMap(CollectionUtil.DefaultingMap.Factory<V,K> defaultGenerator, boolean injectValueOnDefaulting)
      Creates a defaulting map that generates defaults from the provided factory. This is useful when the default is non-static, or the default is mutable, and the client wishes to get a value and mutate it and persist those changes in the map.
  • Method Details