Package htsjdk.samtools.util
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
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:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionDefaultingMap
(CollectionUtil.DefaultingMap.Factory<V, K> defaultGenerator, boolean injectValueOnDefaulting) Creates a defaulting map that generates defaults from the provided factory.DefaultingMap
(V defaultValue) Creates a defaulting map which defaults to the provided value and with injecting-on-default disabled. -
Method Summary
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
-
Constructor Details
-
DefaultingMap
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