Class Pagination
- java.lang.Object
-
- org.ametys.web.frontoffice.search.requesttime.pagination.Pagination
-
public final class Pagination extends Object
The representation of a parameterized pagination (with paramsSearchService.PARAM_NAME_RESULTS_PER_PAGE
andSearchService.PARAM_NAME_MAX_RESULTS
) in a search service, and a fixed page index, providing convenient methods to retrieve counts and indexes.
-
-
Field Summary
Fields Modifier and Type Field Description private int
_pageIndex
private Optional<Integer>
_paramMaxResults
private Optional<Integer>
_paramResultsPerPage
-
Constructor Summary
Constructors Constructor Description Pagination(int pageIndex, Optional<Integer> paramResultsPerPage, Optional<Integer> paramMaxResults)
Builds a pagination
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
_currentNumberOfDocs(int totalHits)
private int
_currentStartDocIndex(int resultsPerPage)
private static int
_endDocExclusiveIndex(int startDocIndex, int resultsPerPage)
private static int
_endDocInclusiveIndex(int startDocIndex, int resultsPerPage)
int
currentEndDocExclusiveIndex(int totalHits)
Gets the absolute index for the ending document in the current state (i.e.int
currentMaxNumberOfDocs()
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
currentPageIndex()
Gets the current page index.int
currentStartDocIndex()
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
-
-
-
Field Detail
-
_pageIndex
private int _pageIndex
-
_paramResultsPerPage
private Optional<Integer> _paramResultsPerPage
-
_paramMaxResults
private Optional<Integer> _paramMaxResults
-
-
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 1paramResultsPerPage
- The (optional) maximum number of allowed results for one pageparamMaxResults
- 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).
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
-
_currentStartDocIndex
private int _currentStartDocIndex(int resultsPerPage)
-
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:-
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
-
_currentNumberOfDocs
private int _currentNumberOfDocs(int totalHits)
-
currentMaxNumberOfDocs
public int 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
-
_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
-
-