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`

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:
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static interface`
`CollectionUtil.DefaultingMap.Factory<V,K>`

## Nested classes/interfaces inherited from class java.util.AbstractMap

`AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>`

## Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<K,V>`

## Constructor Summary

Constructors
Constructor
Description
`DefaultingMap(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

Modifier and Type
Method
Description
`V`
`get(Object key)`

### Methods inherited from class java.util.HashMap

`clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, getOrDefault, isEmpty, keySet, merge, newHashMap, 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

### 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

### get

public V get(Object key)

Specified by:
  `get` in interface `Map<K,V>`
Overrides:
  `get` in class `HashMap<K,V>`