Class Pagination
java.lang.Object
org.ametys.web.frontoffice.search.requesttime.pagination.Pagination
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 Summary
ConstructorDescriptionPagination
(int pageIndex, Optional<Integer> paramResultsPerPage, Optional<Integer> paramMaxResults) Builds a pagination -
Method Summary
Modifier and TypeMethodDescriptionint
currentEndDocExclusiveIndex
(int totalHits) Gets the absolute index for the ending document in the current state (i.e.int
Gets the maximum number of documents allowed in the current page
For instance: let's say thecurrentPageIndex()
is 1 (socurrentStartDocIndex()
is 0) and there are 3results per page
, then the page has the capacity for potential results [0,1,2] and this methods returns 3.int
Gets the current page index.int
Gets the absolute index for the starting document in the current state (i.e.int
numberOfPages
(int totalHits) Given the number of total hits, gets the number of pages
-
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 1paramResultsPerPage
- The (optional) maximum number of allowed results for one pageparamMaxResults
- The (optional) maximum number of allowed results overall
-
-
Method Details
-
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
Gets the absolute index for the starting document in the current state (i.e. current page).
UnlikecurrentPageIndex()
, the first index is 0.
For instance, ifcurrentPageIndex()
is 1, then it will always return 0.
For instance, ifcurrentPageIndex()
is 5 and there are 3results 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
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:-
let's say the
currentPageIndex()
is 1 (socurrentStartDocIndex()
is 0) and there are 3results per page
, and totalHits=100, then the page holds results [0,1,2] and this methods returns 3. -
let's say the
currentPageIndex()
is 5 (socurrentStartDocIndex()
is 12) and there are 3results per page
, and totalHits=100, then the page holds results [12,13,14] and this methods returns 15. -
let's say the
currentPageIndex()
is 5 (socurrentStartDocIndex()
is 12) and there are 3results per page
, and totalHits=13, then the page holds results [12] and this methods returns 13. -
let's say the
currentPageIndex()
is 5 (socurrentStartDocIndex()
is 12) and there are 3results per page
and there are 14max results
, and totalHits=100, then the page holds results [12,13] and this methods returns 14.
- Parameters:
totalHits
- the number of total hits- Returns:
- the (exclusive) index for the ending document
-
let's say the
-
currentMaxNumberOfDocs
Gets the maximum number of documents allowed in the current page
For instance:-
let's say the
currentPageIndex()
is 1 (socurrentStartDocIndex()
is 0) and there are 3results per page
, then the page has the capacity for potential results [0,1,2] and this methods returns 3. -
let's say the
currentPageIndex()
is 5 (socurrentStartDocIndex()
is 12) and there are 3results per page
, then the page has the capacity for potential results [12,13,14] and then this methods returns 3. -
let's say the
currentPageIndex()
is 5 (socurrentStartDocIndex()
is 12) and there are 3results per page
and there are 14max results
, then the page has the capacity for potential results [12,13] and then this methods returns 2.
- Returns:
- the maximum number of documents allowed in the current page
-
let's say the
-
numberOfPages
Given the number of total hits, gets the number of pages- Parameters:
totalHits
- the number of total hits- Returns:
- the number of pages
-