Class LazyBindings
- Direct Known Subclasses:
ProtectedBindings,SlingBindings
The LazyBindings wraps another map and dynamically provides entries for the wrapped map through a map of LazyBindings.Suppliers.
When get(Object) is called with a key that's not present in the wrapped map, then the LazyBindings.Suppliers map
will be queried and, if an entry exists for that key, the LazyBindings.Supplier-generated value will be used to populate the
wrapped map.
While the keySet() and containsKey(Object) will also check the keys present in the LazyBindings.Suppliers map,
all other methods (e.g. values(), HashMap.containsValue(Object)) will only deal with the contents of the wrapped map.
entrySet() will however return a merged view of both the LazyBindings.Suppliers and the wrapped map, so that copies to
other LazyBindings maps preserve the functionality of having lazily-evaluated bindings.
This class does not provide any thread-safety guarantees. If this Bindings map needs to be used in a concurrent
setup it's the responsibility of the caller to synchronize access. The simplest way would be to wrap it through Collections.synchronizedMap(Map).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis marker interface should be used for suppliers which should be unwrapped when used as values stored in aLazyBindingsmap.Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionLazyBindings(Map<String, LazyBindings.Supplier> suppliers) LazyBindings(Map<String, LazyBindings.Supplier> suppliers, Map<String, Object> wrapped) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key) entrySet()booleangetOrDefault(Object key, Object defaultValue) inthashCode()booleanisEmpty()keySet()voidintsize()@NotNull Collection<Object>values()Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsValue, forEach, merge, putIfAbsent, remove, replace, replace, replaceAllMethods inherited from class java.util.AbstractMap
toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsValue, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
LazyBindings
public LazyBindings() -
LazyBindings
-
LazyBindings
-
-
Method Details
-
put
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceBindings- Specified by:
containsKeyin interfaceMap<String,Object> - Overrides:
containsKeyin classHashMap<String,Object>
-
get
-
remove
-
equals
-
hashCode
public int hashCode() -
getOrDefault
- Specified by:
getOrDefaultin interfaceMap<String,Object> - Overrides:
getOrDefaultin classHashMap<String,Object>
-