Class PaginationResult<O>

java.lang.Object
org.nuiton.util.pagination.PaginationResult<O>
All Implemented Interfaces:
Serializable

public class PaginationResult<O> extends Object implements Serializable
Represents the result of a pagination request. It contains the result elements together with the PaginationParameter used to compute it. The class also contains methods to navigate through the other pages.
Since:
3.0
Author:
Arnaud Thimel (Code Lutin)
See Also:
  • Field Details

    • elements

      protected List<O> elements
    • count

      protected long count
    • currentPage

      protected PaginationParameter currentPage
  • Constructor Details

  • Method Details

    • of

      public static <T> PaginationResult<T> of(List<T> elements, long count, PaginationParameter currentPage)
      Creates an instance using the already computed list of {code}elements{/code} and {code}count{/count}, together with the {code}currentPage{/code} PaginationParameter used to build it.
      Type Parameters:
      T - any object type
      Parameters:
      elements - the list of elements
      count - the total number of elements (through all pages)
      currentPage - the PaginationParameter used to build this paged result
      Returns:
      the built instance of PaginationResult
    • fromFullList

      public static <T> PaginationResult<T> fromFullList(List<T> fullList, PaginationParameter requestedPage)
      Creates an instance using the full list of elements ({code}fullList{/code}) and the {code}requestedPage{/code} PaginationParameter. The built instance of PaginationResult will contain a sub list of the given {code}fullList{/code} parameter.
      Type Parameters:
      T - any object type
      Parameters:
      fullList - the full list of elements
      requestedPage - the PaginationParameter to use to build this paged result
      Returns:
      the built instance of PaginationResult.
    • empty

      public static <T> PaginationResult<T> empty(PaginationParameter requestedPage)
      Creates an instance for an empty result.
      Type Parameters:
      T - any object type
      Parameters:
      requestedPage - the PaginationParameter to use to build this paged result
      Returns:
      the built empty instance.
    • getElements

      public List<O> getElements()
    • getCount

      public long getCount()
    • getCurrentPage

      public PaginationParameter getCurrentPage()
    • getNextPage

      public PaginationParameter getNextPage()
    • getPreviousPage

      public PaginationParameter getPreviousPage()
    • getFirstPage

      public PaginationParameter getFirstPage()
    • getLastPage

      public PaginationParameter getLastPage()
    • getPageCount

      public int getPageCount()
    • hasNextPage

      public boolean hasNextPage()
    • hasPreviousPage

      public boolean hasPreviousPage()
    • transform

      public <T> PaginationResult<T> transform(Function<? super O, ? extends T> function)
      Creates an instance of PaginationResult transforming the current one using the given function for each element
    • transformAll

      public <T> PaginationResult<T> transformAll(Function<List<O>,List<T>> function)
      Creates an instance of PaginationResult transforming the current one using the given function for all elements