changeset 6898:eb917225b421

Flatten out SliceOp so that you can pass a shape right into the constructor. This allows us to push down limit() into AbstractPipeline, which enables other optimizations. Rename skip/slice to substream.
author briangoetz
date Fri, 04 Jan 2013 12:39:07 -0500
parents 14777e594ee8
children 663ba732015a
files src/share/classes/java/util/function/package-info.java src/share/classes/java/util/stream/AbstractPipeline.java src/share/classes/java/util/stream/IntPipeline.java src/share/classes/java/util/stream/IntStream.java src/share/classes/java/util/stream/ReferencePipeline.java src/share/classes/java/util/stream/Stream.java src/share/classes/java/util/stream/StreamShape.java src/share/classes/java/util/stream/StreamShapeFactory.java src/share/classes/java/util/stream/op/SliceOp.java test-ng/tests/org/openjdk/tests/java/util/stream/op/SliceOpTest.java test-ng/tests/org/openjdk/tests/java/util/stream/op/SpinedBufferTest.java test-ng/tests/org/openjdk/tests/java/util/stream/primitive/IntSliceOpTest.java
diffstat 12 files changed, 257 insertions(+), 246 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/function/package-info.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/src/share/classes/java/util/function/package-info.java	Fri Jan 04 12:39:07 2013 -0500
@@ -22,6 +22,7 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
+
 /**
  * <em>Functional interfaces</em> provide typing for lambda expressions. Each
  * functional interface provides a single abstract method to which the lambda
@@ -44,5 +45,7 @@
  * context.
  * </li>
  * </ul>
+ *
+ * @@@ Explanation of naming conventions
  */
 package java.util.function;
--- a/src/share/classes/java/util/stream/AbstractPipeline.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/src/share/classes/java/util/stream/AbstractPipeline.java	Fri Jan 04 12:39:07 2013 -0500
@@ -339,6 +339,10 @@
         return pipeline(new NodeCollectorOp<E_OUT>(getOutputShape()));
     }
 
+    protected <S extends BaseStream<E_OUT>> S slice(long skip, long limit) {
+        return pipeline(new SliceOp<E_OUT>(skip, limit, getOutputShape()));
+    }
+
     private static class NodeCollectorOp<T> implements TerminalOp<T, Node<T>> {
         final StreamShape shape;
 
--- a/src/share/classes/java/util/stream/IntPipeline.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/src/share/classes/java/util/stream/IntPipeline.java	Fri Jan 04 12:39:07 2013 -0500
@@ -137,18 +137,27 @@
     }
 
     @Override
-    public IntStream limit(long limit) {
-        return pipeline(new SliceOp.OfInt(0, limit));
+    public IntStream limit(long sizeLimit) {
+        if (sizeLimit < 0)
+            throw new IllegalArgumentException(Long.toString(sizeLimit));
+        return super.slice(0, sizeLimit);
     }
 
     @Override
-    public IntStream skip(long toSkip) {
-        return pipeline(new SliceOp.OfInt(toSkip));
+    public IntStream substream(long startIndex) {
+        if (startIndex < 0)
+            throw new IllegalArgumentException(Long.toString(startIndex));
+        if (startIndex == 0)
+            return this;
+        else
+            return super.slice(startIndex, -1);
     }
 
     @Override
-    public IntStream slice(long skip, long limit) {
-        return pipeline(new SliceOp.OfInt(skip, limit));
+    public IntStream substream(long startIndex, long endIndex) {
+        if (startIndex < 0 || endIndex < startIndex)
+            throw new IllegalArgumentException(String.format("substream(%d, %d)", startIndex, endIndex));
+        return super.slice(startIndex, endIndex - startIndex);
     }
 
     @Override
--- a/src/share/classes/java/util/stream/IntStream.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/src/share/classes/java/util/stream/IntStream.java	Fri Jan 04 12:39:07 2013 -0500
@@ -66,11 +66,11 @@
         return boxed().uniqueElements().map(i -> (int) i);
     }
 
-    IntStream limit(long limit);
+    IntStream limit(long sizeLimit);
 
-    IntStream skip(long toSkip);
+    IntStream substream(long startIndex);
 
-    IntStream slice(long skip, long limit);
+    IntStream substream(long startIndex, long endIndex);
 
     IntStream sequential();
 
--- a/src/share/classes/java/util/stream/ReferencePipeline.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/src/share/classes/java/util/stream/ReferencePipeline.java	Fri Jan 04 12:39:07 2013 -0500
@@ -161,18 +161,27 @@
     }
 
     @Override
-    public Stream<U> limit(long limit) {
-        return pipeline(new SliceOp.OfReference<U>(0, limit));
+    public Stream<U> limit(long sizeLimit) {
+        if (sizeLimit < 0)
+            throw new IllegalArgumentException(Long.toString(sizeLimit));
+        return super.slice(0, sizeLimit);
     }
 
     @Override
-    public Stream<U> skip(long toSkip) {
-        return pipeline(new SliceOp.OfReference<U>(toSkip));
+    public Stream<U> substream(long startIndex) {
+        if (startIndex < 0)
+            throw new IllegalArgumentException(Long.toString(startIndex));
+        if (startIndex == 0)
+            return this;
+        else
+            return super.slice(startIndex, -1);
     }
 
     @Override
-    public Stream<U> slice(long skip, long limit) {
-        return pipeline(new SliceOp.OfReference<U>(skip, limit));
+    public Stream<U> substream(long startIndex, long endIndex) {
+        if (startIndex < 0 || endIndex < startIndex)
+            throw new IllegalArgumentException(String.format("substream(%d, %d)", startIndex, endIndex));
+        return super.slice(startIndex, endIndex - startIndex);
     }
 
     @Override
--- a/src/share/classes/java/util/stream/Stream.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/src/share/classes/java/util/stream/Stream.java	Fri Jan 04 12:39:07 2013 -0500
@@ -64,33 +64,32 @@
     Stream<T> tee(Block<? super T> block);
 
     /**
-     * Limit this stream to at most {@code n} elements. The stream will not be affected
-     * if it contains less than or equal to {@code n} elements.
+     * Limit this stream to at most {@code sizeLimit} elements. The stream will not be affected
+     * if it contains less than or equal to {@code sizeLimit} elements.
      *
      *
-     * @param n the number elements the stream should be limited to.
+     * @param sizeLimit the number elements the stream should be limited to.
      * @return the truncated stream
      */
-    Stream<T> limit(long n);
+    Stream<T> limit(long sizeLimit);
 
     /**
-     * Skip at most {@code n} elements.
+     * Skip at most {@code startIndex} elements.
      *
      *
-     * @param n the number of elements to be skipped.
+     * @param startIndex the number of elements to be skipped.
      * @return the truncated stream
      */
-    Stream<T> skip(long n);
+    Stream<T> substream(long startIndex);
 
     /**
      * Compute a subsequence of this stream
      *
-     *
-     * @param skip the number of elements to be skipped.
-     * @param limit the maximum length of the resulting stream
+     * @param startIndex the starting position of the substream, inclusive
+     * @param endIndex the ending position of the substream, exclusive
      * @return the truncated stream
      */
-    Stream<T> slice(long skip, long limit);
+    Stream<T> substream(long startIndex, long endIndex);
 
     <A extends Destination<? super T>> A into(A target);
 
--- a/src/share/classes/java/util/stream/StreamShape.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/src/share/classes/java/util/stream/StreamShape.java	Fri Jan 04 12:39:07 2013 -0500
@@ -35,16 +35,22 @@
  *
  * @author Brian Goetz
  */
-public interface StreamShape<S extends BaseStream> {
+public abstract class StreamShape<S extends BaseStream> {
+    public static enum Kinds { REFERENCE, INT_VALUE }
 
-    public static StreamShape<Stream> REFERENCE = new StreamShapeFactory.OfReferenceStreamShape();
+    public static StreamShape<Stream> REFERENCE = new StreamShapeFactory.OfReferenceStreamShape(Kinds.REFERENCE);
+    public static StreamShape<IntStream> INT_VALUE = new StreamShapeFactory.OfIntStreamShape(Kinds.INT_VALUE);
 
-    public static StreamShape<IntStream> INT_VALUE = new StreamShapeFactory.OfIntStreamShape();
+    public final Kinds kind;
+
+    protected StreamShape(Kinds kind) {
+        this.kind = kind;
+    }
 
     /**
      * @return the stream type of this shape.
      */
-    Class<S> getStreamType();
+    public abstract Class<S> getStreamType();
 
     /**
      * Create a new pipeline by chaining an intermediate operation to an upstream pipeline.
@@ -58,7 +64,7 @@
      * @param <V> the type of elements output from the new pipeline.
      * @return a the new pipeline.
      */
-    <U, V> AbstractPipeline<U, V> chain(AbstractPipeline<?, U> upstream, IntermediateOp<U, V> op);
+    public abstract <U, V> AbstractPipeline<U, V> chain(AbstractPipeline<?, U> upstream, IntermediateOp<U, V> op);
 
     /**
      * Create a pipeline from a spliterator compatible with this stream shape.
@@ -68,7 +74,7 @@
      * @return the pipeline, whose content is sourced from the spliterator.
      * @throws IllegalArgumentException if the spliterator is not compatible with this stream shape.
      */
-    <T, S> AbstractPipeline<?, T> stream(Supplier<Spliterator<S>> spliterator, int flags) throws IllegalArgumentException;
+    public abstract <T, S> AbstractPipeline<?, T> stream(Supplier<Spliterator<S>> spliterator, int flags) throws IllegalArgumentException;
 
     /**
      * Obtain the node factory for creating nodes compatible with this stream shape.
@@ -76,7 +82,7 @@
      * @param <T>
      * @return the node factory.
      */
-    <T> NodeFactory<T> nodeFactory();
+    public abstract <T> NodeFactory<T> nodeFactory();
 
     /**
      * Collect elements output from a pipeline into Node that holds elements of this shape.
@@ -88,7 +94,7 @@
      * @param <T> the type of elements output from the pipeline.
      * @return the node holding elements output from the pipeline.
      */
-    <P_IN, T> Node<T> collect(PipelineHelper<P_IN, T> helper, boolean flattenTree);
+    public abstract <P_IN, T> Node<T> collect(PipelineHelper<P_IN, T> helper, boolean flattenTree);
 
     /**
      * Create a pull to push block, compatible with this stream shape, that when invoked pulls one element
@@ -96,7 +102,7 @@
      * @param sourceIterator the source iterator to push elements.
      * @return the push to pull block.
      */
-    <T> Block<Sink<T>> pullToPush(Iterator<T> sourceIterator);
+    public abstract <T> Block<Sink<T>> pullToPush(Iterator<T> sourceIterator);
 
     /**
      * Traverse elements of an iterator, compatible with this stream shape, pushing those elements into a sink.
@@ -104,7 +110,7 @@
      * @param sourceIterator the source iterator to pull elements from
      * @param sink the sink to push elements to.
      */
-    <T> void forEachWithCancel(Iterator<T> sourceIterator, Sink<T> sink);
+    public abstract <T> void forEachWithCancel(Iterator<T> sourceIterator, Sink<T> sink);
 
     /**
      * Create an iterator, compatible with this stream shape, over the sink chain associated with a pipeline.
@@ -115,7 +121,7 @@
      * @param sourceSpliterator the source spliterator
      * @return the iterator over the sink chain.
      */
-    <P_IN, P_OUT> Iterator<P_OUT> pushingIterator(PipelineHelper<P_IN, P_OUT> ph, Spliterator<P_IN> sourceSpliterator);
+    public abstract <P_IN, P_OUT> Iterator<P_OUT> pushingIterator(PipelineHelper<P_IN, P_OUT> ph, Spliterator<P_IN> sourceSpliterator);
 
     /**
      * Create a spliterator that wraps a source spliterator, compatible with this stream shape,
@@ -124,5 +130,5 @@
      * @param ph the pipeline helper.
      * @return the wrapping spliterator compatible with this shape.
      */
-    <P_IN, P_OUT> Spliterator<P_OUT> wrappingSpliterator(PipelineHelper<P_IN, P_OUT> ph);
+    public abstract <P_IN, P_OUT> Spliterator<P_OUT> wrappingSpliterator(PipelineHelper<P_IN, P_OUT> ph);
 }
--- a/src/share/classes/java/util/stream/StreamShapeFactory.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/src/share/classes/java/util/stream/StreamShapeFactory.java	Fri Jan 04 12:39:07 2013 -0500
@@ -60,7 +60,11 @@
         }
     }
 
-    static class OfReferenceStreamShape implements StreamShape<Stream>, NodeFactory<Object> {
+    static class OfReferenceStreamShape extends StreamShape<Stream> implements NodeFactory<Object> {
+        OfReferenceStreamShape(Kinds kind) {
+            super(kind);
+        }
+
         @Override
         public Class<Stream> getStreamType() {
             return Stream.class;
@@ -138,7 +142,11 @@
         }
     }
 
-    static class OfIntStreamShape implements StreamShape<IntStream>, NodeFactory<Integer> {
+    static class OfIntStreamShape extends StreamShape<IntStream> implements NodeFactory<Integer> {
+        OfIntStreamShape(Kinds kind) {
+            super(kind);
+        }
+
         @Override
         public Class<IntStream> getStreamType() {
             return IntStream.class;
--- a/src/share/classes/java/util/stream/op/SliceOp.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/src/share/classes/java/util/stream/op/SliceOp.java	Fri Jan 04 12:39:07 2013 -0500
@@ -33,104 +33,78 @@
  *
  * @author Brian Goetz
  */
-public abstract class SliceOp<T> implements StatefulOp<T, T> {
+public class SliceOp<T> implements StatefulOp<T, T> {
+    protected final long skip;
+    protected final long limit; // -1 means infinite
+    protected final StreamShape shape;
+    protected final Ops.SinkWrapper sinkWrapper;
 
-    public static final class OfReference<T> extends SliceOp<T> {
-
-        public OfReference(long skip, long limit) {
-            super(skip, limit, StreamShape.REFERENCE);
-        }
-
-        public OfReference(long skip) {
-            super(skip, StreamShape.REFERENCE);
-        }
-
-        @Override
-        public Sink<T> wrapSink(int flags, Sink sink) {
-            Objects.requireNonNull(sink);
-            return new Sink.ChainedReference<T>(sink) {
-                long n = skip;
-                long m = limit >= 0 ? limit : Long.MAX_VALUE;
-
-                @Override
-                public void accept(T t) {
-                    if (n == 0) {
-                        if (m > 0) {
-                            m--;
-                            downstream.accept(t);
-                        }
-                    }
-                    else {
-                        n--;
-                    }
-                }
-
-                @Override
-                public boolean cancellationRequested() {
-                    return m == 0 || downstream.cancellationRequested();
-                }
-            };
-        }
-    }
-
-    public static final class OfInt extends SliceOp<Integer> {
-
-        public OfInt(long skip, long limit) {
-            super(skip, limit, StreamShape.INT_VALUE);
-        }
-
-        public OfInt(long skip) {
-            super(skip, StreamShape.INT_VALUE);
-        }
-
-        @Override
-        public Sink<Integer> wrapSink(int flags, Sink sink) {
-            Objects.requireNonNull(sink);
-            return new Sink.ChainedInt(sink) {
-                long n = skip;
-                long m = limit >= 0 ? limit : Long.MAX_VALUE;
-
-                @Override
-                public void accept(int t) {
-                    if (n == 0) {
-                        if (m > 0) {
-                            m--;
-                            downstream.accept(t);
-                        }
-                    }
-                    else {
-                        n--;
-                    }
-                }
-
-                @Override
-                public boolean cancellationRequested() {
-                    return m == 0 || downstream.cancellationRequested();
-                }
-            };
-        }
-    }
-
-    protected final long skip;
-    protected final long limit;
-    private final StreamShape shape;
-
-    private SliceOp(long skip, long limit, StreamShape shape) {
-        if (limit < 0)
-            throw new IllegalArgumentException("Limit must be non-negative: " + limit);
+    public SliceOp(long skip, long limit, StreamShape shape) {
         if (skip < 0)
             throw new IllegalArgumentException("Skip must be non-negative: " + skip);
         this.skip = skip;
         this.limit = limit;
         this.shape = shape;
+        switch (shape.kind) {
+            case REFERENCE: sinkWrapper = this::wrapSinkRef; break;
+            case INT_VALUE: sinkWrapper = this::wrapSinkInt; break;
+            default:
+                throw new IllegalStateException("Unknown shape: " + shape.kind);
+        }
     }
 
-    private SliceOp(long skip, StreamShape shape) {
-        if (skip < 0)
-            throw new IllegalArgumentException("Skip must be non-negative: " + skip);
-        this.skip = skip;
-        this.limit = -1;
-        this.shape = shape;
+    public SliceOp(long skip, StreamShape shape) {
+        this(skip, -1, shape);
+    }
+
+    private<T> Sink<T> wrapSinkRef(int flags, Sink sink) {
+        return new Sink.ChainedReference<T>(sink) {
+            long n = skip;
+            long m = limit >= 0 ? limit : Long.MAX_VALUE;
+
+            @Override
+            public void accept(T t) {
+                if (n == 0) {
+                    if (m > 0) {
+                        m--;
+                        downstream.accept(t);
+                    }
+                }
+                else {
+                    n--;
+                }
+            }
+
+            @Override
+            public boolean cancellationRequested() {
+                return m == 0 || downstream.cancellationRequested();
+            }
+        };
+    }
+
+    private Sink<Integer> wrapSinkInt(int flags, Sink sink) {
+        return new Sink.ChainedInt(sink) {
+            long n = skip;
+            long m = limit >= 0 ? limit : Long.MAX_VALUE;
+
+            @Override
+            public void accept(int t) {
+                if (n == 0) {
+                    if (m > 0) {
+                        m--;
+                        downstream.accept(t);
+                    }
+                }
+                else {
+                    n--;
+                }
+            }
+
+            @Override
+            public boolean cancellationRequested() {
+                return m == 0 || downstream.cancellationRequested();
+            }
+        };
     }
 
     @Override
@@ -148,6 +122,11 @@
         return StreamOpFlag.NOT_SIZED | ((limit != -1) ? StreamOpFlag.IS_SHORT_CIRCUIT : 0);
     }
 
+    @Override
+    public Sink<T> wrapSink(int flags, Sink sink) {
+        return sinkWrapper.wrapSink(flags, sink);
+    }
+
     private long getFinalSize(PipelineHelper helper) {
         long size = helper.getOutputSizeIfKnown();
         if (size >= 0) {
@@ -159,9 +138,6 @@
     }
 
     @Override
-    public abstract Sink<T> wrapSink(int flags, Sink sink);
-
-    @Override
     public <S> Node<T> evaluateParallel(PipelineHelper<S, T> helper) {
         // Parallel strategy -- two cases
         // IF we have full size information
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/op/SliceOpTest.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/op/SliceOpTest.java	Fri Jan 04 12:39:07 2013 -0500
@@ -46,27 +46,27 @@
 public class SliceOpTest extends OpTestCase {
 
     public void testSkip() {
-        assertCountSum(countTo(0).stream().skip(0), 0, 0);
-        assertCountSum(countTo(0).stream().skip(4), 0, 0);
-        assertCountSum(countTo(4).stream().skip(4), 0, 0);
-        assertCountSum(countTo(4).stream().skip(2), 2, 7);
-        assertCountSum(countTo(4).stream().skip(0), 4, 10);
+        assertCountSum(countTo(0).stream().substream(0), 0, 0);
+        assertCountSum(countTo(0).stream().substream(4), 0, 0);
+        assertCountSum(countTo(4).stream().substream(4), 0, 0);
+        assertCountSum(countTo(4).stream().substream(2), 2, 7);
+        assertCountSum(countTo(4).stream().substream(0), 4, 10);
 
-        assertCountSum(countTo(0).parallelStream().skip(0), 0, 0);
-        assertCountSum(countTo(0).parallelStream().skip(4), 0, 0);
-        assertCountSum(countTo(4).parallelStream().skip(4), 0, 0);
-        assertCountSum(countTo(4).parallelStream().skip(2), 2, 7);
-        assertCountSum(countTo(4).parallelStream().skip(0), 4, 10);
+        assertCountSum(countTo(0).parallelStream().substream(0), 0, 0);
+        assertCountSum(countTo(0).parallelStream().substream(4), 0, 0);
+        assertCountSum(countTo(4).parallelStream().substream(4), 0, 0);
+        assertCountSum(countTo(4).parallelStream().substream(2), 2, 7);
+        assertCountSum(countTo(4).parallelStream().substream(0), 4, 10);
 
-        exerciseOps(Collections.emptyList(), s -> s.skip(0), Collections.emptyList());
-        exerciseOps(Collections.emptyList(), s -> s.skip(10), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(0), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(10), Collections.emptyList());
 
-        exerciseOps(countTo(1), s -> s.skip(0), countTo(1));
-        exerciseOps(countTo(1), s -> s.skip(1), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.skip(0), countTo(100));
-        exerciseOps(countTo(100), s -> s.skip(10), range(11, 100));
-        exerciseOps(countTo(100), s -> s.skip(100), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.skip(200), Collections.<Integer>emptyList());
+        exerciseOps(countTo(1), s -> s.substream(0), countTo(1));
+        exerciseOps(countTo(1), s -> s.substream(1), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(0), countTo(100));
+        exerciseOps(countTo(100), s -> s.substream(10), range(11, 100));
+        exerciseOps(countTo(100), s -> s.substream(100), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(200), Collections.<Integer>emptyList());
     }
 
     public void testLimit() {
@@ -93,43 +93,43 @@
     }
 
     public void testSkipLimit() {
-        exerciseOps(Collections.emptyList(), s -> s.skip(0).limit(0), Collections.emptyList());
-        exerciseOps(Collections.emptyList(), s -> s.skip(0).limit(10), Collections.emptyList());
-        exerciseOps(Collections.emptyList(), s -> s.skip(10).limit(0), Collections.emptyList());
-        exerciseOps(Collections.emptyList(), s -> s.skip(10).limit(10), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(0).limit(0), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(0).limit(10), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(10).limit(0), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(10).limit(10), Collections.emptyList());
 
-        exerciseOps(countTo(100), s -> s.skip(0).limit(100), countTo(100));
-        exerciseOps(countTo(100), s -> s.skip(0).limit(10), countTo(10));
-        exerciseOps(countTo(100), s -> s.skip(0).limit(0), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.skip(10).limit(100), range(11, 100));
-        exerciseOps(countTo(100), s -> s.skip(10).limit(10), range(11, 20));
-        exerciseOps(countTo(100), s -> s.skip(10).limit(0), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.skip(100).limit(100), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.skip(100).limit(10), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.skip(100).limit(0), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.skip(200).limit(100), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.skip(200).limit(10), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.skip(200).limit(0), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(0).limit(100), countTo(100));
+        exerciseOps(countTo(100), s -> s.substream(0).limit(10), countTo(10));
+        exerciseOps(countTo(100), s -> s.substream(0).limit(0), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(10).limit(100), range(11, 100));
+        exerciseOps(countTo(100), s -> s.substream(10).limit(10), range(11, 20));
+        exerciseOps(countTo(100), s -> s.substream(10).limit(0), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(100).limit(100), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(100).limit(10), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(100).limit(0), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(200).limit(100), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(200).limit(10), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(200).limit(0), Collections.<Integer>emptyList());
     }
 
     public void testSlice() {
-        exerciseOps(Collections.emptyList(), s -> s.slice(0, 0), Collections.emptyList());
-        exerciseOps(Collections.emptyList(), s -> s.slice(0, 10), Collections.emptyList());
-        exerciseOps(Collections.emptyList(), s -> s.slice(10, 0), Collections.emptyList());
-        exerciseOps(Collections.emptyList(), s -> s.slice(10, 10), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(0, 0), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(0, 10), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(10, 10), Collections.emptyList());
+        exerciseOps(Collections.emptyList(), s -> s.substream(10, 20), Collections.emptyList());
 
-        exerciseOps(countTo(100), s -> s.slice(0, 100), countTo(100));
-        exerciseOps(countTo(100), s -> s.slice(0, 10), countTo(10));
-        exerciseOps(countTo(100), s -> s.slice(0, 0), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.slice(10, 100), range(11, 100));
-        exerciseOps(countTo(100), s -> s.slice(10, 10), range(11, 20));
-        exerciseOps(countTo(100), s -> s.slice(10, 0), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.slice(100, 100), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.slice(100, 10), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.slice(100, 0), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.slice(200, 100), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.slice(200, 10), Collections.<Integer>emptyList());
-        exerciseOps(countTo(100), s -> s.slice(200, 0), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(0, 100), countTo(100));
+        exerciseOps(countTo(100), s -> s.substream(0, 10), countTo(10));
+        exerciseOps(countTo(100), s -> s.substream(0, 0), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(10, 110), range(11, 100));
+        exerciseOps(countTo(100), s -> s.substream(10, 20), range(11, 20));
+        exerciseOps(countTo(100), s -> s.substream(10, 10), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(100, 200), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(100, 110), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(100, 100), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(200, 300), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(200, 210), Collections.<Integer>emptyList());
+        exerciseOps(countTo(100), s -> s.substream(200, 200), Collections.<Integer>emptyList());
     }
 
     private int sliceSize(int dataSize, int skip, int limit) {
@@ -148,10 +148,10 @@
         List<Integer> skips = sizes(data.size());
 
         for (int s : skips) {
-            Node<Integer> sr = exerciseOps(data, st -> st.skip(s));
+            Node<Integer> sr = exerciseOps(data, st -> st.substream(s));
             assertEquals(sr.count(), sliceSize(data.size(), s));
 
-            sr = exerciseOps(data, st -> st.skip(s).skip(s / 2));
+            sr = exerciseOps(data, st -> st.substream(s).substream(s / 2));
             assertEquals(sr.count(), sliceSize(sliceSize(data.size(), s), s/2));
         }
     }
@@ -163,10 +163,10 @@
 
         for (int s : skips) {
             for (int limit : limits) {
-                Node<Integer> sr = exerciseOps(data, st -> st.skip(s).limit(limit));
+                Node<Integer> sr = exerciseOps(data, st -> st.substream(s).limit(limit));
                 assertEquals(sr.count(), sliceSize(sliceSize(data.size(), s), 0, limit));
 
-                sr = exerciseOps(data, st -> st.slice(s, limit));
+                sr = exerciseOps(data, st -> st.substream(s, limit+s));
                 assertEquals(sr.count(), sliceSize(data.size(), s, limit));
             }
         }
@@ -203,7 +203,7 @@
     }
 
     public void testSkipParallel() {
-        List<Integer> l = countTo(1000).parallelStream().skip(200).limit(200).sequential().into(new ArrayList<Integer>());
+        List<Integer> l = countTo(1000).parallelStream().substream(200).limit(200).sequential().into(new ArrayList<Integer>());
         assertEquals(l.size(), 200);
         assertEquals(l.get(l.size() -1).intValue(), 400);
     }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/op/SpinedBufferTest.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/op/SpinedBufferTest.java	Fri Jan 04 12:39:07 2013 -0500
@@ -32,7 +32,6 @@
 import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
-import java.util.function.Block;
 import java.util.function.IntBlock;
 import java.util.stream.Spliterator;
 import java.util.stream.Streams;
@@ -112,7 +111,7 @@
 
         List<Integer> end = Arrays.stream(array)
                 .boxed()
-                .skip(array.length - lastSplitSize)
+                .substream(array.length - lastSplitSize)
                 .into(new ArrayList<Integer>());
         assertEquals(contentOfLastSplit, end);
     }
@@ -162,7 +161,7 @@
 
         List<Integer> end = Arrays.stream(array)
                 .boxed()
-                .skip(array.length - lastSplitSize)
+                .substream(array.length - lastSplitSize)
                 .into(new ArrayList<Integer>());
         assertEquals(contentOfLastSplit, end);
     }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/primitive/IntSliceOpTest.java	Fri Jan 04 14:33:48 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/primitive/IntSliceOpTest.java	Fri Jan 04 12:39:07 2013 -0500
@@ -47,27 +47,27 @@
     private static final int[] EMPTY_INT_ARRAY = new int[0];
 
     public void testSkip() {
-        assertCountSum(Streams.intRange(0, 0).skip(0).boxed(), 0, 0);
-        assertCountSum(Streams.intRange(0, 0).skip(4).boxed(), 0, 0);
-        assertCountSum(Streams.intRange(1, 5).skip(4).boxed(), 0, 0);
-        assertCountSum(Streams.intRange(1, 5).skip(2).boxed(), 2, 7);
-        assertCountSum(Streams.intRange(1, 5).skip(0).boxed(), 4, 10);
+        assertCountSum(Streams.intRange(0, 0).substream(0).boxed(), 0, 0);
+        assertCountSum(Streams.intRange(0, 0).substream(4).boxed(), 0, 0);
+        assertCountSum(Streams.intRange(1, 5).substream(4).boxed(), 0, 0);
+        assertCountSum(Streams.intRange(1, 5).substream(2).boxed(), 2, 7);
+        assertCountSum(Streams.intRange(1, 5).substream(0).boxed(), 4, 10);
 
-        assertCountSum(Streams.intRange(0, 0).parallel().skip(0).boxed(), 0, 0);
-        assertCountSum(Streams.intRange(0, 0).parallel().skip(4).boxed(), 0, 0);
-        assertCountSum(Streams.intRange(1, 5).parallel().skip(4).boxed(), 0, 0);
-        assertCountSum(Streams.intRange(1, 5).parallel().skip(2).boxed(), 2, 7);
-        assertCountSum(Streams.intRange(1, 5).parallel().skip(0).boxed(), 4, 10);
+        assertCountSum(Streams.intRange(0, 0).parallel().substream(0).boxed(), 0, 0);
+        assertCountSum(Streams.intRange(0, 0).parallel().substream(4).boxed(), 0, 0);
+        assertCountSum(Streams.intRange(1, 5).parallel().substream(4).boxed(), 0, 0);
+        assertCountSum(Streams.intRange(1, 5).parallel().substream(2).boxed(), 2, 7);
+        assertCountSum(Streams.intRange(1, 5).parallel().substream(0).boxed(), 4, 10);
 
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.skip(0), EMPTY_INT_ARRAY);
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.skip(10), EMPTY_INT_ARRAY);
+        exerciseOps(EMPTY_INT_ARRAY, s -> s.substream(0), EMPTY_INT_ARRAY);
+        exerciseOps(EMPTY_INT_ARRAY, s -> s.substream(10), EMPTY_INT_ARRAY);
 
-        exerciseOps(Streams.intRange(1, 2).toArray(), s -> s.skip(0), Streams.intRange(1, 2).toArray());
-        exerciseOps(Streams.intRange(1, 2).toArray(), s -> s.skip(1), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(0), Streams.intRange(1, 101).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(10), Streams.intRange(11, 101).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(100), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(200), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 2).toArray(), s -> s.substream(0), Streams.intRange(1, 2).toArray());
+        exerciseOps(Streams.intRange(1, 2).toArray(), s -> s.substream(1), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(0), Streams.intRange(1, 101).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(10), Streams.intRange(11, 101).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(100), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(200), EMPTY_INT_ARRAY);
     }
 
     public void testLimit() {
@@ -95,43 +95,41 @@
     }
 
     public void testSkipLimit() {
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.skip(0).limit(0), EMPTY_INT_ARRAY);
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.skip(0).limit(10), EMPTY_INT_ARRAY);
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.skip(10).limit(0), EMPTY_INT_ARRAY);
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.skip(10).limit(10), EMPTY_INT_ARRAY);
+        exerciseOps(EMPTY_INT_ARRAY, s -> s.substream(0).limit(0), EMPTY_INT_ARRAY);
+        exerciseOps(EMPTY_INT_ARRAY, s -> s.substream(0).limit(10), EMPTY_INT_ARRAY);
+        exerciseOps(EMPTY_INT_ARRAY, s -> s.substream(10).limit(0), EMPTY_INT_ARRAY);
+        exerciseOps(EMPTY_INT_ARRAY, s -> s.substream(10).limit(10), EMPTY_INT_ARRAY);
 
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(0).limit(100), Streams.intRange(1, 101).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(0).limit(10), Streams.intRange(1, 11).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(0).limit(0), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(10).limit(100), Streams.intRange(11, 101).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(10).limit(10), Streams.intRange(11, 21).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(10).limit(0), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(100).limit(100), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(100).limit(10), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(100).limit(0), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(200).limit(100), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(200).limit(10), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.skip(200).limit(0), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(0).limit(100), Streams.intRange(1, 101).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(0).limit(10), Streams.intRange(1, 11).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(0).limit(0), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(10).limit(100), Streams.intRange(11, 101).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(10).limit(10), Streams.intRange(11, 21).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(10).limit(0), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(100).limit(100), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(100).limit(10), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(100).limit(0), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(200).limit(100), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(200).limit(10), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(200).limit(0), EMPTY_INT_ARRAY);
     }
 
     public void testSlice() {
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.slice(0, 0), EMPTY_INT_ARRAY);
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.slice(0, 10), EMPTY_INT_ARRAY);
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.slice(10, 0), EMPTY_INT_ARRAY);
-        exerciseOps(EMPTY_INT_ARRAY, s -> s.slice(10, 10), EMPTY_INT_ARRAY);
+        exerciseOps(EMPTY_INT_ARRAY, s -> s.substream(0, 0), EMPTY_INT_ARRAY);
+        exerciseOps(EMPTY_INT_ARRAY, s -> s.substream(10, 10), EMPTY_INT_ARRAY);
 
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(0, 100), Streams.intRange(1, 101).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(0, 10), Streams.intRange(1, 11).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(0, 0), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(10, 100), Streams.intRange(11, 101).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(10, 10), Streams.intRange(11, 21).toArray());
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(10, 0), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(100, 100), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(100, 10), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(100, 0), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(200, 100), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(200, 10), EMPTY_INT_ARRAY);
-        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.slice(200, 0), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(0, 100), Streams.intRange(1, 101).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(0, 10), Streams.intRange(1, 11).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(0, 0), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(10, 110), Streams.intRange(11, 101).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(10, 20), Streams.intRange(11, 21).toArray());
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(10, 10), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(100, 200), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(100, 110), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(100, 100), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(200, 300), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(200, 210), EMPTY_INT_ARRAY);
+        exerciseOps(Streams.intRange(1, 101).toArray(), s -> s.substream(200, 200), EMPTY_INT_ARRAY);
     }
 
     private int sliceSize(int dataSize, int skip, int limit) {
@@ -150,10 +148,10 @@
         List<Integer> skips = sizes(data.size());
 
         for (int s : skips) {
-            Node<Integer> sr = exerciseOps(data, st -> st.skip(s));
+            Node<Integer> sr = exerciseOps(data, st -> st.substream(s));
             assertEquals(sr.count(), sliceSize(data.size(), s));
 
-            sr = exerciseOps(data, st -> st.skip(s).skip(s / 2));
+            sr = exerciseOps(data, st -> st.substream(s).substream(s / 2));
             assertEquals(sr.count(), sliceSize(sliceSize(data.size(), s), s / 2));
         }
     }
@@ -165,10 +163,10 @@
 
         for (int s : skips) {
             for (int limit : limits) {
-                Node<Integer> sr = exerciseOps(data, st -> st.skip(s).limit(limit));
+                Node<Integer> sr = exerciseOps(data, st -> st.substream(s).limit(limit));
                 assertEquals(sr.count(), sliceSize(sliceSize(data.size(), s), 0, limit));
 
-                sr = exerciseOps(data, st -> st.slice(s, limit));
+                sr = exerciseOps(data, st -> st.substream(s, limit+s));
                 assertEquals(sr.count(), sliceSize(data.size(), s, limit));
             }
         }
@@ -203,7 +201,7 @@
     }
 
     public void testSkipParallel() {
-        int[] l = Streams.intRange(1, 1001).parallel().skip(200).limit(200).sequential().toArray();
+        int[] l = Streams.intRange(1, 1001).parallel().substream(200).limit(200).sequential().toArray();
         assertEquals(l.length, 200);
         assertEquals(l[l.length - 1], 400);
     }