Class PagingUtils
java.lang.Object
org.springframework.data.gemfire.repository.query.support.PagingUtils
- Since:
- 2.4.0
- Author:
- John Blum
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertPageable
(Pageable pageable) Asserts that thePageable
object is valid.static <T> List<T>
getPagedList
(List<T> list, Pageable pageable) Gets a page from the givenList
.static Pageable
getPageRequest
(QueryMethod queryMethod, Object... arguments) Finds thepage request
argument from an array of arguments passed to the givenQueryMethod
.static int
getQueryResultSetEndIndexForPage
(Pageable pageable) Null-safe method used to determine the end index in the query result set for populating the content of thePage
.static int
getQueryResultSetLimitForPage
(Pageable pageable) static int
getQueryResultSetStartIndexForPage
(Pageable pageable) Null-safe method used to determine the starting index in the query result set for populating the content of thePage
.static boolean
Null-safe method to determine whether the givenpage request
is for page one.static boolean
isPagingPresent
(QueryMethod queryMethod) Null-safe method used to determine whether the givenQueryMethod
represents (models) a paged query.protected static int
normalize
(int pageNumber) Normalizes 0 index based page numbers (i.e. 0, 1, 2, ...) to natural page numbers (i.e. 1, 2, 3, ...).static int
normalizePageNumber
(Page<?> page) Null-safe method used to normalize 0 index based page numbers (i.e. 0, 1, 2, ...) to natural page numbers (i.e. 1, 2, 3, ...) using the givenPage
.static int
normalizePageNumber
(Pageable pageable) Null-safe method used to normalize 0 index based page numbers (i.e. 0, 1, 2, ...) to natural page numbers (i.e. 1, 2, 3, ...) using the givenPageable
.protected static long
nullSafeSize
(Iterable<?> iterable) Null-safe method to determine the size (number of elements) of theIterable
.static <T> Page<T>
-
Field Details
-
INVALID_PAGE_NUMBER_MESSAGE
- See Also:
-
INVALID_PAGE_SIZE_MESSAGE
- See Also:
-
NON_NULL_PAGEABLE_MESSAGE
- See Also:
-
DEFAULT_IS_PAGE_QUERY_FUNCTION
-
-
Constructor Details
-
PagingUtils
public PagingUtils()
-
-
Method Details
-
assertPageable
Asserts that thePageable
object is valid.- Parameters:
pageable
-Pageable
object to evaluate.- Throws:
IllegalArgumentException
- ifPageable
is null or page number is less than 0 or the page size is less than 1.- See Also:
-
isPageOne
Null-safe method to determine whether the givenpage request
is for page one.- Parameters:
pageable
-page request
to evaluate.- Returns:
- a boolean value indicating whether the given
page request
is for page one. - See Also:
-
isPagingPresent
Null-safe method used to determine whether the givenQueryMethod
represents (models) a paged query.- Parameters:
queryMethod
-QueryMethod
to evaluate for paging.- Returns:
- a boolean value indicating whether the given
QueryMethod
represents (models) a paged query. - See Also:
-
getPagedList
Gets a page from the givenList
. This method is null-safe, and guards against a nullList
andPageable
.- Type Parameters:
T
-type
of theList
elements; must not be null.- Parameters:
list
-List
from which to extract a page of elements; must not be null.pageable
-Pageable
object encapsulating the details for the page requested.- Returns:
- a
sub-List
containing the contents for the requested page. - See Also:
-
getPageRequest
@NonNull public static Pageable getPageRequest(@NonNull QueryMethod queryMethod, @NonNull Object... arguments) Finds thepage request
argument from an array of arguments passed to the givenQueryMethod
.- Parameters:
queryMethod
- invokedQueryMethod
; must not be null.arguments
- array ofarguments
passed to theQueryMethod
; must not be null.- Returns:
- the
page request
argument in the array ofarguments
passed to theQueryMethod
. - Throws:
IllegalArgumentException
- ifQueryMethod
is null, or theQueryMethod
parameter count is not equal to the argument count, or the indexedQueryMethod
argument is not an instance ofPageable
.IllegalStateException
- if theQueryMethod
does not have aPageable
parameter.- See Also:
-
getQueryResultSetStartIndexForPage
Null-safe method used to determine the starting index in the query result set for populating the content of thePage
. -
getQueryResultSetEndIndexForPage
Null-safe method used to determine the end index in the query result set for populating the content of thePage
. -
getQueryResultSetLimitForPage
-
normalizePageNumber
Null-safe method used to normalize 0 index based page numbers (i.e. 0, 1, 2, ...) to natural page numbers (i.e. 1, 2, 3, ...) using the givenPage
.- Parameters:
page
-Page
used to determine the page number to normalize.- Returns:
- the normalized page number from the 0 index based page number.
- See Also:
-
normalizePageNumber
Null-safe method used to normalize 0 index based page numbers (i.e. 0, 1, 2, ...) to natural page numbers (i.e. 1, 2, 3, ...) using the givenPageable
.- Parameters:
pageable
-Pageable
used to determine the page number to normalize.- Returns:
- the normalized page number from the 0 index based page number.
- See Also:
-
normalize
protected static int normalize(int pageNumber) Normalizes 0 index based page numbers (i.e. 0, 1, 2, ...) to natural page numbers (i.e. 1, 2, 3, ...).- Parameters:
pageNumber
- Thepage number
to normalize.- Returns:
- the normalized page number from the 0 index based page number.
-
nullSafeSize
Null-safe method to determine the size (number of elements) of theIterable
. TheIterable
object may be an array, aCollection
or simply a stream backing, pureIterable
object. -
toPage
- Type Parameters:
T
-type
of theList
elements.- Parameters:
list
-List
of content from which to extract aPage
; must not be null.pageable
-Pageable
object encapsulating the details of thePage
requested; must not be null.- Returns:
- a non-null
Page
view from the givenList
based on thePageable
object (page request). - See Also:
-