diff --git a/kool/src/main/java/org/davidmoten/kool/Indexed.java b/kool/src/main/java/org/davidmoten/kool/Indexed.java index 0293622..62bf98b 100644 --- a/kool/src/main/java/org/davidmoten/kool/Indexed.java +++ b/kool/src/main/java/org/davidmoten/kool/Indexed.java @@ -1,19 +1,21 @@ package org.davidmoten.kool; +import java.util.Objects; + import com.github.davidmoten.guavamini.Preconditions; public final class Indexed { private final T t; - private final int index; + private final long index; - private Indexed(T t, int index) { + private Indexed(T t, long index) { Preconditions.checkNotNull(t); this.t = t; this.index = index; } - public static Indexed create(T t, int index) { + public static Indexed create(T t, long index) { return new Indexed(t, index); } @@ -21,17 +23,14 @@ public T value() { return t; } - public int index() { + public long index() { return index; } + @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + index; - result = prime * result + t.hashCode(); - return result; + return Objects.hash(index, t); } @Override diff --git a/kool/src/main/java/org/davidmoten/kool/Stream.java b/kool/src/main/java/org/davidmoten/kool/Stream.java index 66769fc..73b35ad 100644 --- a/kool/src/main/java/org/davidmoten/kool/Stream.java +++ b/kool/src/main/java/org/davidmoten/kool/Stream.java @@ -757,7 +757,7 @@ default Maybe last() { return new Last(this); } - default Maybe get(int index) { + default Maybe get(long index) { return take(index + 1).last(); } @@ -842,7 +842,7 @@ default Stream> buffer(int size, int step) { return new Buffer(this, size, step); } - default Stream skip(int size) { + default Stream skip(long size) { return new Skip(size, this); } @@ -917,11 +917,11 @@ default Stream bufferWhile(Callable factory, step, maxReplay); } - default Stream> mapWithIndex(int startIndex) { + default Stream> mapWithIndex(long startIndex) { return defer(() -> { - int[] index = new int[] { startIndex }; + long[] index = new long[] { startIndex }; return map(x -> { - int n = index[0]; + long n = index[0]; index[0] = n + 1; return Indexed.create(x, n); }); diff --git a/kool/src/main/java/org/davidmoten/kool/internal/operators/stream/Skip.java b/kool/src/main/java/org/davidmoten/kool/internal/operators/stream/Skip.java index 3e025cd..8b2ed99 100644 --- a/kool/src/main/java/org/davidmoten/kool/internal/operators/stream/Skip.java +++ b/kool/src/main/java/org/davidmoten/kool/internal/operators/stream/Skip.java @@ -5,10 +5,10 @@ public final class Skip implements Stream { - private final int count; + private final long count; private final Stream source; - public Skip(int count, Stream source) { + public Skip(long count, Stream source) { this.count = count; this.source = source; } @@ -18,7 +18,7 @@ public StreamIterator iterator() { return new StreamIterator() { StreamIterator it = source.iteratorNullChecked(); - int n = count; + long n = count; @Override public boolean hasNext() {