Class InitialStateImpl<T>
java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.internal.state.InitialStateImpl<T>
- Type Parameters:
T- the value type
- All Implemented Interfaces:
IdentifiableToken,MutableState<T>,State<T>,StateToken
@Internal
public final class InitialStateImpl<T>
extends Object
implements MutableState<T>, IdentifiableToken
Mutable state token bound from
ViewArguments at open: the open phase validates
the argument type and writes the value straight into the session's StateStore.
An absent key reads as null until set. Unlike MutableStateImpl, null
values are stored directly (no sentinel): the open-phase writer always seeds the slot
before any read, so absent-vs-null does not need to be distinguished here.-
Constructor Summary
ConstructorsConstructorDescriptionInitialStateImpl(@NotNull View owner, @NotNull TokenTable table, @NotNull String key, @NotNull Class<T> type) 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.@NotNull Stringkey()Returns theViewArgumentskey this token binds at open.voidset(@NotNull ViewContext context, T value) Writes this token's value for the given context and marks watchers dirty.inttokenId()type()Returns the expected argument type, validated at the open site.voidupdate(@NotNull ViewContext context, @NotNull UnaryOperator<T> fn) Read-modify-write convenience: appliesfnto the current value and stores the result.
-
Constructor Details
-
InitialStateImpl
public InitialStateImpl(@NotNull @NotNull View owner, @NotNull @NotNull TokenTable table, @NotNull @NotNull String key, @NotNull @NotNull Class<T> type) Creates and registers the token.- Parameters:
owner- the view declaring the tokentable- the owner's token tablekey- theViewArgumentskey bound at opentype- the expected argument type, validated at the open site- 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
-
key
Returns theViewArgumentskey this token binds at open.- Returns:
- the argument key
-
type
Returns the expected argument type, validated at the open site.- Returns:
- the value type
-
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. -
set
Description copied from interface:MutableStateWrites this token's value for the given context and marks watchers dirty.- Specified by:
setin interfaceMutableState<T>- Parameters:
context- an active context of the owning viewvalue- the new value, possiblynull
-
update
Description copied from interface:MutableStateRead-modify-write convenience: appliesfnto the current value and stores the result. Main thread only.- Specified by:
updatein interfaceMutableState<T>- Parameters:
context- an active context of the owning viewfn- the function producing the new value from the current one; invoked exactly once on the current value. Side effects inside fn are safe (unlikeSharedState.update(java.util.function.UnaryOperator<T>))
-