Package com.databricks.sdk.support
Class Paginator<RQ,RS,T>
- java.lang.Object
-
- com.databricks.sdk.support.Paginator<RQ,RS,T>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Iterator<T>
iterator()
<ID> Iterable<T>
withDedupe(Function<T,ID> idGetter)
De-duplicate results across all pages with an ID-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
Paginator
public 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.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);
- Parameters:
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 `Collection` of results. nextPageFn
- return non-null request in case we need to fetch another page of results.
-
-
Method Detail
-
withDedupe
public <ID> Iterable<T> withDedupe(Function<T,ID> idGetter)
De-duplicate results across all pages with an IDThis call is only necessary for offset/limit pagination, where additions/removals may get inconsistent results across multiple page calls
- Type Parameters:
ID
- ID type, like Long- Parameters:
idGetter
- reference to ID getter- Returns:
- ID value, like 92384023984
-
-