Class Page<T>

java.lang.Object
org.apache.juneau.commons.beanquery.Page<T>
Type Parameters:
T - The row type.

public final class Page<T> extends Object
One page of query results, plus the optional counts selected by the session's CountPolicy.
  • total(): rows that pass the guards (before the search).
  • matched(): rows that pass the guards and the search.

Under CountPolicy.NONE neither count is present. Under CountPolicy.MATCHED only matched() is. Under CountPolicy.BOTH both are. Counts are opt-in and independent of each other: a caller that did not ask for a count gets an empty OptionalLong back rather than an exception, so "was a count computed" and "read the count" are the same call.

Example:

Page<Person> page = session.find(BeanQuery.create().counts(CountRequest.BOTH).build()); for (Person p : page.rows()) render(p); page.total().ifPresent(total -> renderFooter(page.matched().getAsLong() + " of " + total));

Since:
10.0.0
  • Method Details

    • of

      public static <T> Page<T> of(List<T> rows)
      Creates a page without counts.
      Type Parameters:
      T - The row type.
      Parameters:
      rows - The rows. Must not be null or contain null.
      Returns:
      A new page.
    • of

      public static <T> Page<T> of(List<T> rows, long total, long matched)
      Creates a page with both counts.
      Type Parameters:
      T - The row type.
      Parameters:
      rows - The rows. Must not be null or contain null.
      total - The number of rows that pass the guards.
      matched - The number of rows that pass the guards and the search.
      Returns:
      A new page.
    • ofMatched

      public static <T> Page<T> ofMatched(List<T> rows, long matched)
      Creates a page with only the matched count.
      Type Parameters:
      T - The row type.
      Parameters:
      rows - The rows. Must not be null or contain null.
      matched - The number of rows that pass the guards and the search.
      Returns:
      A new page.
    • rows

      public List<T> rows()
      Returns the rows of this page.
      Returns:
      An unmodifiable list (never null).
    • total

      public OptionalLong total()
      The number of rows in scope before the query's search (after any server-only guard).
      Returns:
      The total row count, or empty if it was not requested.
    • matched

      The number of rows that survive the search, before any page limit.
      Returns:
      The matched row count, or empty if it was not requested.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object