Skip to content

Commit 855194a

Browse files
committed
Polishing.
Introduce method to obtain a position function from OffsetScrollPosition. Tweak documentation wording. See #3070 Original pull request: #3072
1 parent eb18466 commit 855194a

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

Diff for: src/main/antora/modules/ROOT/pages/repositories/scrolling.adoc

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Scrolling consists of a stable sort, a scroll type (Offset- or Keyset-based scro
66
You can define simple sorting expressions by using property names and define static result limiting using the xref:repositories/query-methods-details.adoc#repositories.limit-query-result[`Top` or `First` keyword] through query derivation.
77
You can concatenate expressions to collect multiple criteria into one expression.
88

9-
Scroll queries return a `Window<T>` that allows obtaining the elements scroll position which can be used to fetch the next `Window<T>` until your application has consumed the entire query result.
9+
Scroll queries return a `Window<T>` that allows obtaining the element's scroll position to fetch the next `Window<T>` until your application has consumed the entire query result.
1010
Similar to consuming a Java `Iterator<List<…>>` by obtaining the next batch of results, query result scrolling lets you access the a `ScrollPosition` through `Window.positionAt(...)`.
1111

1212
[source,java]
@@ -26,8 +26,8 @@ do {
2626
[NOTE]
2727
====
2828
The `ScrollPosition` identifies the exact position of an element with the entire query result.
29-
Query execution treats the position parameter as _exclusive_, which means results will start _after_ the given position.
30-
`ScrollPosition#offset` and `ScrollPosition#keyset()` as special incarnations of a `ScrollPosition` indicating the start of a scroll operation.
29+
Query execution treats the position parameter _exclusive_, results will start _after_ the given position.
30+
`ScrollPosition#offset()` and `ScrollPosition#keyset()` as special incarnations of a `ScrollPosition` indicating the start of a scroll operation.
3131
====
3232

3333
`WindowIterator` provides a utility to simplify scrolling across ``Window``s by removing the need to check for the presence of a next `Window` and applying the `ScrollPosition`.
@@ -69,8 +69,8 @@ WindowIterator<User> users = WindowIterator.of(position -> repository.findFirst1
6969
[CAUTION]
7070
====
7171
There is a difference between `ScollPosition.offset()` and `ScollPosition.offset(0L)`.
72-
The former indicates the start of scroll operation, pointing to no specific offset where as the latter identifies the first element (at position `0`) of the result.
73-
Given the _exclusive_ nature of scrolling using `ScollPosition.offset(0)` will skip the first element and translate to an offset of 1.
72+
The former indicates the start of scroll operation, pointing to no specific offset whereas the latter identifies the first element (at position `0`) of the result.
73+
Given the _exclusive_ nature of scrolling, using `ScollPosition.offset(0)` skips the first element and translate to an offset of `1`.
7474
====
7575

7676
[[repositories.scrolling.keyset]]

Diff for: src/main/java/org/springframework/data/domain/OffsetScrollPosition.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
/**
2525
* A {@link ScrollPosition} based on the offsets within query results.
2626
* <p>
27-
* An initial {@link OffsetScrollPosition} does not point to a specific element and is different to a the Po
27+
* An initial {@link OffsetScrollPosition} does not point to a specific element and is different to a position
28+
* {{@link ScrollPosition#offset(long)}.
2829
*
2930
* @author Mark Paluch
3031
* @author Oliver Drotbohm
@@ -69,7 +70,7 @@ static OffsetScrollPosition of(long offset) {
6970
}
7071

7172
/**
72-
* Returns the {@link IntFunction position function} to calculate.
73+
* Returns a {@link IntFunction position function} starting at {@code startOffset}.
7374
*
7475
* @param startOffset the start offset to be used. Must not be negative.
7576
* @return the offset-based position function.
@@ -81,6 +82,16 @@ public static IntFunction<OffsetScrollPosition> positionFunction(long startOffse
8182
return startOffset == 0 ? OffsetPositionFunction.ZERO : new OffsetPositionFunction(startOffset);
8283
}
8384

85+
/**
86+
* Returns the {@link IntFunction position function} starting after the current {@code offset}.
87+
*
88+
* @return the offset-based position function.
89+
* @since 3.3
90+
*/
91+
public IntFunction<OffsetScrollPosition> positionFunction() {
92+
return positionFunction(isInitial() ? 0 : getOffset() + 1);
93+
}
94+
8495
/**
8596
* The zero or positive offset.
8697
* <p>

0 commit comments

Comments
 (0)