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>
Direct Known Subclasses:
BucketObjectsResponse

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.
  • Constructor Details

    • PageResponse

      public PageResponse()
    • PageResponse

      public PageResponse(List<T> content)
      Creates a new PageResponse with the given content. This will result in the created PageResponse being identical to the entire List.
      Parameters:
      content - must not be null.
    • PageResponse

      public PageResponse(List<T> content, PageRequest request, long total)
      Constructor of PageResponse with the given content and the given governing PageRequest.
      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 of PageResponse with the given content and the given governing PageRequest.
      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
      executedSearchTerm - search term being effectively used (may bechanged/normalized in comparance to original sent request search term) on server side for some reason
  • Method Details

    • builder

      public static PageResponse.Builder builder()
    • builder

      public static PageResponse.Builder builder(Class c)
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class ListResponse<T,PageRequest>
    • getNavItems

      public List<PageItem> getNavItems(int maxNumberOfItems)
      Utility method for creating a paging navigation.

      Based on the current page number a list (of maximum length of maxNumberOfItems) of navigation items is returned.

      The current page should be in the middle of the returned PageItems if possible (having enough previous and next pages).

      Each navigation item (PageItem contains a number (= label) and a flag if it is the current page.

      Examples:

      • current page is 1 (of e.g. 202 total pages), given maxNumberOfItems is 5: returning 5 page items for pages: [1], 2, 3, 4, 5
      • current page is 17 (of e.g. 202 total pages), given maxNumberOfItems is 5: returning 5 page items for pages: 15, 16, [17], 18, 19
      • current page is 201 (of e.g. 202 total pages), given maxNumberOfItems is 5: returning 4 page items for pages: 199, 200, [201], 202
      Parameters:
      maxNumberOfItems - maximum number of returned navigation items
      Returns:
      list of navigation items of type PageItem
    • getNumberOfElements

      public int getNumberOfElements()
      Returns the number of elements currently on this PageResponse.
      Returns:
      the number of elements currently on this PageResponse.
    • getPageNumber

      public int getPageNumber()
      Returns the number of the current PageResponse. Is always non-negative.
      Returns:
      the number of the current PageResponse.
    • getSize

      public int getSize()
      Returns the size of the PageResponse.
      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 next PageResponse.
      Returns:
      if there is a next PageResponse.
    • hasPrevious

      public boolean hasPrevious()
      Returns if there is a previous PageResponse.
      Returns:
      if there is a previous PageResponse.
    • init

      protected void init()
      Overrides:
      init in class ListResponse<T,PageRequest>
    • isFirst

      public boolean isFirst()
      Returns whether the current PageResponse is the first one.
      Returns:
      whether the current PageResponse is the first one.
    • isLast

      public boolean isLast()
      Returns whether the current PageResponse is the last one.
      Returns:
      whether the current PageResponse is the last one.
    • nextPageRequest

      public PageRequest nextPageRequest()
      Returns the PageRequest to request the next PageResponse. Can be null in case the current PageResponse is already the last one. Clients should check hasNext() before calling this method to make sure they receive a non-null value.
      Returns:
      the PageRequest to request the next PageResponse
    • previousPageRequest

      public PageRequest previousPageRequest()
      Returns the PageRequest to request the previous PageResponse. Can be null in case the current PageResponse is already the first one. Clients should check hasPrevious() before calling this method make sure receive a non-null value.
      Returns:
      the PageRequest to request the previous PageResponse
    • toString

      public String toString()
      Overrides:
      toString in class ListResponse<T,PageRequest>