Skip to content

Commit

Permalink
add boolean Page.last()
Browse files Browse the repository at this point in the history
so that iteration doesn't work via !page.last() instead
of more verbosely page.nextPageRequest() != null
  • Loading branch information
gavinking committed Feb 29, 2024
1 parent 4fc8a93 commit 4004211
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 this the last page of results, so that
* {@link #nextPageRequest()} will return {@code null}.
* @return {@code true} if this the last page of results
*/
boolean last();

/**
* 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 last() {
return !moreResults;
}

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

0 comments on commit 4004211

Please sign in to comment.