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 class
PageResponse.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 newPageResponse
with the given content.PageResponse(List<T> content, PageRequest request, long total)
Constructor ofPageResponse
with the given content and the given governingPageRequest
.PageResponse(List<T> content, PageRequest request, long total, String executedSearchTerm)
Constructor ofPageResponse
with the given content and the given governingPageRequest
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PageResponse.Builder
builder()
static PageResponse.Builder
builder(Class c)
boolean
equals(Object obj)
int
getNumberOfElements()
Returns the number of elements currently on thisPageResponse
.int
getPageNumber()
Returns the number of the currentPageResponse
.int
getSize()
Returns the size of thePageResponse
.int
getTotalPages()
Returns the number of total pages.boolean
hasNext()
Returns if there is a nextPageResponse
.boolean
hasPrevious()
Returns if there is a previousPageResponse
.protected void
init()
boolean
isFirst()
Returns whether the currentPageResponse
is the first one.boolean
isLast()
Returns whether the currentPageResponse
is the last one.PageRequest
nextPageRequest()
Returns thePageRequest
to request the nextPageResponse
.PageRequest
previousPageRequest()
Returns thePageRequest
to request the previousPageResponse
.String
toString()
-
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 newPageResponse
with the given content. This will result in the createdPageResponse
being identical to the entireList
.- Parameters:
content
- must not be null.
-
PageResponse
public PageResponse(List<T> content, PageRequest request, long total)
Constructor ofPageResponse
with 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 ofPageResponse
with 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:
equals
in 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:
init
in classListResponse<T,PageRequest>
-
isFirst
public boolean isFirst()
Returns whether the currentPageResponse
is the first one.- Returns:
- whether the current
PageResponse
is the first one.
-
isLast
public boolean isLast()
Returns whether the currentPageResponse
is the last one.- Returns:
- whether the current
PageResponse
is the last one.
-
nextPageRequest
public PageRequest nextPageRequest()
Returns thePageRequest
to request the nextPageResponse
. Can be null in case the currentPageResponse
is already the last one. Clients should checkhasNext()
before calling this method to make sure they receive a non-null value.- Returns:
- the
PageRequest
to request the nextPageResponse
-
previousPageRequest
public PageRequest previousPageRequest()
Returns thePageRequest
to request the previousPageResponse
. Can be null in case the currentPageResponse
is already the first one. Clients should checkhasPrevious()
before calling this method make sure receive a non-null value.- Returns:
- the
PageRequest
to request the previousPageResponse
-
toString
public String toString()
- Overrides:
toString
in classListResponse<T,PageRequest>
-
-