Class PageResponse<T>
- java.lang.Object
-
- de.digitalcollections.model.list.ListResponse<T,PageRequest>
-
- de.digitalcollections.model.list.paging.PageResponse<T>
-
- Type Parameters:
T- object type listed in page
- All Implemented Interfaces:
Iterable<T>
public class PageResponse<T> extends ListResponse<T,PageRequest>
Container for pagination information. See Spring Data Commons, but more flat design and independent of Spring libraries.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPageResponse.Builder<T,B extends PageResponse<T>,C extends PageResponse.Builder>
-
Field Summary
-
Fields inherited from class de.digitalcollections.model.list.ListResponse
content, executedSearchTerm, request, total
-
-
Constructor Summary
Constructors Constructor Description PageResponse()PageResponse(List<T> content)Creates a newPageResponsewith the given content.PageResponse(List<T> content, PageRequest request, long total)Constructor ofPageResponsewith the given content and the given governingPageRequest.PageResponse(List<T> content, PageRequest request, long total, String executedSearchTerm)Constructor ofPageResponsewith the given content and the given governingPageRequest.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PageResponse.Builderbuilder()static PageResponse.Builderbuilder(Class c)booleanequals(Object obj)intgetNumberOfElements()Returns the number of elements currently on thisPageResponse.intgetPageNumber()Returns the number of the currentPageResponse.intgetSize()Returns the size of thePageResponse.intgetTotalPages()Returns the number of total pages.booleanhasNext()Returns if there is a nextPageResponse.booleanhasPrevious()Returns if there is a previousPageResponse.protected voidinit()booleanisFirst()Returns whether the currentPageResponseis the first one.booleanisLast()Returns whether the currentPageResponseis the last one.PageRequestnextPageRequest()Returns thePageRequestto request the nextPageResponse.PageRequestpreviousPageRequest()Returns thePageRequestto request the previousPageResponse.StringtoString()-
Methods inherited from class de.digitalcollections.model.list.ListResponse
getContent, getExecutedSearchTerm, getRequest, getSorting, getTotalElements, hasContent, hashCode, iterator, setContent, setExecutedSearchTerm, setRequest, setTotalElements
-
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)
Creates a newPageResponsewith the given content. This will result in the createdPageResponsebeing identical to the entireList.- Parameters:
content- must not be null.
-
PageResponse
public PageResponse(List<T> content, PageRequest request, long total)
Constructor ofPageResponsewith the given content and the given governingPageRequest.- Parameters:
content- the content of this page, must not be null.request- 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, PageRequest request, long total, String executedSearchTerm)
Constructor ofPageResponsewith the given content and the given governingPageRequest.- Parameters:
content- the content of this page, must not be null.request- 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 inconsistenciesexecutedSearchTerm- search term being effectively used (may bechanged/normalized in comparance to original sent request search term) on server side for some reason
-
-
Method Detail
-
builder
public static PageResponse.Builder builder()
-
builder
public static PageResponse.Builder builder(Class c)
-
equals
public boolean equals(Object obj)
- Overrides:
equalsin classListResponse<T,PageRequest>
-
getNumberOfElements
public int getNumberOfElements()
Returns the number of elements currently on thisPageResponse.- Returns:
- the number of elements currently on this
PageResponse.
-
getPageNumber
public int getPageNumber()
Returns the number of the currentPageResponse. Is always non-negative.- Returns:
- the number of the current
PageResponse.
-
getSize
public int getSize()
Returns the size of thePageResponse.- Returns:
- the size of the
PageResponse.
-
getTotalPages
public int getTotalPages()
Returns the number of total pages.- Returns:
- the number of total pages
-
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.
-
init
protected void init()
- Overrides:
initin classListResponse<T,PageRequest>
-
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
-
toString
public String toString()
- Overrides:
toStringin classListResponse<T,PageRequest>
-
-