Class PageResponse<T>
- java.lang.Object
-
- de.digitalcollections.model.paging.PageResponse<T>
-
- Type Parameters:
T- object type listed in page
- All Implemented Interfaces:
Iterable<T>
- Direct Known Subclasses:
SearchPageResponse
public class PageResponse<T> extends Object implements Iterable<T>
Container for pagination information. See Spring Data Commons, but more flat design and independent of Spring libraries. TODO: add Builder, @see PageRequest
-
-
Constructor Summary
Constructors Constructor Description PageResponse()PageResponse(List<T> content)Creates a newPageResponseImplwith the given content.PageResponse(List<T> content, PageRequest pageRequest, long total)Constructor ofPageResponseImplwith the given content and the given governingPageRequest.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)List<T>getContent()intgetNumber()Returns the number of the currentPageResponse.intgetNumberOfElements()Returns the number of elements currently on thisPageResponse.PageRequestgetPageRequest()intgetSize()Returns the size of thePageResponse.SortinggetSorting()longgetTotalElements()Returns the total amount of elements.intgetTotalPages()Returns the number of total pages.booleanhasContent()Returns whether thePageResponsehas content at all.inthashCode()booleanhasNext()Returns if there is a nextPageResponse.booleanhasPrevious()Returns if there is a previousPageResponse.booleanisFirst()Returns whether the currentPageResponseis the first one.booleanisLast()Returns whether the currentPageResponseis the last one.Iterator<T>iterator()PageRequestnextPageRequest()Returns thePageRequestto request the nextPageResponse.PageRequestpreviousPageRequest()Returns thePageRequestto request the previousPageResponse.voidsetContent(List<T> content)Allows to set the content (needed in case of content has to be converted/casted)voidsetPageRequest(PageRequest pageRequest)voidsetTotalElements(long totalElements)StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
PageResponse
public PageResponse()
-
PageResponse
public PageResponse(List<T> content, PageRequest pageRequest, long total)
Constructor ofPageResponseImplwith the given content and the given governingPageRequest.- Parameters:
content- the content of this page, must not be null.pageRequest- the paging information, can be null.total- the total amount of items available. The total might be adapted considering the length of the content given, if it is going to be the content of the last page. This is in place to mitigate inconsistencies
-
PageResponse
public PageResponse(List<T> content)
Creates a newPageResponseImplwith the given content. This will result in the createdPageResponsebeing identical to the entireList.- Parameters:
content- must not be null.
-
-
Method Detail
-
getNumber
public int getNumber()
Returns the number of the currentPageResponse. Is always non-negative.- Returns:
- the number of the current
PageResponse.
-
getNumberOfElements
public int getNumberOfElements()
Returns the number of elements currently on thisPageResponse.- Returns:
- the number of elements currently on this
PageResponse.
-
getPageRequest
public PageRequest getPageRequest()
- Returns:
- the PageRequest used to get this PageResponse
-
getSize
public int getSize()
Returns the size of thePageResponse.- Returns:
- the size of the
PageResponse.
-
getSorting
public Sorting getSorting()
- Returns:
- the sorting parameters for the
PageResponse.
-
getTotalElements
public long getTotalElements()
Returns the total amount of elements.- Returns:
- the total amount of elements
-
getTotalPages
public int getTotalPages()
Returns the number of total pages.- Returns:
- the number of total pages
-
hasContent
public boolean hasContent()
Returns whether thePageResponsehas content at all.- Returns:
- whether the
PageResponsehas content at all.
-
hasNext
public boolean hasNext()
Returns if there is a nextPageResponse.- Returns:
- if there is a next
PageResponse.
-
hasPrevious
public boolean hasPrevious()
Returns if there is a previousPageResponse.- Returns:
- if there is a previous
PageResponse.
-
isFirst
public boolean isFirst()
Returns whether the currentPageResponseis the first one.- Returns:
- whether the current
PageResponseis the first one.
-
isLast
public boolean isLast()
Returns whether the currentPageResponseis the last one.- Returns:
- whether the current
PageResponseis the last one.
-
nextPageRequest
public PageRequest nextPageRequest()
Returns thePageRequestto request the nextPageResponse. Can be null in case the currentPageResponseis already the last one. Clients should checkhasNext()before calling this method to make sure they receive a non-null value.- Returns:
- the
PageRequestto request the nextPageResponse
-
previousPageRequest
public PageRequest previousPageRequest()
Returns thePageRequestto request the previousPageResponse. Can be null in case the currentPageResponseis already the first one. Clients should checkhasPrevious()before calling this method make sure receive a non-null value.- Returns:
- the
PageRequestto request the previousPageResponse
-
setContent
public void setContent(List<T> content)
Allows to set the content (needed in case of content has to be converted/casted)- Parameters:
content- list of content/objects of this page
-
setPageRequest
public void setPageRequest(PageRequest pageRequest)
-
setTotalElements
public void setTotalElements(long totalElements)
-
-