java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.PaginationImpl<T>
Type Parameters:
T - the element type
All Implemented Interfaces:
IdentifiableToken, Pagination<T>, StateToken

@Internal public final class PaginationImpl<T> extends Object implements Pagination<T>, IdentifiableToken
The Pagination token implementation: a per-view singleton declared at view construction time whose per-context runtime lives in a PaginationBinding stored in this token's own StateStore slot. Every method resolves the binding through the shared ContextStateAccess.storeFor(ViewContext, View) guard, then delegates to the pending-navigation recorder before initialization and to the bound Paginator afterwards; mutators additionally assert the main thread.
  • Constructor Details

    • PaginationImpl

      public PaginationImpl(@NotNull @NotNull View owner, @NotNull @NotNull TokenTable table, @NotNull @NotNull PaginationSpec<T> spec)
      Creates and registers the token; called by PaginationBuilderImpl.build(), so registration happens at build time.
      Parameters:
      owner - the view declaring the token
      table - the owner's token table
      spec - the immutable pagination declaration
      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
    • spec

      @NotNull public @NotNull PaginationSpec<T> spec()
      Returns the immutable declaration this token was built from.
      Returns:
      the pagination spec
    • currentPage

      public int currentPage(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Returns the current page, 1-indexed. Before initialization this is the pending navigation target.
      Specified by:
      currentPage in interface Pagination<T>
      Parameters:
      context - the context of the session to read
      Returns:
      the current 1-indexed page
    • totalPages

      public int totalPages(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Returns the total page count, always at least 1. Before initialization — and, for async sources, before the first successful load reveals the totals — this is 1.
      Specified by:
      totalPages in interface Pagination<T>
      Parameters:
      context - the context of the session to read
      Returns:
      the total page count, >= 1
    • totalElements

      public int totalElements(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Returns the total element count of the backing source. Before initialization — and, for async sources, before totals are known — this is 0.
      Specified by:
      totalElements in interface Pagination<T>
      Parameters:
      context - the context of the session to read
      Returns:
      the total element count
    • canAdvance

      public boolean canAdvance(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Returns whether a next page exists, i.e. currentPage + 1 <= totalPages. Always false before initialization.
      Specified by:
      canAdvance in interface Pagination<T>
      Parameters:
      context - the context of the session to read
      Returns:
      true when Pagination.advance(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext) would move forward
    • canBack

      public boolean canBack(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Returns whether a previous page exists, i.e. currentPage > 1. Before initialization this reports whether the pending target is above page 1.
      Specified by:
      canBack in interface Pagination<T>
      Parameters:
      context - the context of the session to read
      Returns:
      true when Pagination.back(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext) would move backward
    • advance

      public void advance(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Navigates one page forward, clamped exactly like Pagination.switchTo(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext, int). Before initialization the pending target is incremented instead. Main thread only.
      Specified by:
      advance in interface Pagination<T>
      Parameters:
      context - the context of the session to navigate
    • back

      public void back(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Navigates one page backward, clamped exactly like Pagination.switchTo(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext, int). Before initialization the pending target is decremented instead (never below 1). Main thread only.
      Specified by:
      back in interface Pagination<T>
      Parameters:
      context - the context of the session to navigate
    • switchTo

      public void switchTo(@NotNull @NotNull ViewContext context, int page)
      Description copied from interface: Pagination
      Switches to the given page. The target is clamped exactly as the 2.x changePage: lower-clamped to page 1 always, upper-clamped to Pagination.totalPages(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext) only once the source's totals are known (always for eager sources; after the first successful load for async sources — an overshooting target is re-clamped downward when that load settles). Re-requesting the page already shown is a no-op while that page is still loading. Before initialization the lower-clamped target is recorded and replayed at initialization. Main thread only.
      Specified by:
      switchTo in interface Pagination<T>
      Parameters:
      context - the context of the session to navigate
      page - the 1-indexed target page; out-of-range values are clamped, not rejected
    • isLoading

      public boolean isLoading(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Returns whether the latest page request has not settled yet. Always false for eager sources and before initialization.
      Specified by:
      isLoading in interface Pagination<T>
      Parameters:
      context - the context of the session to read
      Returns:
      true while a page load is in flight
    • lastError

      @Nullable public @Nullable Throwable lastError(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Returns the failure of the most recently settled page load, or null; cleared when a new request is dispatched. Always null for eager sources and before initialization.
      Specified by:
      lastError in interface Pagination<T>
      Parameters:
      context - the context of the session to read
      Returns:
      the last page-load failure, or null
    • refresh

      public void refresh(@NotNull @NotNull ViewContext context)
      Description copied from interface: Pagination
      Forces a reload of the current page. Before initialization this is a no-op. After initialization the behavior depends on the source kind: lazy sources (View.paginate(Function)) re-invoke the source function against this context and swap the fresh result in; async sources invalidate their page cache; every kind then re-requests the current page, forced — the same-page dedupe is bypassed. Main thread only.
      Specified by:
      refresh in interface Pagination<T>
      Parameters:
      context - the context of the session to refresh