Package st.orm

Record Class Pageable

Record Components:
pageNumber - the zero-based page index (must not be negative).
pageSize - the maximum number of elements per page (must be positive).
orders - the sort orders to apply (may be empty).

public record Pageable(int pageNumber, int pageSize, @Nonnull List<Pageable.Order> orders) extends Record
Represents a pagination request with a zero-based page number, page size, and optional sort orders.

Use ofSize(int) to create a request for the first page, or of(int, int) for a specific page. Add sort orders with sortBy(Metamodel) and sortByDescending(Metamodel). Navigation methods next() and previous() return new instances for adjacent pages, preserving sort orders.

Since:
1.10
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    Represents a sort order for a single metamodel field.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Pageable(int pageNumber, int pageSize)
    Creates a pageable request for the given page number and page size without sort orders.
    Pageable(int pageNumber, int pageSize, List<Pageable.Order> orders)
    Creates an instance of a Pageable record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns a pageable request for the next page, preserving sort orders.
    static Pageable
    of(int pageNumber, int pageSize)
    Creates a pageable request for the given page number and page size without sort orders.
    long
    Returns the offset to use for this page request.
    static Pageable
    ofSize(int pageSize)
    Creates a pageable request for the first page with the given page size.
    Returns the value of the orders record component.
    int
    Returns the value of the pageNumber record component.
    int
    Returns the value of the pageSize record component.
    Returns a pageable request for the previous page, or the first page if already on page 0.
    sortBy(Metamodel<?,?> field)
    Returns a new pageable with an ascending sort order appended for the given field.
    Returns a new pageable with a descending sort order appended for the given field.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Pageable

      public Pageable(int pageNumber, int pageSize, @Nonnull List<Pageable.Order> orders)
      Creates an instance of a Pageable record class.
      Parameters:
      pageNumber - the value for the pageNumber record component
      pageSize - the value for the pageSize record component
      orders - the value for the orders record component
    • Pageable

      public Pageable(int pageNumber, int pageSize)
      Creates a pageable request for the given page number and page size without sort orders.
      Parameters:
      pageNumber - the zero-based page index.
      pageSize - the maximum number of elements per page.
  • Method Details

    • of

      public static Pageable of(int pageNumber, int pageSize)
      Creates a pageable request for the given page number and page size without sort orders.
      Parameters:
      pageNumber - the zero-based page index.
      pageSize - the maximum number of elements per page.
      Returns:
      a pageable request.
    • ofSize

      public static Pageable ofSize(int pageSize)
      Creates a pageable request for the first page with the given page size.
      Parameters:
      pageSize - the maximum number of elements per page.
      Returns:
      a pageable request for page 0.
    • sortBy

      public Pageable sortBy(@Nonnull Metamodel<?,?> field)
      Returns a new pageable with an ascending sort order appended for the given field.
      Parameters:
      field - the metamodel field to sort by.
      Returns:
      a new pageable with the sort order added.
    • sortByDescending

      public Pageable sortByDescending(@Nonnull Metamodel<?,?> field)
      Returns a new pageable with a descending sort order appended for the given field.
      Parameters:
      field - the metamodel field to sort by in descending order.
      Returns:
      a new pageable with the sort order added.
    • next

      public Pageable next()
      Returns a pageable request for the next page, preserving sort orders.
      Returns:
      a pageable for the next page.
    • previous

      public Pageable previous()
      Returns a pageable request for the previous page, or the first page if already on page 0. Sort orders are preserved.
      Returns:
      a pageable for the previous page.
    • offset

      public long offset()
      Returns the offset to use for this page request.
      Returns:
      the offset as a long value.
    • 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.
    • pageNumber

      public int pageNumber()
      Returns the value of the pageNumber record component.
      Returns:
      the value of the pageNumber record component
    • pageSize

      public int pageSize()
      Returns the value of the pageSize record component.
      Returns:
      the value of the pageSize record component
    • orders

      @Nonnull public List<Pageable.Order> orders()
      Returns the value of the orders record component.
      Returns:
      the value of the orders record component