Skip to content

Use -1 instead of null as initial offset #3075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,21 @@
* @author Mark Paluch
* @author Oliver Drotbohm
* @author Christoph Strobl
* @author Yanming Zhou
* @since 3.1
*/
public final class OffsetScrollPosition implements ScrollPosition {

private static final OffsetScrollPosition INITIAL = new OffsetScrollPosition(null);
private static final OffsetScrollPosition INITIAL = new OffsetScrollPosition(-1);

@Nullable private final Long offset;
private final long offset;

/**
* Creates a new {@link OffsetScrollPosition} for the given non-negative offset.
*
* @param offset must be greater or equal to zero.
*/
private OffsetScrollPosition(@Nullable Long offset) {

Assert.isTrue(offset == null || offset >= 0, "Offset must not be negative");

private OffsetScrollPosition(long offset) {
this.offset = offset;
}

Expand All @@ -66,6 +64,7 @@ static OffsetScrollPosition initial() {
* @return will never be {@literal null}.
*/
static OffsetScrollPosition of(long offset) {
Assert.isTrue(offset >= 0, "Offset must not be negative");
return new OffsetScrollPosition(offset);
}

Expand All @@ -89,7 +88,7 @@ public static IntFunction<OffsetScrollPosition> positionFunction(long startOffse
* @since 3.3
*/
public IntFunction<OffsetScrollPosition> positionFunction() {
return positionFunction(isInitial() ? 0 : getOffset() + 1);
return positionFunction(offset + 1);
}

/**
Expand All @@ -102,7 +101,7 @@ public IntFunction<OffsetScrollPosition> positionFunction() {
*/
public long getOffset() {

Assert.state(offset != null, "Initial state does not have an offset. Make sure to check #isInitial()");
Assert.state(offset >= 0, "Initial state does not have an offset. Make sure to check #isInitial()");
return offset;
}

Expand All @@ -122,7 +121,7 @@ public OffsetScrollPosition advanceBy(long delta) {

@Override
public boolean isInitial() {
return offset == null;
return offset == -1;
}

@Override
Expand Down
Loading