NamespaceAwareStore
public static interface ExtensionContext.Store
Store
provides methods for extensions to save and retrieve data.Modifier and Type | Method | Description |
---|---|---|
java.lang.Object |
get(java.lang.Object key) |
Get the value that is stored under the supplied
key . |
<V> V |
get(java.lang.Object key,
java.lang.Class<V> requiredType) |
Get the value of the specified required type that is stored under
the supplied
key . |
default <V> V |
getOrComputeIfAbsent(java.lang.Class<V> type) |
Get the object of type
type that is present in this
Store (keyed by type ); and otherwise invoke
the default constructor for type to generate the object,
store it, and return it. |
<K,V> java.lang.Object |
getOrComputeIfAbsent(K key,
java.util.function.Function<K,V> defaultCreator) |
Get the value that is stored under the supplied
key . |
<K,V> V |
getOrComputeIfAbsent(K key,
java.util.function.Function<K,V> defaultCreator,
java.lang.Class<V> requiredType) |
Get the value of the specified required type that is stored under the
supplied
key . |
void |
put(java.lang.Object key,
java.lang.Object value) |
Store a
value for later retrieval under the supplied key . |
java.lang.Object |
remove(java.lang.Object key) |
Remove the value that was previously stored under the supplied
key . |
<V> V |
remove(java.lang.Object key,
java.lang.Class<V> requiredType) |
Remove the value of the specified required type that was previously stored
under the supplied
key . |
java.lang.Object get(java.lang.Object key)
key
.
If no value is stored in the current ExtensionContext
for the supplied key
, ancestors of the context will be queried
for a value with the same key
in the Namespace
used
to create this store.
For greater type safety, consider using get(Object, Class)
instead.
key
- the key; never null
null
get(Object, Class)
<V> V get(java.lang.Object key, java.lang.Class<V> requiredType)
key
.
If no value is stored in the current ExtensionContext
for the supplied key
, ancestors of the context will be queried
for a value with the same key
in the Namespace
used
to create this store.
V
- the value typekey
- the key; never null
requiredType
- the required type of the value; never null
null
get(Object)
default <V> V getOrComputeIfAbsent(java.lang.Class<V> type)
type
that is present in this
Store
(keyed by type
); and otherwise invoke
the default constructor for type
to generate the object,
store it, and return it.
This method is a shortcut for the following, where X
is
the type of object we wish to retrieve from the store.
X x = store.getOrComputeIfAbsent(X.class, key -> new X(), X.class); // Equivalent to: // X x = store.getOrComputeIfAbsent(X.class);
See getOrComputeIfAbsent(Object, Function, Class)
for
further details.
V
- the key and value typetype
- the type of object to retrieve; never null
null
getOrComputeIfAbsent(Object, Function)
,
getOrComputeIfAbsent(Object, Function, Class)
<K,V> java.lang.Object getOrComputeIfAbsent(K key, java.util.function.Function<K,V> defaultCreator)
key
.
If no value is stored in the current ExtensionContext
for the supplied key
, ancestors of the context will be queried
for a value with the same key
in the Namespace
used
to create this store. If no value is found for the supplied key
,
a new value will be computed by the defaultCreator
(given
the key
as input), stored, and returned.
For greater type safety, consider using
getOrComputeIfAbsent(Object, Function, Class)
instead.
K
- the key typeV
- the value typekey
- the key; never null
defaultCreator
- the function called with the supplied key
to create a new value; never null
null
getOrComputeIfAbsent(Class)
,
getOrComputeIfAbsent(Object, Function, Class)
<K,V> V getOrComputeIfAbsent(K key, java.util.function.Function<K,V> defaultCreator, java.lang.Class<V> requiredType)
key
.
If no value is stored in the current ExtensionContext
for the supplied key
, ancestors of the context will be queried
for a value with the same key
in the Namespace
used
to create this store. If no value is found for the supplied key
,
a new value will be computed by the defaultCreator
(given
the key
as input), stored, and returned.
K
- the key typeV
- the value typekey
- the key; never null
defaultCreator
- the function called with the supplied key
to create a new value; never null
requiredType
- the required type of the value; never null
null
getOrComputeIfAbsent(Class)
,
getOrComputeIfAbsent(Object, Function)
void put(java.lang.Object key, java.lang.Object value)
value
for later retrieval under the supplied key
.
A stored value
is visible in child ExtensionContexts
for the store's Namespace
unless they
overwrite it.
key
- the key under which the value should be stored; never
null
value
- the value to store; may be null
java.lang.Object remove(java.lang.Object key)
key
.
The value will only be removed in the current ExtensionContext
,
not in ancestors.
For greater type safety, consider using remove(Object, Class)
instead.
key
- the key; never null
null
if no value was present
for the specified keyremove(Object, Class)
<V> V remove(java.lang.Object key, java.lang.Class<V> requiredType)
key
.
The value will only be removed in the current ExtensionContext
,
not in ancestors.
V
- the value typekey
- the key; never null
requiredType
- the required type of the value; never null
null
if no value was present
for the specified keyremove(Object)