java.lang.Object
org.ametys.web.frontoffice.search.requesttime.pagination.Pagination

public final class Pagination extends Object
The representation of a parameterized pagination (with params SearchService.PARAM_NAME_RESULTS_PER_PAGE and SearchService.PARAM_NAME_MAX_RESULTS) in a search service, and a fixed page index, providing convenient methods to retrieve counts and indexes.
  • Constructor Details

    • Pagination

      public Pagination(int pageIndex, Optional<Integer> paramResultsPerPage, Optional<Integer> paramMaxResults)
      Builds a pagination
      Parameters:
      pageIndex - The current page index. Must be greater or equal to 1
      paramResultsPerPage - The (optional) maximum number of allowed results for one page
      paramMaxResults - The (optional) maximum number of allowed results overall
  • Method Details

    • currentPageIndex

      public int currentPageIndex()
      Gets the current page index.
      The page index is on final user format, i.e. that the first index is 1 (not 0), etc.
      Returns:
      the current page index
    • currentStartDocIndex

      public int currentStartDocIndex()
      Gets the absolute index for the starting document in the current state (i.e. current page).
      Unlike currentPageIndex(), the first index is 0.
      For instance, if currentPageIndex() is 1, then it will always return 0.
      For instance, if currentPageIndex() is 5 and there are 3 results per page, it will return 12 (because page 1 holds results [0,1,2], page 2 holds results [3,4,5] and so on, and page 5 holds results [12,13,14]).
      Returns:
      the index for the starting document
    • currentEndDocExclusiveIndex

      public int currentEndDocExclusiveIndex(int totalHits)
      Gets the absolute index for the ending document in the current state (i.e. current page).
      For not breaking old expected indexes, this method returns the integer just after the one of the last doc (and thus this integer is not reached in current page). That's why it is called "exclusive".
      For instance:
      Parameters:
      totalHits - the number of total hits
      Returns:
      the (exclusive) index for the ending document
    • currentMaxNumberOfDocs

      public int currentMaxNumberOfDocs()
      Gets the maximum number of documents allowed in the current page
      For instance:
      Returns:
      the maximum number of documents allowed in the current page
    • numberOfPages

      public int numberOfPages(int totalHits)
      Given the number of total hits, gets the number of pages
      Parameters:
      totalHits - the number of total hits
      Returns:
      the number of pages