public static interface ExtensionContext.Store
Store provides methods for extensions to save and retrieve data.| Modifier and Type | Interface and Description |
|---|---|
static interface |
ExtensionContext.Store.CloseableResource
Classes implementing this interface indicate that they want to
ExtensionContext.Store.CloseableResource.close()
some underlying resource or resources when the enclosing Store
is closed. |
| Modifier and Type | Method and Description |
|---|---|
Object |
get(Object key)
Get the value that is stored under the supplied
key. |
<V> V |
get(Object key,
Class<V> requiredType)
Get the value of the specified required type that is stored under
the supplied
key. |
default <V> V |
getOrComputeIfAbsent(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> Object |
getOrComputeIfAbsent(K key,
Function<K,V> defaultCreator)
Get the value that is stored under the supplied
key. |
<K,V> V |
getOrComputeIfAbsent(K key,
Function<K,V> defaultCreator,
Class<V> requiredType)
Get the value of the specified required type that is stored under the
supplied
key. |
void |
put(Object key,
Object value)
Store a
value for later retrieval under the supplied key. |
Object |
remove(Object key)
Remove the value that was previously stored under the supplied
key. |
<V> V |
remove(Object key,
Class<V> requiredType)
Remove the value of the specified required type that was previously stored
under the supplied
key. |
Object get(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 nullnullget(Object, Class)<V> V get(Object key, 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 nullrequiredType - the required type of the value; never nullnullget(Object)@API(status=STABLE,
since="5.1")
default <V> V getOrComputeIfAbsent(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.
If type implements ExtensionContext.Store.CloseableResource
the close() method will be invoked on the stored object when
the store is closed.
V - the key and value typetype - the type of object to retrieve; never nullnullgetOrComputeIfAbsent(Object, Function),
getOrComputeIfAbsent(Object, Function, Class),
ExtensionContext.Store.CloseableResource<K,V> Object getOrComputeIfAbsent(K key, 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.
If the created value is an instance of ExtensionContext.Store.CloseableResource
the close() method will be invoked on the stored object when
the store is closed.
K - the key typeV - the value typekey - the key; never nulldefaultCreator - the function called with the supplied key
to create a new value; never nullnullgetOrComputeIfAbsent(Class),
getOrComputeIfAbsent(Object, Function, Class),
ExtensionContext.Store.CloseableResource<K,V> V getOrComputeIfAbsent(K key,
Function<K,V> defaultCreator,
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.
If requiredType implements ExtensionContext.Store.CloseableResource
the close() method will be invoked on the stored object when
the store is closed.
K - the key typeV - the value typekey - the key; never nulldefaultCreator - the function called with the supplied key
to create a new value; never nullrequiredType - the required type of the value; never nullnullgetOrComputeIfAbsent(Class),
getOrComputeIfAbsent(Object, Function),
ExtensionContext.Store.CloseableResourcevoid put(Object key, 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.
If the value is an instance of ExtensionContext.Store.CloseableResource
the close() method will be invoked on the stored object when
the store is closed.
key - the key under which the value should be stored; never
nullvalue - the value to store; may be nullExtensionContext.Store.CloseableResourceObject remove(Object key)
key.
The value will only be removed in the current ExtensionContext,
not in ancestors. In addition, the ExtensionContext.Store.CloseableResource API will not
be honored for values that are manually removed via this method.
For greater type safety, consider using remove(Object, Class)
instead.
key - the key; never nullnull if no value was present
for the specified keyremove(Object, Class)<V> V remove(Object key, Class<V> requiredType)
key.
The value will only be removed in the current ExtensionContext,
not in ancestors. In addition, the ExtensionContext.Store.CloseableResource API will not
be honored for values that are manually removed via this method.
V - the value typekey - the key; never nullrequiredType - the required type of the value; never nullnull if no value was present
for the specified keyremove(Object)Copyright © 2024. All rights reserved.