Class KiwiPage<T>

java.lang.Object
org.kiwiproject.spring.data.KiwiPage<T>
Type Parameters:
T - the type of content this page contains

public class KiwiPage<T> extends Object
Represents one page of an overall list of results.

By default, pagination assumes a start page index of 0 (i.e. the page offset). You can change this by calling setPagingStartsWith(int) or usingOneAsFirstPage().

You can also indicate whether a sort has been applied to the data by setting the KiwiSort via the setter method or via addKiwiSort(KiwiSort).

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Adds the given sort, returning this instance for method chaining.
    The content on this specific page.
    long
    The number of this page, e.g. page X of Y.
    long
    The number of items/elements on this page.
    int
    Allows adjustment for instances where pagination starts with one instead of zero.
    long
    The size limit of the pagination, for example each page can have up to 25 items.
    Describes any sort that is active for the pagination.
    long
    The total number of items/elements in the overall result list.
    long
    The total number of pages, calculated from the page size and total number of elements.
    boolean
    Determines if this is the first page when paginating a result list.
    boolean
    Determines if this is the last page when paginating a result list.
    boolean
    Does this page have a sort applied?
    static <T> KiwiPage<T>
    of(long pageNum, long limit, long total, List<T> contentList)
    Create a new instance.
    void
    setContent(List<T> content)
    The content on this specific page.
    void
    setNumber(long number)
    The number of this page, e.g. page X of Y.
    void
    setNumberOfElements(long numberOfElements)
    The number of items/elements on this page.
    void
    setPagingStartsWith(int pagingStartsWith)
    Allows adjustment for instances where pagination starts with one instead of zero.
    void
    setSize(long size)
    The size limit of the pagination, for example each page can have up to 25 items.
    void
    Describes any sort that is active for the pagination.
    void
    setTotalElements(long totalElements)
    The total number of items/elements in the overall result list.
    void
    setTotalPages(long totalPages)
    The total number of pages, calculated from the page size and total number of elements.
     
    Sets pagingStartsWith to zero, so that pagination assumes one-based page numbering.
    Sets pagingStartsWith to zero, so that pagination assumes zero-based page numbering.

    Methods inherited from class java.lang.Object

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

    • KiwiPage

      public KiwiPage()
  • Method Details

    • of

      public static <T> KiwiPage<T> of(long pageNum, long limit, long total, List<T> contentList)
      Create a new instance.

      If you need to add a sort or change pagingStartsWith, you can chain the addKiwiSort(KiwiSort) and usingOneAsFirstPage() in a fluent style.

      Type Parameters:
      T - the type of elements on this page
      Parameters:
      pageNum - the number of this page, can be 0 or 1-based (0 is the default)
      limit - the page size limit
      total - the total number of elements in the overall result list
      contentList - the content on this page
      Returns:
      a new instance
      Throws:
      IllegalStateException - if any of the numeric arguments are negative or the limit is zero
      IllegalArgumentException - if contentList is null
    • addKiwiSort

      public KiwiPage<T> addKiwiSort(KiwiSort sort)
      Adds the given sort, returning this instance for method chaining.
      Parameters:
      sort - the sort to add
      Returns:
      this instance
    • usingZeroAsFirstPage

      public KiwiPage<T> usingZeroAsFirstPage()
      Sets pagingStartsWith to zero, so that pagination assumes zero-based page numbering.

      This can also be done via the setter method, but it does not permit method chaining.

      Returns:
      this instance
    • usingOneAsFirstPage

      public KiwiPage<T> usingOneAsFirstPage()
      Sets pagingStartsWith to zero, so that pagination assumes one-based page numbering.

      This can also be done via the setter method, but it does not permit method chaining.

      Returns:
      this instance
    • isFirst

      public boolean isFirst()
      Determines if this is the first page when paginating a result list.
      Returns:
      true if this is the first page
    • isLast

      public boolean isLast()
      Determines if this is the last page when paginating a result list.
      Returns:
      true if this is the last page
    • isSorted

      public boolean isSorted()
      Does this page have a sort applied?
      Returns:
      true if this page has a sort applied
    • getContent

      public List<T> getContent()
      The content on this specific page.
    • getSize

      public long getSize()
      The size limit of the pagination, for example each page can have up to 25 items. The last page will often contain fewer items than this limit unless the total number of items is such that there is no remainder when dividing the total by the page size. e.g. if the total number of items is 100 and the page size is 20, then each of the 5 pages has exactly 20 items (the page size).
    • getNumber

      public long getNumber()
      The number of this page, e.g. page X of Y.
    • getNumberOfElements

      public long getNumberOfElements()
      The number of items/elements on this page. Only on the last page can this be different
    • getTotalPages

      public long getTotalPages()
      The total number of pages, calculated from the page size and total number of elements.
    • getTotalElements

      public long getTotalElements()
      The total number of items/elements in the overall result list.
    • getSort

      public KiwiSort getSort()
      Describes any sort that is active for the pagination. Default value is null.
    • getPagingStartsWith

      public int getPagingStartsWith()
      Allows adjustment for instances where pagination starts with one instead of zero.
    • setContent

      public void setContent(List<T> content)
      The content on this specific page.
    • setSize

      public void setSize(long size)
      The size limit of the pagination, for example each page can have up to 25 items. The last page will often contain fewer items than this limit unless the total number of items is such that there is no remainder when dividing the total by the page size. e.g. if the total number of items is 100 and the page size is 20, then each of the 5 pages has exactly 20 items (the page size).
    • setNumber

      public void setNumber(long number)
      The number of this page, e.g. page X of Y.
    • setNumberOfElements

      public void setNumberOfElements(long numberOfElements)
      The number of items/elements on this page. Only on the last page can this be different
    • setTotalPages

      public void setTotalPages(long totalPages)
      The total number of pages, calculated from the page size and total number of elements.
    • setTotalElements

      public void setTotalElements(long totalElements)
      The total number of items/elements in the overall result list.
    • setSort

      public void setSort(KiwiSort sort)
      Describes any sort that is active for the pagination. Default value is null.
    • setPagingStartsWith

      public void setPagingStartsWith(int pagingStartsWith)
      Allows adjustment for instances where pagination starts with one instead of zero.
    • toString

      public String toString()
      Overrides:
      toString in class Object