Package org.springframework.data.domain
Interface Window<T>
- All Superinterfaces:
Iterable<T>
,Streamable<T>
,Supplier<Stream<T>>
A set of data consumed from an underlying query result. A
Window
is similar to Slice
in the sense
that it contains a subset of the actual query results for easier scrolling across large result sets. The window is
less opinionated about the actual data retrieval, whether the query has used index/offset, keyset-based pagination or
cursor resume tokens.- Since:
- 3.1
- Author:
- Mark Paluch, Christoph Strobl
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Window<T>
from
(List<T> items, IntFunction<? extends ScrollPosition> positionFunction) Construct aWindow
.static <T> Window<T>
from
(List<T> items, IntFunction<? extends ScrollPosition> positionFunction, boolean hasNext) Construct aWindow
.Returns the windows content asList
.boolean
hasNext()
Returns if there is a next window.default boolean
hasPosition
(int index) Returns whether the underlying scroll mechanism can provide aScrollPosition
atindex
.boolean
isEmpty()
Returnstrue
if this window contains no elements.default boolean
isLast()
Returns whether the current window is the last one.<U> Window<U>
Returns a newWindow
with the content of the current one mapped by the givenconverter
.positionAt
(int index) Returns theScrollPosition
atindex
.default ScrollPosition
positionAt
(T object) Returns theScrollPosition
forobject
.int
size()
Returns the number of elements in this window.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
from
Construct aWindow
.- Type Parameters:
T
-- Parameters:
items
- the list of data.positionFunction
- the list of data.- Returns:
- the
Window
.
-
from
static <T> Window<T> from(List<T> items, IntFunction<? extends ScrollPosition> positionFunction, boolean hasNext) Construct aWindow
.- Type Parameters:
T
-- Parameters:
items
- the list of data.positionFunction
- the list of data.hasNext
-- Returns:
- the
Window
.
-
size
int size()Returns the number of elements in this window.- Returns:
- the number of elements in this window.
-
isEmpty
boolean isEmpty()Returnstrue
if this window contains no elements.- Specified by:
isEmpty
in interfaceStreamable<T>
- Returns:
true
if this window contains no elements
-
getContent
Returns the windows content asList
.- Returns:
-
isLast
default boolean isLast()Returns whether the current window is the last one.- Returns:
-
hasNext
boolean hasNext()Returns if there is a next window.- Returns:
- if there is a next window.
-
hasPosition
default boolean hasPosition(int index) Returns whether the underlying scroll mechanism can provide aScrollPosition
atindex
.- Parameters:
index
-- Returns:
true
if aScrollPosition
can be created;false
otherwise.- See Also:
-
positionAt
Returns theScrollPosition
atindex
.- Parameters:
index
-- Returns:
- Throws:
IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= size()
).IllegalStateException
- if the underlying scroll mechanism cannot provide a scroll position for the given object.
-
positionAt
Returns theScrollPosition
forobject
.- Parameters:
object
-- Returns:
- Throws:
NoSuchElementException
- if the object is not part of the result.IllegalStateException
- if the underlying scroll mechanism cannot provide a scroll position for the given object.
-
map
Returns a newWindow
with the content of the current one mapped by the givenconverter
.- Specified by:
map
in interfaceStreamable<T>
- Parameters:
converter
- must not be null.- Returns:
- a new
Window
with the content of the current one mapped by the givenconverter
. - See Also:
-