Top Description Inners Fields Constructors Methods
org.junit.platform.engine.support.store

public final Class NamespacedHierarchicalStore<N>

extends Object
implements AutoCloseable
Class Inheritance
All Implemented Interfaces
java.lang.AutoCloseable
Annotations
@API
status:MAINTAINED
since:1.13.3
Type Parameters
<N>
Namespace type
Static Imports
java.util.Comparator.comparing, .Objects.requireNonNull, org.apiguardian.api.API.Status.DEPRECATED, .API.Status.EXPERIMENTAL, .API.Status.MAINTAINED, org.junit.platform.commons.util.ExceptionUtils.throwAsUncheckedException, .ReflectionUtils.getWrapperType, .ReflectionUtils.isAssignableTo

NamespacedHierarchicalStore is a hierarchical, namespaced key-value store.

Its closing behavior can be customized by passing a CloseAction to the NamespacedHierarchicalStore(NamespacedHierarchicalStore, CloseAction) constructor.

This class is thread-safe. Please note, however, that thread safety is not guaranteed while the close() method is being invoked.

Since
1.10

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
NamespacedHierarchicalStore.CloseAction<N>

Called for each successfully stored non-null value in the store when a NamespacedHierarchicalStore is closed.

private static record
private static record
private static class
NamespacedHierarchicalStore.MemoizingSupplier

Thread-safe Supplier that memoizes the result of calling its delegate and ensures it is called at most once.

private static record

Field Summary

Modifier and TypeField and Description
private final @Nullable NamespacedHierarchicalStore.CloseAction<N>
private volatile boolean
private final AtomicInteger
private final @Nullable NamespacedHierarchicalStore<N>
private final ConcurrentMap<NamespacedHierarchicalStore.CompositeKey<N>, NamespacedHierarchicalStore.StoredValue>

Constructor Summary

AccessConstructor and Description
public
NamespacedHierarchicalStore(@Nullable NamespacedHierarchicalStore<N>
the parent store to use for lookups; may be null
parentStore
)

Create a new store with the supplied parent.

public
NamespacedHierarchicalStore(@Nullable NamespacedHierarchicalStore<N>
the parent store to use for lookups; may be null
parentStore
,
@Nullable NamespacedHierarchicalStore.CloseAction<N>
the action to be called for each stored value when this store is closed; may be null
closeAction
)

Create a new store with the supplied parent and close action.

Method Summary

Modifier and TypeMethod and Description
private <T, V> T
castNonNullToRequiredType(Object key, V value, Class<T> requiredType)

private <T> @Nullable T
castToRequiredType(Object key, @Nullable Object value, Class<T> requiredType)

public void
close()

Implements java.lang.AutoCloseable.close.

If a CloseAction is configured, it will be called with all successfully stored values in reverse insertion order.

public <K, V> Object

Returns:

the stored value; never null
computeIfAbsent
(N
the namespace; never null
namespace
,
K
the key; never null
key
,
Function<? super K, ? extends V>
the function called with the supplied key to create a new value; never null and must not return null
defaultCreator
)

Return the value stored for the supplied namespace and key in this store or the parent store, if present and not null, or call the supplied function to compute it.

public <K, V> V

Returns:

the stored value; never null
computeIfAbsent
(N
the namespace; never null
namespace
,
K
the key; never null
key
,
Function<? super K, ? extends V>
the function called with the supplied key to create a new value; never null and must not return null
defaultCreator
,
Class<V>
the required type of the value; never null
requiredType
)

Return the value stored for the supplied namespace and key in this store or the parent store, if present and not null, or call the supplied function to compute it and, finally, cast it to the supplied required type.

public @Nullable Object

Returns:

the stored value; may be null
get
(N
the namespace; never null
namespace
,
Object
the key; never null
key
)

Get the value stored for the supplied namespace and key in this store or the parent store, if present.

public <T> @Nullable T

Returns:

the stored value; may be null
get
(N
the namespace; never null
namespace
,
Object
the key; never null
key
,
Class<T>
the required type of the value; never null
requiredType
)

Get the value stored for the supplied namespace and key in this store or the parent store, if present, and cast it to the supplied required type.

public <K, V extends @Nullable Object> @Nullable Object

Returns:

the stored value; may be null
getOrComputeIfAbsent
(N
the namespace; never null
namespace
,
K
the key; never null
key
,
Function<? super K, ? extends V>
the function called with the supplied key to create a new value; never null but may return null
defaultCreator
)
Deprecated since 6.0. Please use computeIfAbsent(Object, Object, Function) instead.

Get the value stored for the supplied namespace and key in this store or the parent store, if present, or call the supplied function to compute it.

public <K, V extends @Nullable Object> @Nullable V

Returns:

the stored value; may be null
getOrComputeIfAbsent
(N
the namespace; never null
namespace
,
K
the key; never null
key
,
Function<? super K, ? extends V>
the function called with the supplied key to create a new value; never null but may return null
defaultCreator
,
Class<V>
the required type of the value; never null
requiredType
)
Deprecated since 6.0. Please use computeIfAbsent(Object, Object, Function, Class) instead.

Get the value stored for the supplied namespace and key in this store or the parent store, if present, or call the supplied function to compute it and, finally, cast it to the supplied required type.

public Optional<NamespacedHierarchicalStore<N>>

Returns:

an Optional containing the parent store, or an empty Optional if there is no parent
getParent
()

Returns the parent store of this NamespacedHierarchicalStore.

private @Nullable NamespacedHierarchicalStore.StoredValue
public boolean

Returns:

true if this store has been closed
isClosed
()

Determine if this store has been closed.

public NamespacedHierarchicalStore<N>
newChild()

Create a child store with this store as its parent and this store's close action.

private NamespacedHierarchicalStore.StoredValue
public @Nullable Object

Returns:

the previously stored value; may be null
put
(N
the namespace; never null
namespace
,
Object
the key; never null
key
,
@Nullable Object
the value to store; may be null
value
)

Put the supplied value for the supplied namespace and key into this store and return the previously associated value in this store.

private void
public @Nullable Object

Returns:

the previously stored value; may be null
remove
(N
the namespace; never null
namespace
,
Object
the key; never null
key
)

Remove the value stored for the supplied namespace and key from this store.

public <T> @Nullable T

Returns:

the previously stored value; may be null
remove
(N
the namespace; never null
namespace
,
Object
the key; never null
key
,
Class<T>
the required type of the value; never null
requiredType
)

Remove the value stored for the supplied namespace and key from this store and cast it to the supplied required type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait