Class LazyBindings
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<java.lang.String,java.lang.Object>
-
- org.apache.sling.api.scripting.LazyBindings
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.util.Map<java.lang.String,java.lang.Object>
,javax.script.Bindings
- Direct Known Subclasses:
SlingBindings
@ConsumerType public class LazyBindings extends java.util.HashMap<java.lang.String,java.lang.Object> implements javax.script.Bindings
The
LazyBindings
wraps another map and dynamically provides entries for the wrapped map through a map ofLazyBindings.Supplier
s.When
get(Object)
is called with akey
that's not present in the wrapped map, then theLazyBindings.Supplier
s 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.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 theLazyBindings.Supplier
s and the wrapped map, so that copies to otherLazyBindings
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 throughCollections.synchronizedMap(Map)
.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
LazyBindings.Supplier
This marker interface should be used for suppliers which should be unwrapped when used as values stored in aLazyBindings
map.
-
Constructor Summary
Constructors Constructor Description LazyBindings()
LazyBindings(java.util.Map<java.lang.String,LazyBindings.Supplier> suppliers)
LazyBindings(java.util.Map<java.lang.String,LazyBindings.Supplier> suppliers, java.util.Map<java.lang.String,java.lang.Object> wrapped)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(java.lang.Object key)
@NotNull java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>>
entrySet()
boolean
equals(java.lang.Object o)
java.lang.Object
get(java.lang.Object key)
java.lang.Object
getOrDefault(java.lang.Object key, java.lang.Object defaultValue)
int
hashCode()
boolean
isEmpty()
@NotNull java.util.Set<java.lang.String>
keySet()
java.lang.Object
put(java.lang.String key, java.lang.Object value)
void
putAll(java.util.Map<? extends java.lang.String,?> toMerge)
java.lang.Object
remove(java.lang.Object key)
int
size()
@NotNull java.util.Collection<java.lang.Object>
values()
-
-
-
Constructor Detail
-
LazyBindings
public LazyBindings()
-
LazyBindings
public LazyBindings(java.util.Map<java.lang.String,LazyBindings.Supplier> suppliers)
-
LazyBindings
public LazyBindings(java.util.Map<java.lang.String,LazyBindings.Supplier> suppliers, java.util.Map<java.lang.String,java.lang.Object> wrapped)
-
-
Method Detail
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object value)
- Specified by:
put
in interfacejavax.script.Bindings
- Specified by:
put
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
put
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
putAll
public void putAll(java.util.Map<? extends java.lang.String,?> toMerge)
- Specified by:
putAll
in interfacejavax.script.Bindings
- Specified by:
putAll
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
putAll
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
clear
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
keySet
@NotNull public @NotNull java.util.Set<java.lang.String> keySet()
- Specified by:
keySet
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
keySet
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
values
@NotNull public @NotNull java.util.Collection<java.lang.Object> values()
- Specified by:
values
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
values
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
entrySet
@NotNull public @NotNull java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
- Specified by:
entrySet
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
entrySet
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
size
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
isEmpty
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
containsKey
public boolean containsKey(java.lang.Object key)
- Specified by:
containsKey
in interfacejavax.script.Bindings
- Specified by:
containsKey
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
containsKey
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
get
in interfacejavax.script.Bindings
- Specified by:
get
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
get
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
remove
in interfacejavax.script.Bindings
- Specified by:
remove
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
remove
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
equals
in classjava.util.AbstractMap<java.lang.String,java.lang.Object>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
hashCode
in classjava.util.AbstractMap<java.lang.String,java.lang.Object>
-
getOrDefault
public java.lang.Object getOrDefault(java.lang.Object key, java.lang.Object defaultValue)
- Specified by:
getOrDefault
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
getOrDefault
in classjava.util.HashMap<java.lang.String,java.lang.Object>
-
-