- Type Parameters:
T- the type of elements in this page.
- All Superinterfaces:
Iterable<T>
- All Known Subinterfaces:
CursoredPage<T>
- All Known Implementing Classes:
CursoredPageRecord,PageRecord
A page contains the data that is retrieved to satisfy a given page request.
An instance of Page is obtained by supplying a PageRequest as
an argument of a repository method. For example,
@Find
Page<Vehicle> search(@By("make") String make,
@By("model") String model,
@By("year") int designYear,
PageRequest pageRequest,
Order<Vehicle> order);
If PageRequest.requestTotal() is enabled, the Page also
contains information about the total number of pages
and the total number of elements that can be
retrieved by the query.
-
Method Summary
Modifier and TypeMethodDescriptioncontent()Returns the page content as aList.booleanReturns whether thePagehas content at all.booleanhasNext()Returnstrueif it is known that there are more results or that it is necessary to request a next page to determine whether there are more results, so thatnextPageRequest()will definitely not returnnull.booleanReturnstrueif it is known that there are previous results or that it is necessary to request the previous page to determine whether there are previous results, so thatpreviousPageRequest()will not returnnull.booleanReturnstrueif thepageRequest()specified that the total number of elements should be retrieved from the database, and that it is therefore safe to calltotalElements()ortotalPages().Returns a request for the next page ifhasNext()indicates there might be a next page.intReturns the number of elements on thisPage, which must be no larger than the maximumsizeof the page request.Returns the page request for which this page was obtained.Returns a request for the previous page, ifhasPrevious()indicates there might be a previous page.stream()Returns a sequential stream of results, which follow the order of the sort criteria, if any were specified.longReturns the total number of elements across all pages of query results, if thepageRequest()specified that the total should be retrieved from the database.longReturns the total number of pages of query results, if thepageRequest()specified that the total should be retrieved from the database.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
content
Returns the page content as aList. The list is sorted according to the combined sort criteria of the repository method and the sort criteria of the page request that is supplied to the repository method, sorting first by the sort criteria of the repository method, and then by the sort criteria of the page request.- Returns:
- the page content as a
List; will never benull.
-
hasContent
boolean hasContent()Returns whether thePagehas content at all.- Returns:
- whether the
Pagehas content at all.
-
stream
Returns a sequential stream of results, which follow the order of the sort criteria, if any were specified.- Returns:
- a stream of results.
-
numberOfElements
int numberOfElements()Returns the number of elements on thisPage, which must be no larger than the maximumsizeof the page request. If the number of elements in the page is smaller than the maximum page size, then there are no subsequent pages of data to read.- Returns:
- the number of elements on this
Page.
-
hasNext
boolean hasNext()Returnstrueif it is known that there are more results or that it is necessary to request a next page to determine whether there are more results, so thatnextPageRequest()will definitely not returnnull.- Returns:
falseif this is the last page of results.
-
hasPrevious
boolean hasPrevious()Returnstrueif it is known that there are previous results or that it is necessary to request the previous page to determine whether there are previous results, so thatpreviousPageRequest()will not returnnull.- Returns:
falseif this is the first page of results.
-
pageRequest
PageRequest pageRequest()Returns the page request for which this page was obtained.- Returns:
- the request for the current page; will never be
null.
-
nextPageRequest
PageRequest nextPageRequest()Returns a request for the next page ifhasNext()indicates there might be a next page.- Returns:
- a request for the next page.
- Throws:
NoSuchElementException- if it is known that there is no next page. To avoid this exception, check for atrueresult ofhasNext()before invoking this method.
-
previousPageRequest
PageRequest previousPageRequest()Returns a request for the previous page, if
hasPrevious()indicates there might be a previous page.- Returns:
- a request for the previous page.
- Throws:
NoSuchElementException- if it is known that there is no previous page. To avoid this exception, check for atrueresult ofhasPrevious()before invoking this method.
-
hasTotals
boolean hasTotals()Returnstrueif thepageRequest()specified that the total number of elements should be retrieved from the database, and that it is therefore safe to calltotalElements()ortotalPages().- Returns:
trueif totals are available.
-
totalElements
long totalElements()Returns the total number of elements across all pages of query results, if thepageRequest()specified that the total should be retrieved from the database.- Returns:
- the total number of elements across all pages.
- Throws:
IllegalStateException- if the total was not retrieved from the database.
-
totalPages
long totalPages()Returns the total number of pages of query results, if thepageRequest()specified that the total should be retrieved from the database.- Returns:
- the total number of pages.
- Throws:
IllegalStateException- if the total was not retrieved from the database.
-