java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.internal.state.LazyStateImpl<T>
Type Parameters:
T - the value type
All Implemented Interfaces:
IdentifiableToken, State<T>, StateToken

@Internal public final class LazyStateImpl<T> extends Object implements State<T>, IdentifiableToken
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 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 token
      table - the owner's token table
      computation - 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:
      tokenId in interface IdentifiableToken
      Returns:
      the token id assigned by the owning view's token table
    • 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