Class NamespaceAwareStore
- java.lang.Object
-
- org.junit.jupiter.engine.execution.NamespaceAwareStore
-
- All Implemented Interfaces:
ExtensionContext.Store
@API(status=INTERNAL, since="5.0") public class NamespaceAwareStore extends Object implements ExtensionContext.Store
- Since:
- 5.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.ExtensionContext.Store
ExtensionContext.Store.CloseableResource
-
-
Constructor Summary
Constructors Constructor Description NamespaceAwareStore(ExtensionValuesStore valuesStore, ExtensionContext.Namespace namespace)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
get(Object key)
Get the value that is stored under the suppliedkey
.<T> T
get(Object key, Class<T> requiredType)
Get the value of the specified required type that is stored under the suppliedkey
.<K,V>
ObjectgetOrComputeIfAbsent(K key, Function<K,V> defaultCreator)
Get the value that is stored under the suppliedkey
.<K,V>
VgetOrComputeIfAbsent(K key, Function<K,V> defaultCreator, Class<V> requiredType)
Get the value of the specified required type that is stored under the suppliedkey
.void
put(Object key, Object value)
Store avalue
for later retrieval under the suppliedkey
.Object
remove(Object key)
Remove the value that was previously stored under the suppliedkey
.<T> T
remove(Object key, Class<T> requiredType)
Remove the value of the specified required type that was previously stored under the suppliedkey
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.junit.jupiter.api.extension.ExtensionContext.Store
getOrComputeIfAbsent, getOrDefault
-
-
-
-
Constructor Detail
-
NamespaceAwareStore
public NamespaceAwareStore(ExtensionValuesStore valuesStore, ExtensionContext.Namespace namespace)
-
-
Method Detail
-
get
public Object get(Object key)
Description copied from interface:ExtensionContext.Store
Get the value that is stored under the suppliedkey
.If no value is stored in the current
ExtensionContext
for the suppliedkey
, ancestors of the context will be queried for a value with the samekey
in theNamespace
used to create this store.For greater type safety, consider using
ExtensionContext.Store.get(Object, Class)
instead.- Specified by:
get
in interfaceExtensionContext.Store
- Parameters:
key
- the key; nevernull
- Returns:
- the value; potentially
null
- See Also:
ExtensionContext.Store.get(Object, Class)
,ExtensionContext.Store.getOrDefault(Object, Class, Object)
-
get
public <T> T get(Object key, Class<T> requiredType)
Description copied from interface:ExtensionContext.Store
Get the value of the specified required type that is stored under the suppliedkey
.If no value is stored in the current
ExtensionContext
for the suppliedkey
, ancestors of the context will be queried for a value with the samekey
in theNamespace
used to create this store.- Specified by:
get
in interfaceExtensionContext.Store
- Type Parameters:
T
- the value type- Parameters:
key
- the key; nevernull
requiredType
- the required type of the value; nevernull
- Returns:
- the value; potentially
null
- See Also:
ExtensionContext.Store.get(Object)
,ExtensionContext.Store.getOrDefault(Object, Class, Object)
-
getOrComputeIfAbsent
public <K,V> Object getOrComputeIfAbsent(K key, Function<K,V> defaultCreator)
Description copied from interface:ExtensionContext.Store
Get the value that is stored under the suppliedkey
.If no value is stored in the current
ExtensionContext
for the suppliedkey
, ancestors of the context will be queried for a value with the samekey
in theNamespace
used to create this store. If no value is found for the suppliedkey
, a new value will be computed by thedefaultCreator
(given thekey
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
theclose()
method will be invoked on the stored object when the store is closed.- Specified by:
getOrComputeIfAbsent
in interfaceExtensionContext.Store
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
key
- the key; nevernull
defaultCreator
- the function called with the suppliedkey
to create a new value; nevernull
- Returns:
- the value; potentially
null
- See Also:
ExtensionContext.Store.getOrComputeIfAbsent(Class)
,ExtensionContext.Store.getOrComputeIfAbsent(Object, Function, Class)
,ExtensionContext.Store.CloseableResource
-
getOrComputeIfAbsent
public <K,V> V getOrComputeIfAbsent(K key, Function<K,V> defaultCreator, Class<V> requiredType)
Description copied from interface:ExtensionContext.Store
Get the value of the specified required type that is stored under the suppliedkey
.If no value is stored in the current
ExtensionContext
for the suppliedkey
, ancestors of the context will be queried for a value with the samekey
in theNamespace
used to create this store. If no value is found for the suppliedkey
, a new value will be computed by thedefaultCreator
(given thekey
as input), stored, and returned.If
requiredType
implementsExtensionContext.Store.CloseableResource
theclose()
method will be invoked on the stored object when the store is closed.- Specified by:
getOrComputeIfAbsent
in interfaceExtensionContext.Store
- Type Parameters:
K
- the key typeV
- the value type- Parameters:
key
- the key; nevernull
defaultCreator
- the function called with the suppliedkey
to create a new value; nevernull
requiredType
- the required type of the value; nevernull
- Returns:
- the value; potentially
null
- See Also:
ExtensionContext.Store.getOrComputeIfAbsent(Class)
,ExtensionContext.Store.getOrComputeIfAbsent(Object, Function)
,ExtensionContext.Store.CloseableResource
-
put
public void put(Object key, Object value)
Description copied from interface:ExtensionContext.Store
Store avalue
for later retrieval under the suppliedkey
.A stored
value
is visible in childExtensionContexts
for the store'sNamespace
unless they overwrite it.If the
value
is an instance ofExtensionContext.Store.CloseableResource
theclose()
method will be invoked on the stored object when the store is closed.- Specified by:
put
in interfaceExtensionContext.Store
- Parameters:
key
- the key under which the value should be stored; nevernull
value
- the value to store; may benull
- See Also:
ExtensionContext.Store.CloseableResource
-
remove
public Object remove(Object key)
Description copied from interface:ExtensionContext.Store
Remove the value that was previously stored under the suppliedkey
.The value will only be removed in the current
ExtensionContext
, not in ancestors. In addition, theExtensionContext.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.- Specified by:
remove
in interfaceExtensionContext.Store
- Parameters:
key
- the key; nevernull
- Returns:
- the previous value or
null
if no value was present for the specified key - See Also:
ExtensionContext.Store.remove(Object, Class)
-
remove
public <T> T remove(Object key, Class<T> requiredType)
Description copied from interface:ExtensionContext.Store
Remove the value of the specified required type that was previously stored under the suppliedkey
.The value will only be removed in the current
ExtensionContext
, not in ancestors. In addition, theExtensionContext.Store.CloseableResource
API will not be honored for values that are manually removed via this method.- Specified by:
remove
in interfaceExtensionContext.Store
- Type Parameters:
T
- the value type- Parameters:
key
- the key; nevernull
requiredType
- the required type of the value; nevernull
- Returns:
- the previous value or
null
if no value was present for the specified key - See Also:
ExtensionContext.Store.remove(Object)
-
-