Package org.kiwiproject.spring.data
Class KiwiPage<T>
java.lang.Object
org.kiwiproject.spring.data.KiwiPage<T>
- Type Parameters:
T- the type of content this page contains
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 -
Method Summary
Modifier and TypeMethodDescriptionaddKiwiSort(KiwiSort sort) Adds the given sort, returning this instance for method chaining.The content on this specific page.longThe number of this page, e.g. page X of Y.longThe number of items/elements on this page.intAllows adjustment for instances where pagination starts with one instead of zero.longgetSize()The size limit of the pagination, for example each page can have up to 25 items.getSort()Describes any sort that is active for the pagination.longThe total number of items/elements in the overall result list.longThe total number of pages, calculated from the page size and total number of elements.booleanisFirst()Determines if this is the first page when paginating a result list.booleanisLast()Determines if this is the last page when paginating a result list.booleanisSorted()Does this page have a sort applied?static <T> KiwiPage<T>Create a new instance.voidsetContent(List<T> content) The content on this specific page.voidsetNumber(long number) The number of this page, e.g. page X of Y.voidsetNumberOfElements(long numberOfElements) The number of items/elements on this page.voidsetPagingStartsWith(int pagingStartsWith) Allows adjustment for instances where pagination starts with one instead of zero.voidsetSize(long size) The size limit of the pagination, for example each page can have up to 25 items.voidDescribes any sort that is active for the pagination.voidsetTotalElements(long totalElements) The total number of items/elements in the overall result list.voidsetTotalPages(long totalPages) The total number of pages, calculated from the page size and total number of elements.toString()SetspagingStartsWithto zero, so that pagination assumes one-based page numbering.SetspagingStartsWithto zero, so that pagination assumes zero-based page numbering.
-
Constructor Details
-
KiwiPage
public KiwiPage()
-
-
Method Details
-
of
Create a new instance.If you need to add a sort or change
pagingStartsWith, you can chain theaddKiwiSort(KiwiSort)andusingOneAsFirstPage()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 limittotal- the total number of elements in the overall result listcontentList- the content on this page- Returns:
- a new instance
- Throws:
IllegalStateException- if any of the numeric arguments are negative or the limit is zeroIllegalArgumentException- if contentList is null
-
addKiwiSort
Adds the given sort, returning this instance for method chaining.- Parameters:
sort- the sort to add- Returns:
- this instance
-
usingZeroAsFirstPage
SetspagingStartsWithto 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
SetspagingStartsWithto 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
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
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
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
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
-