Class LazyBindings
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,Object>
-
- org.apache.sling.api.scripting.LazyBindings
-
- Direct Known Subclasses:
SlingBindings
@ConsumerType public class LazyBindings extends HashMap<String,Object> implements Bindings
The
LazyBindingswraps another map and dynamically provides entries for the wrapped map through a map ofLazyBindings.Suppliers.When
get(Object)is called with akeythat's not present in the wrapped map, then theLazyBindings.Suppliers map will be queried and, if an entry exists for that key, theLazyBindings.Supplier-generated value will be used to populate the wrapped map.While the
keySet()andcontainsKey(Object)will also check the keys present in theLazyBindings.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 theLazyBindings.Suppliers and the wrapped map, so that copies to otherLazyBindingsmaps preserve the functionality of having lazily-evaluated bindings.This class does not provide any thread-safety guarantees. If
thisBindingsmap 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 throughCollections.synchronizedMap(Map).- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceLazyBindings.SupplierThis 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
Constructors Constructor Description LazyBindings()LazyBindings(Map<String,LazyBindings.Supplier> suppliers)LazyBindings(Map<String,LazyBindings.Supplier> suppliers, Map<String,Object> wrapped)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()booleancontainsKey(Object key)@NotNull Set<Map.Entry<String,Object>>entrySet()booleanequals(Object o)Objectget(Object key)ObjectgetOrDefault(Object key, Object defaultValue)inthashCode()booleanisEmpty()@NotNull Set<String>keySet()Objectput(String key, Object value)voidputAll(Map<? extends String,?> toMerge)Objectremove(Object key)intsize()@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 Detail
-
LazyBindings
public LazyBindings()
-
LazyBindings
public LazyBindings(Map<String,LazyBindings.Supplier> suppliers)
-
-
Method Detail
-
clear
public void clear()
-
values
@NotNull public @NotNull Collection<Object> values()
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceBindings- Specified by:
containsKeyin interfaceMap<String,Object>- Overrides:
containsKeyin classHashMap<String,Object>
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
-