Record Class PageRecord<T>

java.lang.Object
java.lang.Record
jakarta.data.page.impl.PageRecord<T>
Type Parameters:
T - The type of elements on the page
Record Components:
pageRequest - The page request for which this page was obtained
content - The page content
totalElements - The total number of elements across all pages that can be requested for the query. A negative value indicates that a total count of elements and pages is not available.
moreResults - whether there is a (nonempty) next page of results
All Implemented Interfaces:
Page<T>, Iterable<T>

public record PageRecord<T>(PageRequest pageRequest, List<T> content, long totalElements, boolean moreResults) extends Record implements Page<T>
Record type implementing Page. This may be used to simplify implementation of a repository interface.
  • Constructor Details

    • PageRecord

      public PageRecord(PageRequest pageRequest, List<T> content, long totalElements)
      Constructs a new instance, computing the moreResults component as true if the page content is a full page of results and the totalElements is either unavailable (indicated by a negative value) or it exceeds the current page number multiplied by the size of a full page.
      Parameters:
      pageRequest - The page request for which this page was obtained.
      content - The page content.
      totalElements - The total number of elements across all pages that can be requested for the query. A negative value indicates that a total count of elements and pages is not available.
    • PageRecord

      public PageRecord(PageRequest pageRequest, List<T> content, long totalElements, boolean moreResults)
      Creates an instance of a PageRecord record class.
      Parameters:
      pageRequest - the value for the pageRequest record component
      content - the value for the content record component
      totalElements - the value for the totalElements record component
      moreResults - the value for the moreResults record component
  • Method Details

    • hasContent

      public boolean hasContent()
      Description copied from interface: Page
      Returns whether the Page has content at all.
      Specified by:
      hasContent in interface Page<T>
      Returns:
      whether the Page has content at all.
    • numberOfElements

      public int numberOfElements()
      Description copied from interface: Page
      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.
      Specified by:
      numberOfElements in interface Page<T>
      Returns:
      the number of elements on this Page.
    • hasNext

      public boolean hasNext()
      Description copied from interface: Page
      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 Page.nextPageRequest() will definitely not return null.
      Specified by:
      hasNext in interface Page<T>
      Returns:
      false if this is the last page of results.
    • nextPageRequest

      public PageRequest nextPageRequest()
      Description copied from interface: Page
      Returns a request for the next page if Page.hasNext() indicates there might be a next page.
      Specified by:
      nextPageRequest in interface Page<T>
      Returns:
      a request for the next page.
    • hasPrevious

      public boolean hasPrevious()
      Description copied from interface: Page
      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 Page.previousPageRequest() will not return null.
      Specified by:
      hasPrevious in interface Page<T>
      Returns:
      false if this is the first page of results.
    • previousPageRequest

      public PageRequest previousPageRequest()
      Description copied from interface: Page

      Returns a request for the previous page, if Page.hasPrevious() indicates there might be a previous page.

      Specified by:
      previousPageRequest in interface Page<T>
      Returns:
      a request for the previous page.
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • hasTotals

      public boolean hasTotals()
      Description copied from interface: Page
      Returns true if the Page.pageRequest() specified that the total number of elements should be retrieved from the database, and that it is therefore safe to call Page.totalElements() or Page.totalPages().
      Specified by:
      hasTotals in interface Page<T>
      Returns:
      true if totals are available.
    • totalElements

      public long totalElements()
      Returns the value of the totalElements record component.
      Specified by:
      totalElements in interface Page<T>
      Returns:
      the value of the totalElements record component
    • totalPages

      public long totalPages()
      Description copied from interface: Page
      Returns the total number of pages of query results, if the Page.pageRequest() specified that the total should be retrieved from the database.
      Specified by:
      totalPages in interface Page<T>
      Returns:
      the total number of pages.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • pageRequest

      public PageRequest pageRequest()
      Returns the value of the pageRequest record component.
      Specified by:
      pageRequest in interface Page<T>
      Returns:
      the value of the pageRequest record component
    • content

      public List<T> content()
      Returns the value of the content record component.
      Specified by:
      content in interface Page<T>
      Returns:
      the value of the content record component
    • moreResults

      public boolean moreResults()
      Returns the value of the moreResults record component.
      Returns:
      the value of the moreResults record component