Class 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 Detail

      • PageResponse

        public PageResponse()
      • PageResponse

        public PageResponse​(List<T> content,
                            PageRequest pageRequest,
                            long total)
        Constructor of PageResponseImpl with the given content and the given governing PageRequest.
        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 new PageResponseImpl with the given content. This will result in the created PageResponse being identical to the entire List.
        Parameters:
        content - must not be null.
    • Method Detail

      • getContent

        public List<T> getContent()
        Returns:
        the page content/objects as List.
      • getNumber

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

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

        public PageRequest getPageRequest()
        Returns:
        the PageRequest used to get this 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 the PageResponse has content at all.
        Returns:
        whether the PageResponse has content at all.
      • hasPrevious

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

        public int hashCode()
        Overrides:
        hashCode in class Object
      • 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.
      • 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)