| Constructor and Description |
|---|
Paginator(RQ request,
Function<RQ,RS> requestFn,
Function<RS,Collection<T>> itemsFn,
Function<RS,RQ> nextPageFn)
Repeatedly call `requestFn` until `nextPageFn` returns non-null result.
|
| Modifier and Type | Method and Description |
|---|---|
Iterator<T> |
iterator() |
<ID> Iterable<T> |
withDedupe(Function<T,ID> idGetter)
De-duplicate results across all pages with an ID
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic Paginator(RQ request, Function<RQ,RS> requestFn, Function<RS,Collection<T>> itemsFn, Function<RS,RQ> nextPageFn)
Example:
return new Paginator<>(request, impl::listRuns, ListRunsResponse::getRuns, response -> {
Long offset = request.getOffset();
if (offset == null) {
offset = 0L;
}
offset += response.getRuns().size();
return request.setOffset(offset);
}).withDedupe(BaseRun::getRunId);
request - initial request to `requestFn` implementation, possibly with filters.requestFn - implementation of request, that takes modified `request` and returns some
results.itemsFn - reference to the getter method, that returns `CollectionnextPageFn - return non-null request in case we need to fetch another page of results.public <ID> Iterable<T> withDedupe(Function<T,ID> idGetter)
This call is only necessary for offset/limit pagination, where additions/removals may get inconsistent results across multiple page calls
ID - ID type, like LongidGetter - reference to ID getterCopyright © 2024. All rights reserved.