3030 * @author Mark Paluch
3131 * @author Oliver Drotbohm
3232 * @author Christoph Strobl
33+ * @author Yanming Zhou
3334 * @since 3.1
3435 */
3536public final class OffsetScrollPosition implements ScrollPosition {
3637
37- private static final OffsetScrollPosition INITIAL = new OffsetScrollPosition (null );
38+ private static final OffsetScrollPosition INITIAL = new OffsetScrollPosition (- 1 );
3839
39- @ Nullable private final Long offset ;
40+ private final long offset ;
4041
4142 /**
4243 * Creates a new {@link OffsetScrollPosition} for the given non-negative offset.
4344 *
4445 * @param offset must be greater or equal to zero.
4546 */
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 ) {
5048 this .offset = offset ;
5149 }
5250
@@ -66,6 +64,7 @@ static OffsetScrollPosition initial() {
6664 * @return will never be {@literal null}.
6765 */
6866 static OffsetScrollPosition of (long offset ) {
67+ Assert .isTrue (offset >= 0 , "Offset must not be negative" );
6968 return new OffsetScrollPosition (offset );
7069 }
7170
@@ -89,7 +88,7 @@ public static IntFunction<OffsetScrollPosition> positionFunction(long startOffse
8988 * @since 3.3
9089 */
9190 public IntFunction <OffsetScrollPosition > positionFunction () {
92- return positionFunction (isInitial () ? 0 : getOffset () + 1 );
91+ return positionFunction (offset + 1 );
9392 }
9493
9594 /**
@@ -102,7 +101,7 @@ public IntFunction<OffsetScrollPosition> positionFunction() {
102101 */
103102 public long getOffset () {
104103
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()" );
106105 return offset ;
107106 }
108107
@@ -122,7 +121,7 @@ public OffsetScrollPosition advanceBy(long delta) {
122121
123122 @ Override
124123 public boolean isInitial () {
125- return offset == null ;
124+ return offset == - 1 ;
126125 }
127126
128127 @ Override
0 commit comments