Class PaginationImpl<T>
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 Summary
ConstructorsConstructorDescriptionPaginationImpl(@NotNull View owner, @NotNull TokenTable table, @NotNull PaginationSpec<T> spec) Creates and registers the token; called byPaginationBuilderImpl.build(), so registration happens at build time. -
Method Summary
Modifier and TypeMethodDescriptionvoidadvance(@NotNull ViewContext context) Navigates one page forward, clamped exactly likePagination.switchTo(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext, int).voidback(@NotNull ViewContext context) Navigates one page backward, clamped exactly likePagination.switchTo(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext, int).booleancanAdvance(@NotNull ViewContext context) Returns whether a next page exists, i.e.booleancanBack(@NotNull ViewContext context) Returns whether a previous page exists, i.e.intcurrentPage(@NotNull ViewContext context) Returns the current page, 1-indexed.intid()Returns the table-assigned token id, the index into the per-session state store.booleanisLoading(@NotNull ViewContext context) Returns whether the latest page request has not settled yet.@Nullable ThrowablelastError(@NotNull ViewContext context) Returns the failure of the most recently settled page load, ornull; cleared when a new request is dispatched.voidrefresh(@NotNull ViewContext context) Forces a reload of the current page.@NotNull PaginationSpec<T>spec()Returns the immutable declaration this token was built from.voidswitchTo(@NotNull ViewContext context, int page) Switches to the given page.inttokenId()inttotalElements(@NotNull ViewContext context) Returns the total element count of the backing source.inttotalPages(@NotNull ViewContext context) Returns the total page count, always at least 1.
-
Constructor Details
-
PaginationImpl
public PaginationImpl(@NotNull @NotNull View owner, @NotNull @NotNull TokenTable table, @NotNull @NotNull PaginationSpec<T> spec) Creates and registers the token; called byPaginationBuilderImpl.build(), so registration happens at build time.- Parameters:
owner- the view declaring the tokentable- the owner's token tablespec- 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:
tokenIdin interfaceIdentifiableToken- Returns:
- the token id assigned by the owning view's token table
-
spec
Returns the immutable declaration this token was built from.- Returns:
- the pagination spec
-
currentPage
Description copied from interface:PaginationReturns the current page, 1-indexed. Before initialization this is the pending navigation target.- Specified by:
currentPagein interfacePagination<T>- Parameters:
context- the context of the session to read- Returns:
- the current 1-indexed page
-
totalPages
Description copied from interface:PaginationReturns the total page count, always at least 1. Before initialization — and, for async sources, before the first successful load reveals the totals — this is1.- Specified by:
totalPagesin interfacePagination<T>- Parameters:
context- the context of the session to read- Returns:
- the total page count,
>= 1
-
totalElements
Description copied from interface:PaginationReturns the total element count of the backing source. Before initialization — and, for async sources, before totals are known — this is0.- Specified by:
totalElementsin interfacePagination<T>- Parameters:
context- the context of the session to read- Returns:
- the total element count
-
canAdvance
Description copied from interface:PaginationReturns whether a next page exists, i.e.currentPage + 1 <= totalPages. Alwaysfalsebefore initialization.- Specified by:
canAdvancein interfacePagination<T>- Parameters:
context- the context of the session to read- Returns:
truewhenPagination.advance(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext)would move forward
-
canBack
Description copied from interface:PaginationReturns whether a previous page exists, i.e.currentPage > 1. Before initialization this reports whether the pending target is above page 1.- Specified by:
canBackin interfacePagination<T>- Parameters:
context- the context of the session to read- Returns:
truewhenPagination.back(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext)would move backward
-
advance
Description copied from interface:PaginationNavigates one page forward, clamped exactly likePagination.switchTo(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext, int). Before initialization the pending target is incremented instead. Main thread only.- Specified by:
advancein interfacePagination<T>- Parameters:
context- the context of the session to navigate
-
back
Description copied from interface:PaginationNavigates one page backward, clamped exactly likePagination.switchTo(tech.guilhermekaua.spigotboot.inventoryapi.context.ViewContext, int). Before initialization the pending target is decremented instead (never below 1). Main thread only.- Specified by:
backin interfacePagination<T>- Parameters:
context- the context of the session to navigate
-
switchTo
Description copied from interface:PaginationSwitches to the given page. The target is clamped exactly as the 2.xchangePage: lower-clamped to page 1 always, upper-clamped toPagination.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:
switchToin interfacePagination<T>- Parameters:
context- the context of the session to navigatepage- the 1-indexed target page; out-of-range values are clamped, not rejected
-
isLoading
Description copied from interface:PaginationReturns whether the latest page request has not settled yet. Alwaysfalsefor eager sources and before initialization.- Specified by:
isLoadingin interfacePagination<T>- Parameters:
context- the context of the session to read- Returns:
truewhile a page load is in flight
-
lastError
Description copied from interface:PaginationReturns the failure of the most recently settled page load, ornull; cleared when a new request is dispatched. Alwaysnullfor eager sources and before initialization.- Specified by:
lastErrorin interfacePagination<T>- Parameters:
context- the context of the session to read- Returns:
- the last page-load failure, or
null
-
refresh
Description copied from interface:PaginationForces 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:
refreshin interfacePagination<T>- Parameters:
context- the context of the session to refresh
-