Class EagerPageSource<T>
java.lang.Object
tech.guilhermekaua.spigotboot.inventoryapi.pagination.source.EagerPageSource<T>
- All Implemented Interfaces:
PageSource<T>
In-memory
PageSource: serves slices of a fixed list and settles every request
synchronously on the calling thread. Totals are always known, loading is never observable and
requests never fail.-
Constructor Summary
ConstructorsConstructorDescriptionEagerPageSource(List<T> elements) Creates an eager source over a defensive copy of the given list. -
Method Summary
Modifier and TypeMethodDescriptionelements()static <T> EagerPageSource<T>empty()booleanvoidrequest(PageRequest request, BiConsumer<PageResult<T>, Throwable> onSettle) Requests the page described byrequest.intbooleanMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface tech.guilhermekaua.spigotboot.inventoryapi.pagination.source.PageSource
invalidate
-
Constructor Details
-
EagerPageSource
Creates an eager source over a defensive copy of the given list.- Parameters:
elements- the backing elements, not null- Throws:
NullPointerException- ifelementsis null
-
-
Method Details
-
empty
- Type Parameters:
T- the element type- Returns:
- an eager source over an empty list
-
request
Description copied from interface:PageSourceRequests the page described byrequest.Contract for implementations:
onSettleis invoked at most once per request, with exactly one of result/error non-null — and possibly never (a superseded request).- It MAY be invoked synchronously inside this method and MAY be invoked on any thread.
- A request superseded by a newer one MUST NOT be settled.
PageSource.isLoading()must returnfalseonce the latest request settled.
- Specified by:
requestin interfacePageSource<T>- Parameters:
request- the page to load, never nullonSettle- receives the result or the failure, never null
-
totalElements
public int totalElements()- Specified by:
totalElementsin interfacePageSource<T>- Returns:
- the total number of elements in the backing store;
0until known for async sources
-
totalsKnown
public boolean totalsKnown()- Specified by:
totalsKnownin interfacePageSource<T>- Returns:
trueoncePageSource.totalElements()reflects the real store size — always for eager sources, after the first successful settle for async sources
-
isLoading
public boolean isLoading()- Specified by:
isLoadingin interfacePageSource<T>- Returns:
truewhile the latest request has not settled
-
lastError
- Specified by:
lastErrorin interfacePageSource<T>- Returns:
- the failure of the most recently settled request, or
null; cleared when a new request is dispatched
-
elements
- Specified by:
elementsin interfacePageSource<T>- Returns:
- the elements currently held locally — the full backing list for eager sources, the items of the most recently applied page for async sources
-