Class PaginationSourceSpec<T>
java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.internal.pagination.PaginationSourceSpec<T>
- Type Parameters:
T- the element type served by the source
Immutable source declaration of one pagination token: which of the four source kinds the
view declared, and how to construct the
PageSource for one context.
PaginationSourceSpec.Kind.EAGER_STATIC carries the ONE EagerPageSource shared by every context —
safe because that source is immutable; every other kind constructs a fresh source per
context, preserving per-context isolation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe four ways a view can declare where page elements come from. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> @NotNull PaginationSourceSpec<T>async(@NotNull AsyncPageSupplier<T> supplier) Declares an async source: a freshAsyncPageSourceis constructed per context from the supplier and the owning spec's async options.@NotNull PageSource<T>createSource(@NotNull ViewContext context, @NotNull PaginationSpec<T> spec, @NotNull PlatformScheduler scheduler) Creates (or returns) thePageSourcefor one context.static <T> @NotNull PaginationSourceSpec<T>custom(@NotNull Function<ViewContext, PageSource<T>> factory) Declares a custom source: the factory runs once per context and its result is used as-is.static <T> @NotNull PaginationSourceSpec<T>Declares a static eager source.booleanisAsync()Returns whether this is an async declaration — the gate for the async-only builder options.@NotNull PaginationSourceSpec.Kindkind()Returns the source kind.static <T> @NotNull PaginationSourceSpec<T>lazy(@NotNull Function<ViewContext, List<T>> source) Declares a lazy eager source:sourceruns once per context at initialization (and again onPagination.refresh), each result wrapped in a freshEagerPageSource.@Nullable Function<ViewContext,List<T>> Returns the lazy list function, used by thePagination.refreshpath to re-evaluate the source.
-
Method Details
-
eager
Declares a static eager source. The ONE sharedEagerPageSourceevery context will use is built immediately; the defensive copy ofsourceis taken by theEagerPageSourceconstructor itself, so later mutation of the caller's list never leaks into pages.- Type Parameters:
T- the element type- Parameters:
source- the backing elements- Returns:
- the source spec
- Throws:
NullPointerException- ifsourceis null
-
lazy
@NotNull public static <T> @NotNull PaginationSourceSpec<T> lazy(@NotNull @NotNull Function<ViewContext, List<T>> source) Declares a lazy eager source:sourceruns once per context at initialization (and again onPagination.refresh), each result wrapped in a freshEagerPageSource.- Type Parameters:
T- the element type- Parameters:
source- produces the backing elements for one context- Returns:
- the source spec
- Throws:
NullPointerException- ifsourceis null
-
async
@NotNull public static <T> @NotNull PaginationSourceSpec<T> async(@NotNull @NotNull AsyncPageSupplier<T> supplier) Declares an async source: a freshAsyncPageSourceis constructed per context from the supplier and the owning spec's async options.- Type Parameters:
T- the element type- Parameters:
supplier- loads pages on demand- Returns:
- the source spec
- Throws:
NullPointerException- ifsupplieris null
-
custom
@NotNull public static <T> @NotNull PaginationSourceSpec<T> custom(@NotNull @NotNull Function<ViewContext, PageSource<T>> factory) Declares a custom source: the factory runs once per context and its result is used as-is.- Type Parameters:
T- the element type- Parameters:
factory- produces the page source for one context- Returns:
- the source spec
- Throws:
NullPointerException- iffactoryis null
-
kind
Returns the source kind.- Returns:
- the kind
-
isAsync
public boolean isAsync()Returns whether this is an async declaration — the gate for the async-only builder options.- Returns:
truewhenkind()isPaginationSourceSpec.Kind.ASYNC
-
lazyFunction
Returns the lazy list function, used by thePagination.refreshpath to re-evaluate the source.- Returns:
- the function; non-null only for
PaginationSourceSpec.Kind.EAGER_LAZY
-
createSource
@NotNull public @NotNull PageSource<T> createSource(@NotNull @NotNull ViewContext context, @NotNull @NotNull PaginationSpec<T> spec, @NotNull @NotNull PlatformScheduler scheduler) Creates (or returns) thePageSourcefor one context.PaginationSourceSpec.Kind.EAGER_STATIC: returns the single sharedEagerPageSourcebuilt byeager(List).PaginationSourceSpec.Kind.EAGER_LAZY: invokes the source function withcontextand wraps the result in a freshEagerPageSource(whose constructor takes the defensive copy).PaginationSourceSpec.Kind.ASYNC: constructs a freshAsyncPageSourcefrom the supplier and the spec's async options, dispatching settles through aBukkitSettleDispatcherbacked by the given scheduler.PaginationSourceSpec.Kind.CUSTOM: invokes the factory withcontextand returns its result as-is.
- Parameters:
context- the context the source will servespec- the owning spec, read for the async optionsscheduler- the platform scheduler used to route async settles to the viewer's region thread; passed through to theBukkitSettleDispatcherforPaginationSourceSpec.Kind.ASYNCsources- Returns:
- the page source for this context
- Throws:
NullPointerException- if the lazy function returns null ("lazy pagination source function returned null"), or the custom factory returns null ("paginateSource factory returned null"), or an argument is null
-