-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] java: pagination #3632
base: main
Are you sure you want to change the base?
[WIP] java: pagination #3632
Conversation
a2fb89e
to
3806580
Compare
.startingAfter(startingAfter) | ||
.build(); | ||
return new SyncPagingIterable<>(startingAfter.isPresent(), parsedResponse.getData(), | ||
() -> listWithCursorPagination(nextRequest, requestOptions)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example block for offset pagination (from hume, includes handling a response that's an Optional<List< ... >>
)
FilePage parsedResponse = ObjectMappers.JSON_MAPPER.readValue(responseBody.string(), FilePage.class);
Integer newPageNumber = request.getPageNumber().map(page -> page + 1).orElse(1);
FilesListFilesRequest nextRequest = FilesListFilesRequest.builder()
.from(request)
.pageNumber(newPageNumber)
.build();
return new SyncPagingIterable<>(
true, parsedResponse.getContent(), () -> listFiles(nextRequest, requestOptions));
super(hasNext, items, getNext); | ||
} | ||
|
||
public SyncPagingIterable(boolean hasNext, Optional<List<T>> items, Supplier<? extends SyncPage<T>> getNext) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made this extra constructor to handle an Optional
items
for 2 reasons:
- this basically delegates some extra logic to this class instead of the client method. imo feels most important to keep client methods clean over
core
classes; i'd imagine people spend more time looking at clients - a bit easier to implement this way!
public SyncPagingIterable(boolean hasNext, Optional<List<T>> items, Supplier<? extends SyncPage<T>> getNext) { | ||
super(hasNext, items.orElse(new ArrayList<>()), getNext); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the itererator, should we have a way to get all of the values in a list or stream easily? like a toList()
?
my vote: make a ticket and consider adding this in the future
No description provided.