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.Supplier
s.
When get(Object)
is called with a key
that's not present in the wrapped map, then the LazyBindings.Supplier
s 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.Supplier
s 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.Supplier
s 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 interface
This marker interface should be used for suppliers which should be unwrapped when used as values stored in aLazyBindings
map.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 TypeMethodDescriptionvoid
clear()
boolean
containsKey
(Object key) entrySet()
boolean
getOrDefault
(Object key, Object defaultValue) int
hashCode()
boolean
isEmpty()
keySet()
void
int
size()
@NotNull Collection<Object>
values()
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsValue, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
Methods inherited from class java.util.AbstractMap
toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods 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:
containsKey
in interfaceBindings
- Specified by:
containsKey
in interfaceMap<String,
Object> - Overrides:
containsKey
in classHashMap<String,
Object>
-
get
-
remove
-
equals
-
hashCode
public int hashCode() -
getOrDefault
- Specified by:
getOrDefault
in interfaceMap<String,
Object> - Overrides:
getOrDefault
in classHashMap<String,
Object>
-