Class PaginationBuilderImpl<T>
java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.PaginationBuilderImpl<T>
- Type Parameters:
T- the element type
- All Implemented Interfaces:
PaginationBuilder<T>
@Internal
public final class PaginationBuilderImpl<T>
extends Object
implements PaginationBuilder<T>
PaginationBuilder implementation behind View.paginate*: collects the
declaration fluently (value errors rejected at setter time), validates the combination
at build(), resolves geometry and target, and constructs the registered
PaginationImpl token. One builder produces at most one token.-
Constructor Summary
ConstructorsConstructorDescriptionPaginationBuilderImpl(@NotNull View owner, @NotNull TokenTable table, @NotNull PaginationSourceSpec<T> source) Creates a builder for one pagination declaration of a view. -
Method Summary
Modifier and TypeMethodDescription@NotNull Pagination<T>build()Validates the declaration, constructs the token and registers it with the owning view.@NotNull PaginationBuilder<T>cacheMaxPages(int maxPages) Bounds the page cache (least-recently-used eviction).@NotNull PaginationBuilder<T>Enables page caching: revisiting a page within the TTL renders from cache without calling the supplier;Pagination.refresh(ViewContext)invalidates the cache.@NotNull PaginationBuilder<T>emptyStateItem(@NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item, int... slots) Sets an item painted into the given slots when the current page settled with no elements, leaving every other layout slot empty.@NotNull PaginationBuilder<T>fallbackItem(@NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item) Sets the item painted into page slots not covered by an element (for example the tail of a short last page) and into slots whose element failed on its very first paint.@NotNull PaginationBuilder<T>itemRenderer(@NotNull PaginationItemRenderer<T> renderer) Sets the per-element renderer.@NotNull PaginationBuilder<T>Sets an explicit fill order, silently overridingPaginationBuilder.layoutChar(char).@NotNull PaginationBuilder<T>layoutChar(char character) Targets every slot of the given character in the view's layout, in row-major order.@NotNull PaginationBuilder<T>loadingItem(@NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item) Sets the item painted into every page slot while an async load is in flight.@NotNull PaginationBuilder<T>loadingItem(@NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item, int... slots) Sets the loading item painted only into the given slots while an async load is in flight, leaving every other layout slot empty.@NotNull PaginationBuilder<T>onError(@NotNull PaginationErrorCallback callback) Sets the callback invoked when an async page load fails.@NotNull PaginationBuilder<T>Switches to pattern geometry: pageppaints into the slots of pattern(p - 1) % patterns.length, cycling through the given patterns.@NotNull PaginationBuilder<T>requestTimeout(@NotNull Duration timeout) Enables a per-request timeout: a load exceeding it fails with aTimeoutExceptionand follows the normal error path.@NotNull PaginationBuilder<T>scroll()Switches to sliding-window geometry: each page slides the visible window by exactly one element instead of jumping a full page.
-
Constructor Details
-
PaginationBuilderImpl
public PaginationBuilderImpl(@NotNull @NotNull View owner, @NotNull @NotNull TokenTable table, @NotNull @NotNull PaginationSourceSpec<T> source) Creates a builder for one pagination declaration of a view.- Parameters:
owner- the view declaring the paginationtable- the owner's token table;build()registers into itsource- the source declaration produced by theView.paginate*factory
-
-
Method Details
-
layoutChar
Description copied from interface:PaginationBuilderTargets every slot of the given character in the view's layout, in row-major order. Defaults to'O'when never called. The character must exist in the view's layout; both "no layout at all" and "char absent from the layout" are validated at view registration time. An explicitPaginationBuilder.layout(Layout)silently overrides this value; combining an explicit call withPaginationBuilder.patterns(Layout...)fails atPaginationBuilder.build().- Specified by:
layoutCharin interfacePaginationBuilder<T>- Parameters:
character- the layout character whose slots receive the page items- Returns:
- this builder
-
layout
Description copied from interface:PaginationBuilderSets an explicit fill order, silently overridingPaginationBuilder.layoutChar(char). An empty layout, or combining withPaginationBuilder.patterns(Layout...), fails atPaginationBuilder.build()withViewConfigurationException.- Specified by:
layoutin interfacePaginationBuilder<T>- Parameters:
layout- the explicit fill order for the page items- Returns:
- this builder
-
scroll
Description copied from interface:PaginationBuilderSwitches to sliding-window geometry: each page slides the visible window by exactly one element instead of jumping a full page. Cannot be combined withPaginationBuilder.patterns(Layout...)— that fails atPaginationBuilder.build().- Specified by:
scrollin interfacePaginationBuilder<T>- Returns:
- this builder
-
patterns
Description copied from interface:PaginationBuilderSwitches to pattern geometry: pageppaints into the slots of pattern(p - 1) % patterns.length, cycling through the given patterns. Cannot be combined with an explicitPaginationBuilder.layoutChar(char)call,PaginationBuilder.layout(Layout)orPaginationBuilder.scroll(); an empty array or any empty pattern also fails — all atPaginationBuilder.build()withViewConfigurationException.- Specified by:
patternsin interfacePaginationBuilder<T>- Parameters:
patterns- the per-page slot patterns, cycled in order- Returns:
- this builder
-
itemRenderer
@NotNull public @NotNull PaginationBuilder<T> itemRenderer(@NotNull @NotNull PaginationItemRenderer<T> renderer) Description copied from interface:PaginationBuilderSets the per-element renderer. Required — a declaration without a renderer fails atPaginationBuilder.build()withViewConfigurationException.- Specified by:
itemRendererin interfacePaginationBuilder<T>- Parameters:
renderer- renders one element of the current page into its component builder- Returns:
- this builder
-
fallbackItem
@NotNull public @NotNull PaginationBuilder<T> fallbackItem(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item) Description copied from interface:PaginationBuilderSets the item painted into page slots not covered by an element (for example the tail of a short last page) and into slots whose element failed on its very first paint. Evaluated against the session's context at paint time. When absent, uncovered slots are cleared instead.- Specified by:
fallbackItemin interfacePaginationBuilder<T>- Parameters:
item- the fallback item factory- Returns:
- this builder
-
loadingItem
@NotNull public @NotNull PaginationBuilder<T> loadingItem(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item) Description copied from interface:PaginationBuilderSets the item painted into every page slot while an async load is in flight. Async-only: on a non-async builderPaginationBuilder.build()throwsViewConfigurationException.- Specified by:
loadingItemin interfacePaginationBuilder<T>- Parameters:
item- the loading placeholder factory- Returns:
- this builder
-
emptyStateItem
@NotNull public @NotNull PaginationBuilder<T> emptyStateItem(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item, int... slots) Description copied from interface:PaginationBuilderSets an item painted into the given slots when the current page settled with no elements, leaving every other layout slot empty. UnlikePaginationBuilder.fallbackItem(Function)— which fills every uncovered slot of every page — this renders only while the current page is empty, and only inslots; when the page has any element it renders nothing. When both are set, the empty page shows the empty-state item (the fallback fill is suppressed for that paint).Slots are absolute container slots and may lie outside the pagination's layout. Evaluated against the session's context once per slot at paint time. A slot bound to a static component or to another pagination fails at open with
ViewConfigurationException.- Specified by:
emptyStateItemin interfacePaginationBuilder<T>- Parameters:
item- the empty-state item factoryslots- the absolute container slots to paint, at least one, each non-negative- Returns:
- this builder
-
loadingItem
@NotNull public @NotNull PaginationBuilder<T> loadingItem(@NotNull @NotNull Function<ViewContext, org.bukkit.inventory.ItemStack> item, int... slots) Description copied from interface:PaginationBuilderSets the loading item painted only into the given slots while an async load is in flight, leaving every other layout slot empty. The slotted form ofPaginationBuilder.loadingItem(Function); it has the same trigger (shown while loading) and only restricts where the item paints. Async-only: on a non-async builderPaginationBuilder.build()throwsViewConfigurationException.Slots are absolute container slots and may lie outside the pagination's layout. Evaluated against the session's context once per slot at paint time. A slot bound to a static component or to another pagination fails at open with
ViewConfigurationException.- Specified by:
loadingItemin interfacePaginationBuilder<T>- Parameters:
item- the loading item factoryslots- the absolute container slots to paint, at least one, each non-negative- Returns:
- this builder
-
onError
@NotNull public @NotNull PaginationBuilder<T> onError(@NotNull @NotNull PaginationErrorCallback callback) Description copied from interface:PaginationBuilderSets the callback invoked when an async page load fails. Async-only: on a non-async builderPaginationBuilder.build()throwsViewConfigurationException.- Specified by:
onErrorin interfacePaginationBuilder<T>- Parameters:
callback- the failure callback- Returns:
- this builder
-
requestTimeout
Description copied from interface:PaginationBuilderEnables a per-request timeout: a load exceeding it fails with aTimeoutExceptionand follows the normal error path. Async-only: on a non-async builderPaginationBuilder.build()throwsViewConfigurationException.- Specified by:
requestTimeoutin interfacePaginationBuilder<T>- Parameters:
timeout- the timeout, must be positive- Returns:
- this builder
-
cacheTtl
Description copied from interface:PaginationBuilderEnables page caching: revisiting a page within the TTL renders from cache without calling the supplier;Pagination.refresh(ViewContext)invalidates the cache. Async-only: on a non-async builderPaginationBuilder.build()throwsViewConfigurationException.- Specified by:
cacheTtlin interfacePaginationBuilder<T>- Parameters:
ttl- the cache entry freshness window, must be positive- Returns:
- this builder
-
cacheMaxPages
Description copied from interface:PaginationBuilderBounds the page cache (least-recently-used eviction). Defaults to 128. RequiresPaginationBuilder.cacheTtl(Duration)— setting it without a TTL fails atPaginationBuilder.build()withViewConfigurationException. Async-only: on a non-async builderPaginationBuilder.build()throwsViewConfigurationException.- Specified by:
cacheMaxPagesin interfacePaginationBuilder<T>- Parameters:
maxPages- the maximum number of cached pages, at least 1- Returns:
- this builder
-
build
Description copied from interface:PaginationBuilderValidates the declaration, constructs the token and registers it with the owning view. Like every token registration this is legal only while the view's tokens are still open for registration — i.e. from field initializers or the view constructor; the builder construction itself (thepaginate*call) never registers anything, only this method does.- Specified by:
buildin interfacePaginationBuilder<T>- Returns:
- the registered pagination token
-