Class LazyStateImpl<T>
java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.internal.state.LazyStateImpl<T>
- Type Parameters:
T- the value type
- All Implemented Interfaces:
IdentifiableToken,State<T>,StateToken
Read-only state token computed once per context on the first read and stored in the
session's
StateStore; a null result is cached via a private sentinel so
the computation never re-runs for that context.-
Constructor Summary
ConstructorsConstructorDescriptionLazyStateImpl(@NotNull View owner, @NotNull TokenTable table, @NotNull Function<ViewContext, T> computation) Creates and registers the token. -
Method Summary
Modifier and TypeMethodDescriptionget(@NotNull ViewContext context) Reads this token's value for the given context.intid()Returns the table-assigned token id, the index into the per-session state store.inttokenId()
-
Constructor Details
-
LazyStateImpl
public LazyStateImpl(@NotNull @NotNull View owner, @NotNull @NotNull TokenTable table, @NotNull @NotNull Function<ViewContext, T> computation) Creates and registers the token.- Parameters:
owner- the view declaring the tokentable- the owner's token tablecomputation- the once-per-context computation- Throws:
IllegalStateException- when the table is already frozen
-
-
Method Details
-
id
public int id()Returns the table-assigned token id, the index into the per-session state store.- Returns:
- the token id
-
tokenId
public int tokenId()- Specified by:
tokenIdin interfaceIdentifiableToken- Returns:
- the token id assigned by the owning view's token table
-
get
Description copied from interface:StateReads this token's value for the given context. Callable from any thread, but values are only coherent on the main thread.
-