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

    Constructors
    Constructor
    Description
    InitialStateImpl(@NotNull View owner, @NotNull TokenTable table, @NotNull String key, @NotNull Class<T> type)
    Creates and registers the token.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(@NotNull ViewContext context)
    Reads this token's value for the given context.
    int
    id()
    Returns the table-assigned token id, the index into the per-session state store.
    @NotNull String
    key()
    Returns the ViewArguments key this token binds at open.
    void
    set(@NotNull ViewContext context, T value)
    Writes this token's value for the given context and marks watchers dirty.
    int
     
    @NotNull Class<T>
    Returns the expected argument type, validated at the open site.
    void
    update(@NotNull ViewContext context, @NotNull UnaryOperator<T> fn)
    Read-modify-write convenience: applies fn to the current value and stores the result.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 token
      table - the owner's token table
      key - the ViewArguments key bound at open
      type - 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:
      tokenId in interface IdentifiableToken
      Returns:
      the token id assigned by the owning view's token table
    • key

      @NotNull public @NotNull String key()
      Returns the ViewArguments key this token binds at open.
      Returns:
      the argument key
    • type

      @NotNull public @NotNull Class<T> type()
      Returns the expected argument type, validated at the open site.
      Returns:
      the value type
    • get

      @Nullable public T get(@NotNull @NotNull ViewContext context)
      Description copied from interface: State
      Reads this token's value for the given context. Callable from any thread, but values are only coherent on the main thread.
      Specified by:
      get in interface State<T>
      Parameters:
      context - an active context of the owning view
      Returns:
      the current value, possibly null
    • set

      public void set(@NotNull @NotNull ViewContext context, @Nullable T value)
      Description copied from interface: MutableState
      Writes this token's value for the given context and marks watchers dirty.
      Specified by:
      set in interface MutableState<T>
      Parameters:
      context - an active context of the owning view
      value - the new value, possibly null
    • update

      public void update(@NotNull @NotNull ViewContext context, @NotNull @NotNull UnaryOperator<T> fn)
      Description copied from interface: MutableState
      Read-modify-write convenience: applies fn to the current value and stores the result. Main thread only.
      Specified by:
      update in interface MutableState<T>
      Parameters:
      context - an active context of the owning view
      fn - the function producing the new value from the current one; invoked exactly once on the current value. Side effects inside fn are safe (unlike SharedState.update(java.util.function.UnaryOperator<T>))