public abstract class PagingUtils extends Object
Collection
,
Page
,
Pageable
,
PageableExecutionUtils
Modifier and Type | Field and Description |
---|---|
protected static Function<QueryMethod,Boolean> |
DEFAULT_IS_PAGE_QUERY_FUNCTION |
static String |
INVALID_PAGE_NUMBER_MESSAGE |
static String |
INVALID_PAGE_SIZE_MESSAGE |
static String |
NON_NULL_PAGEABLE_MESSAGE |
Constructor and Description |
---|
PagingUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
assertPageable(Pageable pageable)
Asserts that the
Pageable object is valid. |
static <T> List<T> |
getPagedList(List<T> list,
Pageable pageable)
Gets a page from the given
List . |
static Pageable |
getPageRequest(QueryMethod queryMethod,
Object... arguments)
Finds the
page request argument from an array of arguments passed to
the given QueryMethod . |
static int |
getQueryResultSetEndIndexForPage(Pageable pageable)
Null-safe method used to determine the end index in the query result set for populating the content
of the
Page . |
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 the
Page . |
static boolean |
isPageOne(Pageable pageable)
Null-safe method to determine whether the given
page request is for page one. |
static boolean |
isPagingPresent(QueryMethod queryMethod)
Null-safe method used to determine whether the given
QueryMethod 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 given
Page . |
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 given
Pageable . |
protected static long |
nullSafeSize(Iterable<?> iterable)
Null-safe method to determine the size (number of elements) of the
Iterable . |
static <T> Page<T> |
toPage(List<T> list,
Pageable pageable)
|
public static final String INVALID_PAGE_NUMBER_MESSAGE
public static final String INVALID_PAGE_SIZE_MESSAGE
public static final String NON_NULL_PAGEABLE_MESSAGE
protected static final Function<QueryMethod,Boolean> DEFAULT_IS_PAGE_QUERY_FUNCTION
public static void assertPageable(@NonNull Pageable pageable)
Pageable
object is valid.pageable
- Pageable
object to evaluate.IllegalArgumentException
- if Pageable
is null or page number is less than 0
or the page size is less than 1.Pageable
public static boolean isPageOne(@NonNull Pageable pageable)
page request
is for page one.pageable
- page request
to evaluate.page request
is for page one.Pageable
public static boolean isPagingPresent(@Nullable QueryMethod queryMethod)
QueryMethod
represents (models) a paged query.queryMethod
- QueryMethod
to evaluate for paging.QueryMethod
represents (models) a paged query.QueryMethod
@NonNull public static <T> List<T> getPagedList(@NonNull List<T> list, @NonNull Pageable pageable)
List
.
This method is null-safe, and guards against a null List
and Pageable
.T
- type
of the List
elements; must not be null.list
- List
from which to extract a page of elements; must not be null.pageable
- Pageable
object encapsulating the details for the page requested.sub-List
containing the contents for the requested page.getQueryResultSetStartIndexForPage(Pageable)
,
getQueryResultSetEndIndexForPage(Pageable)
,
Pageable
,
List
@NonNull public static Pageable getPageRequest(@NonNull QueryMethod queryMethod, @NonNull Object... arguments)
page request
argument from an array of arguments passed to
the given QueryMethod
.queryMethod
- invoked QueryMethod
; must not be null.arguments
- array of arguments
passed to the QueryMethod
;
must not be null.page request
argument in the array of arguments
passed to the QueryMethod
.IllegalArgumentException
- if QueryMethod
is null, or the QueryMethod
parameter
count is not equal to the argument count, or the indexed QueryMethod
argument is not an instance of
Pageable
.IllegalStateException
- if the QueryMethod
does not have a Pageable
parameter.QueryMethod
,
Pageable
public static int getQueryResultSetStartIndexForPage(@Nullable Pageable pageable)
Page
.pageable
- Pageable
object encapsulating the details of the requested Page
.Page
.Pageable
,
getQueryResultSetEndIndexForPage(Pageable)
public static int getQueryResultSetEndIndexForPage(@Nullable Pageable pageable)
Page
.pageable
- Pageable
object encapsulating the details of the requested Page
.Page
.Pageable
,
getQueryResultSetStartIndexForPage(Pageable)
public static int getQueryResultSetLimitForPage(@Nullable Pageable pageable)
public static int normalizePageNumber(@Nullable Page<?> page)
Page
.page
- Page
used to determine the page number to normalize.Page
,
normalize(int)
public static int normalizePageNumber(@Nullable Pageable pageable)
Pageable
.pageable
- Pageable
used to determine the page number to normalize.Pageable
,
normalize(int)
protected static int normalize(int pageNumber)
pageNumber
- The page number
to normalize.protected static long nullSafeSize(@Nullable Iterable<?> iterable)
Iterable
.
The Iterable
object may be an array, a Collection
or simply a stream backing,
pure Iterable
object.@NonNull public static <T> Page<T> toPage(@NonNull List<T> list, @NonNull Pageable pageable)
T
- type
of the List
elements.list
- List
of content from which to extract a Page
; must not be null.pageable
- Pageable
object encapsulating the details of the Page
requested;
must not be null.Page
view from the given List
based on the Pageable
object
(page request).Pageable
,
Page
,
getPagedList(List, Pageable)
,
List
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.