30
30
* @author Mark Paluch
31
31
* @author Oliver Drotbohm
32
32
* @author Christoph Strobl
33
+ * @author Yanming Zhou
33
34
* @since 3.1
34
35
*/
35
36
public final class OffsetScrollPosition implements ScrollPosition {
36
37
37
- private static final OffsetScrollPosition INITIAL = new OffsetScrollPosition (null );
38
+ private static final OffsetScrollPosition INITIAL = new OffsetScrollPosition (- 1 );
38
39
39
- @ Nullable private final Long offset ;
40
+ private final long offset ;
40
41
41
42
/**
42
43
* Creates a new {@link OffsetScrollPosition} for the given non-negative offset.
43
44
*
44
45
* @param offset must be greater or equal to zero.
45
46
*/
46
- private OffsetScrollPosition (@ Nullable Long offset ) {
47
-
48
- Assert .isTrue (offset == null || offset >= 0 , "Offset must not be negative" );
49
-
47
+ private OffsetScrollPosition (long offset ) {
50
48
this .offset = offset ;
51
49
}
52
50
@@ -66,6 +64,7 @@ static OffsetScrollPosition initial() {
66
64
* @return will never be {@literal null}.
67
65
*/
68
66
static OffsetScrollPosition of (long offset ) {
67
+ Assert .isTrue (offset >= 0 , "Offset must not be negative" );
69
68
return new OffsetScrollPosition (offset );
70
69
}
71
70
@@ -89,7 +88,7 @@ public static IntFunction<OffsetScrollPosition> positionFunction(long startOffse
89
88
* @since 3.3
90
89
*/
91
90
public IntFunction <OffsetScrollPosition > positionFunction () {
92
- return positionFunction (isInitial () ? 0 : getOffset () + 1 );
91
+ return positionFunction (offset + 1 );
93
92
}
94
93
95
94
/**
@@ -102,7 +101,7 @@ public IntFunction<OffsetScrollPosition> positionFunction() {
102
101
*/
103
102
public long getOffset () {
104
103
105
- Assert .state (offset != null , "Initial state does not have an offset. Make sure to check #isInitial()" );
104
+ Assert .state (offset >= 0 , "Initial state does not have an offset. Make sure to check #isInitial()" );
106
105
return offset ;
107
106
}
108
107
@@ -122,7 +121,7 @@ public OffsetScrollPosition advanceBy(long delta) {
122
121
123
122
@ Override
124
123
public boolean isInitial () {
125
- return offset == null ;
124
+ return offset == - 1 ;
126
125
}
127
126
128
127
@ Override
0 commit comments