- Type Parameters:
R- the result type (e.g.,Userfor entity queries,Ref<User>for ref queries).- Record Components:
content- the list of results in this window; never containsnullelements.hasNext-trueif more results existed beyond this window in the scroll direction at query time.hasPrevious-trueif this window was fetched with a cursor position (i.e., not the first page).nextScrollable- the scrollable to fetch the next window, ornullif the window is empty.previousScrollable- the scrollable to fetch the previous window, ornullif the window is empty.
- All Implemented Interfaces:
Slice<R>
Scrollable navigation tokens.
A Window implements Slice and provides cursor-based navigation for sequential traversal
through large result sets. Use next() and previous() for typed programmatic navigation,
or nextCursor() and previousCursor() for serialized cursor strings suitable for REST APIs.
Window<User> window = userRepository.scroll(Scrollable.of(User_.id, 20));
if (window.hasNext()) {
Window<User> next = userRepository.scroll(window.next());
}
The next() and previous() navigation tokens are always provided when the window
has content, regardless of whether hasNext or hasPrevious is true. This allows developers
to follow the cursor even when no more results were detected at query time, which is useful for polling scenarios
where new data may appear after the initial query. The hasNext and hasPrevious flags are
informational: they indicate whether more results existed at the time of the query, but the decision to follow
the cursor is left to the developer.
- Since:
- 1.11
-
Constructor Summary
ConstructorsConstructorDescriptionWindow(List<R> content, boolean hasNext, boolean hasPrevious, Scrollable<?> nextScrollable, Scrollable<?> previousScrollable) Creates an instance of aWindowrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncontent()Returns the value of thecontentrecord component.static <R> Window<R> empty()Returns an empty window with no content and no navigation tokens.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanhasNext()Returns the value of thehasNextrecord component.booleanReturns the value of thehasPreviousrecord component.<T extends Data>
Scrollable<T> next()Returns a typed scrollable for fetching the next window, ornullif the window is empty.Returns an opaque cursor string for fetching the next window, ornullif there is no next window according tohasNext().Scrollable<?> Returns the value of thenextScrollablerecord component.<T extends Data>
Scrollable<T> previous()Returns a typed scrollable for fetching the previous window, ornullif the window is empty.Returns an opaque cursor string for fetching the previous window, ornullif this is the first window according tohasPrevious().Scrollable<?> Returns the value of thepreviousScrollablerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
Window
public Window(@Nonnull List<R> content, boolean hasNext, boolean hasPrevious, @Nullable Scrollable<?> nextScrollable, @Nullable Scrollable<?> previousScrollable) Creates an instance of aWindowrecord class.- Parameters:
content- the value for thecontentrecord componenthasNext- the value for thehasNextrecord componenthasPrevious- the value for thehasPreviousrecord componentnextScrollable- the value for thenextScrollablerecord componentpreviousScrollable- the value for thepreviousScrollablerecord component
-
-
Method Details
-
empty
Returns an empty window with no content and no navigation tokens.- Type Parameters:
R- the result type.- Returns:
- an empty window.
-
next
Returns a typed scrollable for fetching the next window, ornullif the window is empty.The type parameter
Tis inferred from the call-site context, typically from thescroll(Scrollable<T>)method parameter:Window<User> next = userRepository.scroll(window.next());- Type Parameters:
T- the data type, inferred from context.- Returns:
- the scrollable for the next window, or
null.
-
previous
Returns a typed scrollable for fetching the previous window, ornullif the window is empty.The type parameter
Tis inferred from the call-site context, typically from thescroll(Scrollable<T>)method parameter:Window<User> prev = userRepository.scroll(window.previous());- Type Parameters:
T- the data type, inferred from context.- Returns:
- the scrollable for the previous window, or
null.
-
nextCursor
Returns an opaque cursor string for fetching the next window, ornullif there is no next window according tohasNext().This method is a convenience for REST APIs that want to include a cursor only when more results were detected. For polling or streaming use cases where you want to follow the cursor regardless, use
next()directly.- Returns:
- the cursor string, or
null. - See Also:
-
previousCursor
Returns an opaque cursor string for fetching the previous window, ornullif this is the first window according tohasPrevious().This method is a convenience for REST APIs that want to include a cursor only when previous results exist. For use cases where you want to follow the cursor regardless, use
previous()directly.- Returns:
- the cursor string, or
null. - See Also:
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
content
Returns the value of thecontentrecord component. -
hasNext
public boolean hasNext()Returns the value of thehasNextrecord component. -
hasPrevious
public boolean hasPrevious()Returns the value of thehasPreviousrecord component.- Specified by:
hasPreviousin interfaceSlice<R>- Returns:
- the value of the
hasPreviousrecord component
-
nextScrollable
Returns the value of thenextScrollablerecord component.- Returns:
- the value of the
nextScrollablerecord component
-
previousScrollable
Returns the value of thepreviousScrollablerecord component.- Returns:
- the value of the
previousScrollablerecord component
-