@API(status=EXPERIMENTAL,
since="1.2.3")
public interface Store<T>
Modifier and Type | Interface and Description |
---|---|
static interface |
Store.CloseOnReset
Any value that implements this interface will automatically be closed when its store goes out of scope.
|
static class |
Store.StoreFacade |
Modifier and Type | Method and Description |
---|---|
static <T> Store<T> |
create(java.lang.Object identifier,
Lifespan lifespan,
java.util.function.Supplier<T> initialValueSupplier)
Create a new store for storing and retrieving values and objects in lifecycle
hooks and lifecycle-dependent methods.
|
static <T> Store<T> |
free(java.util.function.Supplier<T> initializer)
Create a "free" store, i.e. one that lives independently from a test run, property or try.
|
T |
get() |
static <T> Store<T> |
get(java.lang.Object identifier)
Retrieve a store that must be created somewhere else.
|
static <T> Store<T> |
getOrCreate(java.lang.Object identifier,
Lifespan lifespan,
java.util.function.Supplier<T> initialValueSupplier)
Find an existing store or create a new one if it doesn't exist.
|
Lifespan |
lifespan() |
void |
reset() |
void |
update(java.util.function.Function<T,T> updater) |
T get()
Lifespan lifespan()
@API(status=INTERNAL, since="1.6.3") void reset()
static <T> Store<T> create(java.lang.Object identifier, Lifespan lifespan, java.util.function.Supplier<T> initialValueSupplier)
Stores are created with respect to the current test / property. Therefore you _must not save created stores in member variables_, unless the containing object is unique per test / property.
T
- The type of object to storeidentifier
- Any object to identify a store. Must be globally unique and stable, i.e. hashCode and equals must not change.lifespan
- A stored object's lifespaninitialValueSupplier
- Supplies the value to be used for initializing the store depending on its lifespanstatic <T> Store<T> getOrCreate(java.lang.Object identifier, Lifespan lifespan, java.util.function.Supplier<T> initialValueSupplier)
Stores are created with respect to the current test / property. Therefore you _must not save created stores in member variables_, unless the containing object is unique per test / property.
T
- The type of object to storeidentifier
- Any object to identify a store. Must be globally unique and stable, i.e. hashCode and equals must not change.lifespan
- A stored object's lifespaninitialValueSupplier
- Supplies the value to be used for initializing the store depending on its lifespanstatic <T> Store<T> get(java.lang.Object identifier)
T
- The type of object to storeidentifier
- Any object to identify a store. Must be globally unique and stable, i.e. hashCode and equals must not change.CannotFindStoreException
@API(status=EXPERIMENTAL, since="1.5.0") static <T> Store<T> free(java.util.function.Supplier<T> initializer)
T
- The type of object to storeinitializer
- Supplies the value to be used for initializing the store depending on its lifespan