@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 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)
.
Modifier and Type | Class and Description |
---|---|
static interface |
LazyBindings.Supplier
This marker interface should be used for suppliers which should be unwrapped when used as values stored in a
LazyBindings map. |
Constructor and 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) |
Modifier and Type | Method and 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() |
clone, compute, computeIfAbsent, computeIfPresent, containsValue, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
public LazyBindings()
public LazyBindings(java.util.Map<java.lang.String,LazyBindings.Supplier> suppliers)
public LazyBindings(java.util.Map<java.lang.String,LazyBindings.Supplier> suppliers, java.util.Map<java.lang.String,java.lang.Object> wrapped)
public java.lang.Object put(java.lang.String key, java.lang.Object value)
put
in interface java.util.Map<java.lang.String,java.lang.Object>
put
in interface javax.script.Bindings
put
in class java.util.HashMap<java.lang.String,java.lang.Object>
public void putAll(java.util.Map<? extends java.lang.String,?> toMerge)
putAll
in interface java.util.Map<java.lang.String,java.lang.Object>
putAll
in interface javax.script.Bindings
putAll
in class java.util.HashMap<java.lang.String,java.lang.Object>
public void clear()
clear
in interface java.util.Map<java.lang.String,java.lang.Object>
clear
in class java.util.HashMap<java.lang.String,java.lang.Object>
@NotNull public @NotNull java.util.Set<java.lang.String> keySet()
keySet
in interface java.util.Map<java.lang.String,java.lang.Object>
keySet
in class java.util.HashMap<java.lang.String,java.lang.Object>
@NotNull public @NotNull java.util.Collection<java.lang.Object> values()
values
in interface java.util.Map<java.lang.String,java.lang.Object>
values
in class java.util.HashMap<java.lang.String,java.lang.Object>
@NotNull public @NotNull java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
entrySet
in interface java.util.Map<java.lang.String,java.lang.Object>
entrySet
in class java.util.HashMap<java.lang.String,java.lang.Object>
public int size()
size
in interface java.util.Map<java.lang.String,java.lang.Object>
size
in class java.util.HashMap<java.lang.String,java.lang.Object>
public boolean isEmpty()
isEmpty
in interface java.util.Map<java.lang.String,java.lang.Object>
isEmpty
in class java.util.HashMap<java.lang.String,java.lang.Object>
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<java.lang.String,java.lang.Object>
containsKey
in interface javax.script.Bindings
containsKey
in class java.util.HashMap<java.lang.String,java.lang.Object>
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map<java.lang.String,java.lang.Object>
get
in interface javax.script.Bindings
get
in class java.util.HashMap<java.lang.String,java.lang.Object>
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map<java.lang.String,java.lang.Object>
remove
in interface javax.script.Bindings
remove
in class java.util.HashMap<java.lang.String,java.lang.Object>
public boolean equals(java.lang.Object o)
equals
in interface java.util.Map<java.lang.String,java.lang.Object>
equals
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
public int hashCode()
hashCode
in interface java.util.Map<java.lang.String,java.lang.Object>
hashCode
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
public java.lang.Object getOrDefault(java.lang.Object key, java.lang.Object defaultValue)
getOrDefault
in interface java.util.Map<java.lang.String,java.lang.Object>
getOrDefault
in class java.util.HashMap<java.lang.String,java.lang.Object>
Copyright © 2022 The Apache Software Foundation. All rights reserved.