Class PatternPagination<T>
- Type Parameters:
T- the source element type
- All Implemented Interfaces:
Paginator<T>
Layout patterns, cycling through the
patterns as the player pages forward. Each page renders a contiguous slice of the source whose
length equals the slot count of that page's pattern, so every source item appears exactly once
across the pages with no gaps or overlap.
The pattern controls only where and in what order items are placed: slots
are filled in the order of the layout's Layout.slots() list, which lets a pattern
lay items out horizontally, vertically, or in any custom order. Grid-based layouts derive that
order from their letters; ordered-slots layouts state it explicitly.
Paginator.changePage(int) records the previous layout in lastPattern and clears its
slots before rendering the new page, so cycling between patterns of different sizes leaves no
residual items behind. Pages come from a PageSource: an in-memory list by default, or
an async supplier configured by the declaring view.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected final Supplier<RenderedItem>protected PaginationHostprotected final PageItemFactory<T>protected intprotected final Supplier<RenderedItem>protected final LoggerNamed after the concrete class so warnings point at the actual pagination type.protected PageSource<T> -
Constructor Summary
ConstructorsConstructorDescriptionPatternPagination(@Nullable Supplier<RenderedItem> fallbackItem, @NotNull PageItemFactory<T> itemFactory, @NotNull List<Layout> patterns) Creates an eager paginator over an initially empty source.PatternPagination(@Nullable Supplier<RenderedItem> fallbackItem, @NotNull PageItemFactory<T> itemFactory, @NotNull List<Layout> patterns, @Nullable Supplier<RenderedItem> loadingItem, @NotNull PageSource<T> pageSource) Creates a paginator over the given page source. -
Method Summary
Modifier and TypeMethodDescriptionvoidbind(@NotNull PaginationHost host) Binds the engine against a freshly opened host: sets the host, derives the navigation state for the current (possibly pre-recorded) page and dispatches the initial load without requesting a render — the open's initial paint covers it.voidchangePage(int page) Navigates directly to the given 1-indexed page.protected voidcommitNavigation(int target) Commits navigation to the already-clamped target page: updates the current page and any per-type layout state.protected final @NotNull RenderedItemintgetPageOfIndex(int index) Maps a global source index onto the page it appears on.intReturns the element count of the current source.intReturns the page count of the current source.booleanReturns whether forward navigation is possible.booleanReturns whether backward navigation is possible.protected voidDerives the layout state (page limit, pattern, ...) for the current page.voidPaints the items of the current page throughPaginationHost.fillPage(java.util.List<tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.RenderedItem>, tech.guilhermekaua.spigotboot.inventoryapi.layout.Layout).booleanReports whether the most recently settled page rendered no elements.booleanReturns the in-flight state of the source.@Nullable ThrowableReturns the most recent load failure.protected final @NotNull RenderedItemprotected tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.engine.PatternPagination.PatternStatevoidnextPage()Advances to the next page if one exists.voidReturns to the previous page if one exists.voidrefresh()Re-requests the current page, invalidating any cached copy first.protected LayoutvoidreplaceSource(@NotNull PageSource<T> source) Swaps the backing source and clears the locally held items.protected intprotected voidrestoreNavigation(tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.engine.PatternPagination.PatternState snapshot) Restores the navigation state captured bynavigationSnapshot()after a failed load, including clearing anything the failed navigation already painted.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.engine.Paginator
getCurrentPage, getItemPageLimit
-
Field Details
-
logger
Named after the concrete class so warnings point at the actual pagination type. -
fallbackItem
-
itemFactory
-
loadingItem
-
pageSource
-
host
-
currentPage
protected int currentPage -
itemPageLimit
protected int itemPageLimit
-
-
Constructor Details
-
PatternPagination
public PatternPagination(@Nullable @Nullable Supplier<RenderedItem> fallbackItem, @NotNull @NotNull PageItemFactory<T> itemFactory, @NotNull @NotNull List<Layout> patterns) Creates an eager paginator over an initially empty source.- Parameters:
fallbackItem- item used for empty slots, may be nullitemFactory- renders one source element, not nullpatterns- the layout patterns cycled across pages, not null or empty
-
PatternPagination
public PatternPagination(@Nullable @Nullable Supplier<RenderedItem> fallbackItem, @NotNull @NotNull PageItemFactory<T> itemFactory, @NotNull @NotNull List<Layout> patterns, @Nullable @Nullable Supplier<RenderedItem> loadingItem, @NotNull @NotNull PageSource<T> pageSource) Creates a paginator over the given page source.- Parameters:
fallbackItem- item used for empty slots, may be nullitemFactory- renders one source element, not nullpatterns- the layout patterns cycled across pages, not null or emptyloadingItem- item rendered while an async load is in flight, may be nullpageSource- where page items come from, not null- Throws:
NullPointerException- ifpageSourceis null
-
-
Method Details
-
requestOffset
protected int requestOffset()- Returns:
- the global element offset of the first item of the current page
-
renderLayout
- Returns:
- the layout the current page renders into
-
getTotalPages
public int getTotalPages()Description copied from interface:PaginatorReturns the page count of the current source.Results are undefined before
Paginator.bind(tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.PaginationHost): the page limit is derived from the layout at bind time (pre-init reads are answered by the binding, never by the engine).- Returns:
- the total number of pages backing the current source, at least 1
-
getPageOfIndex
public int getPageOfIndex(int index) Description copied from interface:PaginatorMaps a global source index onto the page it appears on.Results are undefined before
Paginator.bind(tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.PaginationHost): the page limit is derived from the layout at bind time (pre-init reads are answered by the binding, never by the engine).- Parameters:
index- the global element index- Returns:
- the 1-indexed page containing the given index (for scroll paginators: the first
page on which the index becomes visible), or
-1if the index is outside[0, getTotalElements())
-
bind
Description copied from interface:PaginatorBinds the engine against a freshly opened host: sets the host, derives the navigation state for the current (possibly pre-recorded) page and dispatches the initial load without requesting a render — the open's initial paint covers it.Must be called once before any painting method is invoked. Eager sources settle inline during bind, so their items are ready before the first paint; async sources leave
Paginator.isLoading()trueso the first paint shows the loading frame. -
nextPage
public void nextPage()Description copied from interface:PaginatorAdvances to the next page if one exists. -
hasNextPage
public boolean hasNextPage()Description copied from interface:PaginatorReturns whether forward navigation is possible.- Specified by:
hasNextPagein interfacePaginator<T>- Returns:
trueif there is at least one page after the current one
-
previousPage
public void previousPage()Description copied from interface:PaginatorReturns to the previous page if one exists.- Specified by:
previousPagein interfacePaginator<T>
-
hasPreviousPage
public boolean hasPreviousPage()Description copied from interface:PaginatorReturns whether backward navigation is possible.- Specified by:
hasPreviousPagein interfacePaginator<T>- Returns:
trueif there is at least one page before the current one
-
insertPageItems
public void insertPageItems()Description copied from interface:PaginatorPaints the items of the current page throughPaginationHost.fillPage(java.util.List<tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.RenderedItem>, tech.guilhermekaua.spigotboot.inventoryapi.layout.Layout).- Specified by:
insertPageItemsin interfacePaginator<T>
-
isCurrentPageEmpty
public boolean isCurrentPageEmpty()Description copied from interface:PaginatorReports whether the most recently settled page rendered no elements. Used by the host to decide whether to paint the empty-state frame.- Specified by:
isCurrentPageEmptyin interfacePaginator<T>- Returns:
truewhen the current page has no elements
-
changePage
public void changePage(int page) Description copied from interface:PaginatorNavigates directly to the given 1-indexed page.The target is clamped to at least 1, and to
Paginator.getTotalPages()once the backing source's totals are known. For async sources, navigation issued before the first load completes is honored optimistically and re-clamped downward when totals arrive. A call that targets the current page while a request for it is already in flight is ignored; usePaginator.refresh()to force a reload. BeforePaginator.bind(PaginationHost)the call only records the target page;binddispatches the load for it.- Specified by:
changePagein interfacePaginator<T>- Parameters:
page- the 1-indexed page to navigate to
-
replaceSource
Description copied from interface:PaginatorSwaps the backing source and clears the locally held items. Dispatches nothing and renders nothing — callers drive the re-request; a swap beforePaginator.bind(PaginationHost)is picked up by the bind-time dispatch.- Specified by:
replaceSourcein interfacePaginator<T>- Parameters:
source- the new page source, not null
-
isLoading
public boolean isLoading()Description copied from interface:PaginatorReturns the in-flight state of the source. -
lastError
Description copied from interface:PaginatorReturns the most recent load failure. -
getTotalElements
public int getTotalElements()Description copied from interface:PaginatorReturns the element count of the current source.- Specified by:
getTotalElementsin interfacePaginator<T>- Returns:
- the total number of elements in the backing source, independent of how many are loaded locally
-
refresh
public void refresh()Description copied from interface:PaginatorRe-requests the current page, invalidating any cached copy first. For async sources this is the supported idiom to re-query after the backing store changed; for eager sources it re-renders the current page. -
emptyOrFallback
- Returns:
- the configured fallback item, or a slot clear when none was set
-
loadingOrFallback
- Returns:
- the configured loading item, falling back to
emptyOrFallback()