Package org.apache.sling.api.scripting

# Class LazyBindings

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,Object>
org.apache.sling.api.scripting.LazyBindings

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `Map<String,Object>`, `Bindings`

Direct Known Subclasses:
  `SlingBindings`

@ConsumerType public class LazyBindings extends HashMap<String,Object> implements 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)`.

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 a `LazyBindings` 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>`

## Nested classes/interfaces inherited from interface java.util.Map

`Map.Entry<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

Modifier and Type
Method
Description
`void`
`clear()`
`boolean`
`containsKey(Object key)`
`@NotNull Set<Map.Entry<String,Object>>`
`entrySet()`
`boolean`
`equals(Object o)`
`Object`
`get(Object key)`
`Object`
`getOrDefault(Object key, Object defaultValue)`
`int`
`hashCode()`
`boolean`
`isEmpty()`
`@NotNull Set<String>`
`keySet()`
`Object`
`put(String key, Object value)`
`void`
`putAll(Map<? extends String,?> toMerge)`
`Object`
`remove(Object key)`
`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

public LazyBindings(Map<String,LazyBindings.Supplier> suppliers)

### LazyBindings

public LazyBindings(Map<String,LazyBindings.Supplier> suppliers, Map<String,Object> wrapped)

## Method Details

### put

public Object put(String key, Object value)

Specified by:
  `put` in interface `Bindings`
Specified by:
  `put` in interface `Map<String,Object>`
Overrides:
  `put` in class `HashMap<String,Object>`

### putAll

public void putAll(Map<? extends String,?> toMerge)

Specified by:
  `putAll` in interface `Bindings`
Specified by:
  `putAll` in interface `Map<String,Object>`
Overrides:
  `putAll` in class `HashMap<String,Object>`

### clear

public void clear()

Specified by:
  `clear` in interface `Map<String,Object>`
Overrides:
  `clear` in class `HashMap<String,Object>`

### keySet

@NotNull public @NotNull Set<String> keySet()

Specified by:
  `keySet` in interface `Map<String,Object>`
Overrides:
  `keySet` in class `HashMap<String,Object>`

### values

@NotNull public @NotNull Collection<Object> values()

Specified by:
  `values` in interface `Map<String,Object>`
Overrides:
  `values` in class `HashMap<String,Object>`

### entrySet

@NotNull public @NotNull Set<Map.Entry<String,Object>> entrySet()

Specified by:
  `entrySet` in interface `Map<String,Object>`
Overrides:
  `entrySet` in class `HashMap<String,Object>`

### size

public int size()

Specified by:
  `size` in interface `Map<String,Object>`
Overrides:
  `size` in class `HashMap<String,Object>`

### isEmpty

public boolean isEmpty()

Specified by:
  `isEmpty` in interface `Map<String,Object>`
Overrides:
  `isEmpty` in class `HashMap<String,Object>`

### containsKey

public boolean containsKey(Object key)

Specified by:
  `containsKey` in interface `Bindings`
Specified by:
  `containsKey` in interface `Map<String,Object>`
Overrides:
  `containsKey` in class `HashMap<String,Object>`

### get

public Object get(Object key)

Specified by:
  `get` in interface `Bindings`
Specified by:
  `get` in interface `Map<String,Object>`
Overrides:
  `get` in class `HashMap<String,Object>`

### remove

public Object remove(Object key)

Specified by:
  `remove` in interface `Bindings`
Specified by:
  `remove` in interface `Map<String,Object>`
Overrides:
  `remove` in class `HashMap<String,Object>`

### equals

public boolean equals(Object o)

Specified by:
  `equals` in interface `Map<String,Object>`
Overrides:
  `equals` in class `AbstractMap<String,Object>`

### hashCode

public int hashCode()

Specified by:
  `hashCode` in interface `Map<String,Object>`
Overrides:
  `hashCode` in class `AbstractMap<String,Object>`

### getOrDefault

public Object getOrDefault(Object key, Object defaultValue)

Specified by:
  `getOrDefault` in interface `Map<String,Object>`
Overrides:
  `getOrDefault` in class `HashMap<String,Object>`