Skip to content

Commit

Permalink
add boolean Page.hasNextPage()
Browse files Browse the repository at this point in the history
so that iteration works via page.hasNextPage() instead
of more verbosely page.nextPageRequest() != null
  • Loading branch information
gavinking committed Feb 29, 2024
1 parent 4fc8a93 commit 5a1fd27
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions api/src/main/java/jakarta/data/page/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
*/
public interface Page<T> extends Slice<T> {

/**
* Returns {@code true} if it is known that there are more results, so that
* {@link #nextPageRequest()} will definitely not return {@code null}.
* @return {@code false} if this the last page of results
*/
boolean hasNextPage();

/**
* Returns the total number of elements across all pages that can be requested for the query.
* @return the total number of elements across all pages.
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/jakarta/data/page/impl/PageRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public int numberOfElements() {
return content.size();
}

@Override
public boolean hasNextPage() {
return moreResults;
}

@Override
@SuppressWarnings("unchecked")
public <E> PageRequest<E> pageRequest(Class<E> entityClass) {
Expand Down

0 comments on commit 5a1fd27

Please sign in to comment.