Package org.linkki.util
Class LazyInitializingMap<K,V>
java.lang.Object
org.linkki.util.LazyInitializingMap<K,V>
- Type Parameters:
K- the type of key stored in this mapV- the type of values stored in this map
Key-value store that initializes its values lazily. Values will be initialized using the
initializer function the
map is created with.-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
LazyInitializingMap
- Parameters:
initializer- the initializer function for lazily creating values. This function throws aNullPointerExceptionwhen givennull. Returns non-nullvalues otherwise.
-
-
Method Details
-
get
Returns the value the given key maps to. Creates a new value if none is present using this map's initializer. Never returnsnull.Use as replacement for the usual "get or initialize and get" code:
if (!contains(key)) { initValue(key); } return get(key);- Throws:
NullPointerException- if either the key isnull, or if the initializer function violates its contract and returnsnull.
-
getIfPresent
Returns the value the given key maps to. Returnsnullif the key does not map to a value. -
clear
public void clear()Clears this map. -
remove
Removes the key from the map. Returns the removed value ornullif the key does not map to a value.- See Also:
-