changeset 7492:440c59e7eed0

Clean up generics in XxxPipeline constructors; various other small cleanups
author briangoetz
date Thu, 21 Feb 2013 16:43:05 -0500
parents 8875666d12a8
children 2d19796f57c4
files src/share/classes/java/util/stream/AbstractPipeline.java src/share/classes/java/util/stream/DoublePipeline.java src/share/classes/java/util/stream/FoldOp.java src/share/classes/java/util/stream/IntPipeline.java src/share/classes/java/util/stream/LongPipeline.java src/share/classes/java/util/stream/ReferencePipeline.java
diffstat 6 files changed, 22 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/stream/AbstractPipeline.java	Wed Feb 20 23:13:38 2013 -0500
+++ b/src/share/classes/java/util/stream/AbstractPipeline.java	Thu Feb 21 16:43:05 2013 -0500
@@ -122,9 +122,9 @@
      * Constructor for the head of a stream pipeline.
      *
      * @param source {@code Spliterator} describing the stream source
-     * @param sourceFlags The source flags for the stream source, described in {@link StreamOpFlags}
+     * @param sourceFlags The source flags for the stream source, described in {@link StreamOpFlag}
      */
-    protected AbstractPipeline(Supplier<Spliterator<?>> source,
+    protected AbstractPipeline(Supplier<? extends Spliterator<?>> source,
                                int sourceFlags) {
         this(null, 0, null,
              StreamOpFlag.combineOpFlags(sourceFlags, StreamOpFlag.INITIAL_OPS_VALUE),
@@ -283,11 +283,13 @@
                 generator);
     }
 
+    /** Common implementation of {@code limit()} / {@code substream} for all shapes */
     protected S slice(long skip, long limit) {
         // @@@ Optimize for case where depth=0 or pipeline is size-preserving
         return pipeline(new SliceOp<E_OUT>(skip, limit, getOutputShape()));
     }
 
+    // Implements sequential() from BaseStream
     public S sequential() {
         if (isParallel()) {
             return pipeline(new StatefulOp<E_OUT>() {
@@ -321,6 +323,7 @@
         }
     }
 
+    // Implements parallel() from BaseStream
     public S parallel() {
         if (isParallel()) {
             return (S) this;
@@ -399,7 +402,7 @@
      * @return the pipeline, whose content is sourced from the spliterator.
      * @throws IllegalArgumentException if the spliterator is not compatible with this stream shape.
      */
-    protected abstract <T, S> AbstractPipeline<?, T, ?> stream(Supplier<Spliterator<S>> supplier, int flags);
+    protected abstract <T> AbstractPipeline<?, T, ?> stream(Supplier<? extends Spliterator<?>> supplier, int flags);
 
     /**
      * Traverse elements of a spliterator, compatible with this stream shape, pushing those elements into a sink.
--- a/src/share/classes/java/util/stream/DoublePipeline.java	Wed Feb 20 23:13:38 2013 -0500
+++ b/src/share/classes/java/util/stream/DoublePipeline.java	Thu Feb 21 16:43:05 2013 -0500
@@ -51,7 +51,7 @@
      * @param sourceFlags The source flags for the stream source, described in {@link StreamOpFlag}
      */
     public DoublePipeline(Supplier<? extends Spliterator<Double>> source, int sourceFlags) {
-        super((Supplier) source, sourceFlags);
+        super(source, sourceFlags);
     }
 
     /**
@@ -92,8 +92,8 @@
     }
 
     @Override
-    protected <T, S> AbstractPipeline<?, T, ?> stream(Supplier<Spliterator<S>> supplier, int flags) {
-        return new DoublePipeline((Supplier) supplier, flags);
+    protected <T> AbstractPipeline<?, T, ?> stream(Supplier<? extends Spliterator<?>> supplier, int flags) {
+        return new DoublePipeline((Supplier<? extends Spliterator<Double>>) supplier, flags);
     }
 
     @Override
--- a/src/share/classes/java/util/stream/FoldOp.java	Wed Feb 20 23:13:38 2013 -0500
+++ b/src/share/classes/java/util/stream/FoldOp.java	Thu Feb 21 16:43:05 2013 -0500
@@ -161,6 +161,7 @@
         }
 
         public void clearState() {
+            empty = true;
             state = 0;
         }
 
@@ -203,6 +204,7 @@
         }
 
         public void clearState() {
+            empty = true;
             state = 0;
         }
 
@@ -245,6 +247,7 @@
         }
 
         public void clearState() {
+            empty = true;
             state = 0;
         }
 
--- a/src/share/classes/java/util/stream/IntPipeline.java	Wed Feb 20 23:13:38 2013 -0500
+++ b/src/share/classes/java/util/stream/IntPipeline.java	Thu Feb 21 16:43:05 2013 -0500
@@ -50,7 +50,7 @@
      * @param sourceFlags The source flags for the stream source, described in {@link StreamOpFlag}
      */
     public IntPipeline(Supplier<? extends Spliterator<Integer>> source, int sourceFlags) {
-        super((Supplier) source, sourceFlags);
+        super(source, sourceFlags);
     }
 
     /**
@@ -91,8 +91,8 @@
     }
 
     @Override
-    protected <T, S> AbstractPipeline<?, T, ?> stream(Supplier<Spliterator<S>> supplier, int flags) {
-        return new IntPipeline((Supplier) supplier, flags);
+    protected <T> AbstractPipeline<?, T, ?> stream(Supplier<? extends Spliterator<?>> supplier, int flags) {
+        return new IntPipeline((Supplier<? extends Spliterator<Integer>>) supplier, flags);
     }
 
     @Override
--- a/src/share/classes/java/util/stream/LongPipeline.java	Wed Feb 20 23:13:38 2013 -0500
+++ b/src/share/classes/java/util/stream/LongPipeline.java	Thu Feb 21 16:43:05 2013 -0500
@@ -51,7 +51,7 @@
      * @param sourceFlags The source flags for the stream source, described in {@link StreamOpFlag}
      */
     public LongPipeline(Supplier<? extends Spliterator<Long>> source, int sourceFlags) {
-        super((Supplier) source, sourceFlags);
+        super(source, sourceFlags);
     }
 
     /**
@@ -92,8 +92,8 @@
     }
 
     @Override
-    protected <T, S> AbstractPipeline<?, T, ?> stream(Supplier<Spliterator<S>> supplier, int flags) {
-        return new LongPipeline((Supplier) supplier, flags);
+    protected <T> AbstractPipeline<?, T, ?> stream(Supplier<? extends Spliterator<?>> supplier, int flags) {
+        return new LongPipeline((Supplier<? extends Spliterator<Long>>) supplier, flags);
     }
 
     @Override
--- a/src/share/classes/java/util/stream/ReferencePipeline.java	Wed Feb 20 23:13:38 2013 -0500
+++ b/src/share/classes/java/util/stream/ReferencePipeline.java	Thu Feb 21 16:43:05 2013 -0500
@@ -57,9 +57,9 @@
      * @param source {@code Spliterator} describing the stream source
      * @param sourceFlags The source flags for the stream source, described in {@link StreamOpFlag}
      */
-    public<S> ReferencePipeline(Supplier<? extends Spliterator<S>> source,
-                                int sourceFlags) {
-        super((Supplier) source, sourceFlags);
+    public ReferencePipeline(Supplier<? extends Spliterator<?>> source,
+                             int sourceFlags) {
+        super(source, sourceFlags);
     }
 
     /**
@@ -100,7 +100,7 @@
     }
 
     @Override
-    protected <E_OUT, S> AbstractPipeline<?, E_OUT, ?> stream(Supplier<Spliterator<S>> supplier, int flags) {
+    protected <E_OUT> AbstractPipeline<?, E_OUT, ?> stream(Supplier<? extends Spliterator<?>> supplier, int flags) {
         return new ReferencePipeline<>(supplier, flags);
     }