Package io.micronaut.data.model
Interface CursoredPage<T>
- Type Parameters:
T
- The generic type
@DefaultImplementation(io.micronaut.data.model.DefaultCursoredPage.class)
public interface CursoredPage<T>
extends Page<T>
Inspired by the Jakarta's
CursoredPage
, this models a type that supports
pagination operations with cursors.
A CursoredPage is a result set associated with a particular Pageable
that includes
a calculation of the total size of page of records.
- Since:
- 4.8.0
- Author:
- Andriy Dmytruk
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T2> @NonNull CursoredPage<T2>
empty()
Creates an empty page object.getCursor
(int i) Get cursor at the given position or empty if no such cursor exists.Get all the cursors.default int
Get the total count of pages that can be given by this query.long
Get the total count of all the records that can be given by this query.default boolean
hasNext()
Determine whether there is a next page.default boolean
Determine whether there is a previous page.boolean
default <T2> @NonNull CursoredPage<T2>
Maps the content with the given function.default CursoredPageable
Create a pageable for querying the next page of data.static <T> @NonNull CursoredPage<T>
of
(@NonNull List<T> content, @NonNull Pageable pageable, @Nullable List<Pageable.Cursor> cursors, @Nullable Long totalSize) Creates a cursored page from the given content, pageable, cursors and totalSize.default CursoredPageable
Create a pageable for querying the previous page of data.Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface io.micronaut.data.model.Slice
getContent, getNumberOfElements, getOffset, getPageable, getPageNumber, getSize, getSort, isEmpty, iterator
-
Field Details
-
EMPTY
-
-
Method Details
-
hasTotalSize
boolean hasTotalSize()- Specified by:
hasTotalSize
in interfacePage<T>
- Returns:
- Whether this
CursoredPage
contains the total count of the records - Since:
- 4.8.0
-
getTotalSize
long getTotalSize()Get the total count of all the records that can be given by this query. The method may produce aIllegalStateException
if thePageable
request did not ask for total size.- Specified by:
getTotalSize
in interfacePage<T>
- Returns:
- The total size of the all records.
-
getTotalPages
default int getTotalPages()Get the total count of pages that can be given by this query. The method may produce aIllegalStateException
if thePageable
request did not ask for total size.- Specified by:
getTotalPages
in interfacePage<T>
- Returns:
- The total page of pages
-
hasNext
default boolean hasNext()Description copied from interface:Slice
Determine whether there is a next page. -
hasPrevious
default boolean hasPrevious()Description copied from interface:Slice
Determine whether there is a previous page.- Specified by:
hasPrevious
in interfaceSlice<T>
- Returns:
- Whether there exist a previous page.
-
nextPageable
Description copied from interface:Slice
Create a pageable for querying the next page of data.A pageable may be created even if the end of data was reached to accommodate for cases when new data might be added to the repository. Use
Slice.hasNext()
to verify if you have reached the end.- Specified by:
nextPageable
in interfaceSlice<T>
- Returns:
- The next pageable
-
previousPageable
Description copied from interface:Slice
Create a pageable for querying the previous page of data.A pageable may be created even if the end of data was reached to accommodate for cases when new data might be added to the repository. Use
Slice.hasPrevious()
to verify if you have reached the end.- Specified by:
previousPageable
in interfaceSlice<T>
- Returns:
- The previous pageable
-
map
Maps the content with the given function. -
of
@NonNull static <T> @NonNull CursoredPage<T> of(@NonNull @NonNull List<T> content, @NonNull @NonNull Pageable pageable, @Nullable @Nullable List<Pageable.Cursor> cursors, @Nullable @Nullable Long totalSize) Creates a cursored page from the given content, pageable, cursors and totalSize.- Type Parameters:
T
- The generic type- Parameters:
content
- The contentpageable
- The pageablecursors
- The cursors for cursored paginationtotalSize
- The total size- Returns:
- The slice
-
getCursor
Get cursor at the given position or empty if no such cursor exists. There must be a cursor for each of the data entities in the same order. To start pagination after or before a cursor create a pageable from it using the same sorting as before.- Parameters:
i
- The index of cursor to retrieve.- Returns:
- The cursor at the provided index.
-
getCursors
List<Pageable.Cursor> getCursors()Get all the cursors.- Returns:
- All the cursors
- See Also:
-
empty
Creates an empty page object.- Type Parameters:
T2
- The generic type- Returns:
- The slice
-