K
- V
- public class DefaultValueMap<K,V> extends ForwardingMap<K,V>
Map
that provides default values. When the get(Object)
method is invoked and the underlying
map does not contain the given key, the default value is stored in the map under the given key. The new value is then
returned from the methods.
This class is not thread-safe and needs to be externally synchronized. It is not thread safe even if the delegate map is.
The semantics of ForwardingMap.keySet()
, ForwardingMap.containsKey(Object)
, ForwardingMap.containsValue(Object)
and ForwardingMap.values()
are
not modified by this wrapper.ForwardingMap.StandardEntrySet, ForwardingMap.StandardKeySet, ForwardingMap.StandardValues
Modifier and Type | Method and Description |
---|---|
protected Map<K,V> |
delegate() |
V |
get(Object key) |
static <K,V> DefaultValueMap<K,V> |
hashMapWithDefaultValue(Supplier<V> defaultValueSupplier) |
static <K,V> DefaultValueMap<K,V> |
of(Map<K,V> delegate,
Supplier<V> defaultValueSupplier) |
clear, containsKey, containsValue, entrySet, equals, hashCode, isEmpty, keySet, put, putAll, remove, size, standardClear, standardContainsKey, standardContainsValue, standardEquals, standardHashCode, standardIsEmpty, standardPutAll, standardRemove, standardToString, values
toString
public static <K,V> DefaultValueMap<K,V> of(Map<K,V> delegate, Supplier<V> defaultValueSupplier)
public static <K,V> DefaultValueMap<K,V> hashMapWithDefaultValue(Supplier<V> defaultValueSupplier)
Copyright © 2013 Seam Framework. All Rights Reserved.