Record Class PageResult<T>

java.lang.Object
java.lang.Record
com.vertyll.freshly.lang.page.PageResult<T>
Type Parameters:
T - a domain model

public record PageResult<T>(List<T> content, int page, int size, long totalElements) extends Record
One page as a repository hands it back.

Paired with PagedResponse, which is what a query use case returns. The split is deliberate: this one holds domain models and has whatever shape paging needs, that one holds DTOs and has the shape the API promises. Collapsing them would make the storage adapter's convenience into the client's contract.

So this type should not appear above a repository port. PagedResponse.from is the crossing point, and the only place both are named.

  • Constructor Summary

    Constructors
    Constructor
    Description
    PageResult(List<T> content, int page, int size, long totalElements)
    Creates an instance of a PageResult record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the content record component.
    static <T> PageResult<T>
    empty(PageRequest request)
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    <R> PageResult<R>
    map(Function<? super T, ? extends R> mapper)
    Maps the content while keeping the paging metadata, so an adapter can turn a page of domain models into a page of DTOs without restating the counts.
    int
    Returns the value of the page record component.
    int
    Returns the value of the size record component.
    final String
    Returns a string representation of this record class.
    long
    Returns the value of the totalElements record component.
    int
     

    Methods inherited from class Object

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

    • PageResult

      public PageResult(List<T> content, int page, int size, long totalElements)
      Creates an instance of a PageResult record class.
      Parameters:
      content - the value for the content record component
      page - the value for the page record component
      size - the value for the size record component
      totalElements - the value for the totalElements record component
  • Method Details

    • empty

      public static <T> PageResult<T> empty(PageRequest request)
    • totalPages

      public int totalPages()
    • map

      public <R> PageResult<R> map(Function<? super T, ? extends R> mapper)
      Maps the content while keeping the paging metadata, so an adapter can turn a page of domain models into a page of DTOs without restating the counts.
    • 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 the compare method from their corresponding wrapper classes.
      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.
    • content

      public List<T> content()
      Returns the value of the content record component.
      Returns:
      the value of the content record component
    • page

      public int page()
      Returns the value of the page record component.
      Returns:
      the value of the page record component
    • size

      public int size()
      Returns the value of the size record component.
      Returns:
      the value of the size record component
    • totalElements

      public long totalElements()
      Returns the value of the totalElements record component.
      Returns:
      the value of the totalElements record component