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()
Returns the backing delegate instance that methods are forwarded to.
|
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)
protected Map<K,V> delegate()
ForwardingObject
ForwardingSet.delegate()
. Concrete subclasses override this method to supply
the instance being decorated.delegate
in class ForwardingMap<K,V>
Copyright © 2013 Seam Framework. All Rights Reserved.