Module jakarta.data

Interface Page<T>

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

public interface Page<T> extends Iterable<T>

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 Details

    • content

      List<T> content()
      Returns the page content as a List. 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 be null.
    • hasContent

      boolean hasContent()
      Returns whether the Page has content at all.
      Returns:
      whether the Page has content at all.
    • stream

      default Stream<T> 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 this Page, which must be no larger than the maximum size of 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()
      Returns true if 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 that nextPageRequest() will definitely not return null.
      Returns:
      false if this is the last page of results.
    • hasPrevious

      boolean hasPrevious()
      Returns true if 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 that previousPageRequest() will not return null.
      Returns:
      false if 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 if hasNext() 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 a true result of hasNext() 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 a true result of hasPrevious() before invoking this method.
    • hasTotals

      boolean hasTotals()
      Returns true if the pageRequest() specified that the total number of elements should be retrieved from the database, and that it is therefore safe to call totalElements() or totalPages().
      Returns:
      true if totals are available.
    • totalElements

      long totalElements()
      Returns the total number of elements across all pages of query results, if the pageRequest() 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 the pageRequest() 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.