Decorates another Map returning a default value if the map
does not contain the requested key.
When the get(Object) method is called with a key that does not
exist in the map, this map will return the default value specified in
the constructor/factory. Only the get method is altered, so the
containsKey(Object) can be used to determine if a key really
is in the map or not.
The defaulted value is not added to the map.
Compare this behaviour with LazyMap , which does add the value
to the map (via a Transformer).
After the above code is executed the map is still empty.
Note that DefaultedMap is not synchronized and is not thread-safe.
If you wish to use this map from multiple threads concurrently, you must use
appropriate synchronization. The simplest approach is to wrap this map
using synchronizedMap(Map) . This class may throw
exceptions when accessed by concurrent threads without synchronization.
Mapreturning a default value if the map does not contain the requested key.When the get(Object) method is called with a key that does not exist in the map, this map will return the default value specified in the constructor/factory. Only the get method is altered, so the containsKey(Object) can be used to determine if a key really is in the map or not.
The defaulted value is not added to the map. Compare this behaviour with LazyMap , which does add the value to the map (via a Transformer).
For instance:
Map map = new DefaultedMap("NULL"); Object obj = map.get("Surname"); // obj == "NULL"After the above code is executed the map is still empty.Note that DefaultedMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. The simplest approach is to wrap this map using synchronizedMap(Map) . This class may throw exceptions when accessed by concurrent threads without synchronization.