ExtensionContext.Store
@API(status=INTERNAL, since="5.0") public class NamespaceAwareStore extends java.lang.Object implements ExtensionContext.Store
ExtensionContext.Store.CloseableResource
Constructor | Description |
---|---|
NamespaceAwareStore(ExtensionValuesStore valuesStore,
ExtensionContext.Namespace namespace) |
Modifier and Type | Method | Description |
---|---|---|
java.lang.Object |
get(java.lang.Object key) |
Get the value that is stored under the supplied
key . |
<T> T |
get(java.lang.Object key,
java.lang.Class<T> requiredType) |
Get the value of the specified required type that is stored under
the supplied
key . |
<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 . |
<T> T |
remove(java.lang.Object key,
java.lang.Class<T> requiredType) |
Remove the value of the specified required type that was previously stored
under the supplied
key . |
getOrComputeIfAbsent
public NamespaceAwareStore(ExtensionValuesStore valuesStore, ExtensionContext.Namespace namespace)
public java.lang.Object get(java.lang.Object key)
ExtensionContext.Store
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 ExtensionContext.Store.get(Object, Class)
instead.
get
in interface ExtensionContext.Store
key
- the key; never null
null
ExtensionContext.Store.get(Object, Class)
public <T> T get(java.lang.Object key, java.lang.Class<T> requiredType)
ExtensionContext.Store
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.
get
in interface ExtensionContext.Store
T
- the value typekey
- the key; never null
requiredType
- the required type of the value; never null
null
ExtensionContext.Store.get(Object)
public <K,V> java.lang.Object getOrComputeIfAbsent(K key, java.util.function.Function<K,V> defaultCreator)
ExtensionContext.Store
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
ExtensionContext.Store.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.
getOrComputeIfAbsent
in interface ExtensionContext.Store
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
ExtensionContext.Store.getOrComputeIfAbsent(Class)
,
ExtensionContext.Store.getOrComputeIfAbsent(Object, Function, Class)
,
ExtensionContext.Store.CloseableResource
public <K,V> V getOrComputeIfAbsent(K key, java.util.function.Function<K,V> defaultCreator, java.lang.Class<V> requiredType)
ExtensionContext.Store
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.
getOrComputeIfAbsent
in interface ExtensionContext.Store
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
ExtensionContext.Store.getOrComputeIfAbsent(Class)
,
ExtensionContext.Store.getOrComputeIfAbsent(Object, Function)
,
ExtensionContext.Store.CloseableResource
public void put(java.lang.Object key, java.lang.Object value)
ExtensionContext.Store
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.
put
in interface ExtensionContext.Store
key
- the key under which the value should be stored; never
null
value
- the value to store; may be null
ExtensionContext.Store.CloseableResource
public java.lang.Object remove(java.lang.Object key)
ExtensionContext.Store
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 ExtensionContext.Store.remove(Object, Class)
instead.
remove
in interface ExtensionContext.Store
key
- the key; never null
null
if no value was present
for the specified keyExtensionContext.Store.remove(Object, Class)
public <T> T remove(java.lang.Object key, java.lang.Class<T> requiredType)
ExtensionContext.Store
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.
remove
in interface ExtensionContext.Store
T
- 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 keyExtensionContext.Store.remove(Object)