Class Pagination

    • Constructor Detail

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

      • 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
      • _endDocInclusiveIndex

        private static int _endDocInclusiveIndex​(int startDocIndex,
                                                 int resultsPerPage)
      • _endDocExclusiveIndex

        private static int _endDocExclusiveIndex​(int startDocIndex,
                                                 int resultsPerPage)
      • 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