changeset 6356:4e7f6a6e8369

Refactor stream op hiearchy; now all ops extend base type StreamOp, with specializations IntermediateOp, StatefulOp, and TerminalOp Contributed-by: paul.sandoz@oracle.com
author briangoetz
date Fri, 26 Oct 2012 11:07:34 -0400
parents c30c20389172
children b93e380a7834
files src/share/classes/java/util/streams/ops/EvaluableOp.java src/share/classes/java/util/streams/ops/IntermediateOp.java src/share/classes/java/util/streams/ops/StatefulOp.java src/share/classes/java/util/streams/ops/StreamOp.java src/share/classes/java/util/streams/ops/TerminalOp.java
diffstat 5 files changed, 79 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/streams/ops/EvaluableOp.java	Fri Oct 26 10:57:35 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package java.util.streams.ops;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.streams.ParallelPipelineHelper;
-import java.util.streams.PipelineHelper;
-
-/**
- * An Op whose results can be evaluated directly.  This includes terminal operations, as well as stateless
- * intermediate operations.
- *
- * @param <E_IN> Type of input elements.
- * @param <R> Type of result.
- * @author Brian Goetz
- */
-public interface EvaluableOp<E_IN, R> {
-
-    /**
-     * Evaluate the result of the operation in parallel.
-     *
-     * @param helper
-     * @param <P_IN> Type of elements input to the pipeline.
-     * @return the result of the operation.
-     */
-    <P_IN> R evaluateParallel(ParallelPipelineHelper<P_IN, E_IN> helper) default {
-        Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} using computeParallel serial default", getClass().getSimpleName());
-        return evaluateSequential(helper);
-    }
-
-    /**
-     * Evaluate the result of the operation sequentially.
-     *
-     * @param helper
-     * @return the result of the operation.
-     */
-    <P_IN> R evaluateSequential(PipelineHelper<P_IN, E_IN> helper);
-}
--- a/src/share/classes/java/util/streams/ops/IntermediateOp.java	Fri Oct 26 10:57:35 2012 -0400
+++ b/src/share/classes/java/util/streams/ops/IntermediateOp.java	Fri Oct 26 11:07:34 2012 -0400
@@ -25,6 +25,7 @@
 package java.util.streams.ops;
 
 import java.util.Iterator;
+import java.util.streams.PipelineHelper;
 import java.util.streams.Sink;
 import java.util.streams.StreamShape;
 
@@ -37,7 +38,7 @@
  * @param <E_OUT> Type of output elements to the operation.
  * @author Brian Goetz
  */
-public interface IntermediateOp<E_IN, E_OUT> {
+public interface IntermediateOp<E_IN, E_OUT> extends StreamOp<E_IN, Node<E_OUT>> {
 
     /**
      * Get the properties of the operation.
@@ -80,7 +81,13 @@
      */
     Sink<E_IN> wrapSink(int flags, Sink<E_OUT> sink);
 
-    StreamShape inputShape() default { return StreamShape.VALUE; }
+    StreamShape outputShape() default { return StreamShape.VALUE; }
 
-    StreamShape outputShape() default { return StreamShape.VALUE; }
+    @Override
+    <P_IN> Node<E_OUT> evaluateSequential(PipelineHelper<P_IN, E_IN> helper) default {
+        // @@@ Can we determine the size from the pipeline and this operation?
+        final NodeBuilder<E_OUT> nb = Nodes.makeVariableSizeBuilder();
+        helper.into(wrapSink(helper.getStreamFlags(), nb));
+        return nb.build();
+    }
 }
--- a/src/share/classes/java/util/streams/ops/StatefulOp.java	Fri Oct 26 10:57:35 2012 -0400
+++ b/src/share/classes/java/util/streams/ops/StatefulOp.java	Fri Oct 26 11:07:34 2012 -0400
@@ -10,19 +10,12 @@
  * @param <E_OUT> Type of output elements.
  *
  */
-public interface StatefulOp<E_IN, E_OUT>
-        extends IntermediateOp<E_IN, E_OUT>, EvaluableOp<E_IN, Node<E_OUT>> {
+public interface StatefulOp<E_IN, E_OUT> extends IntermediateOp<E_IN, E_OUT> {
 
     @Override
     public boolean isStateful() default {
         return true;
     }
 
-    @Override
-    <P_IN> Node<E_OUT> evaluateSequential(PipelineHelper<P_IN, E_IN> helper) default {
-        // @@@ Can we determine the size from the pipeline and this operation?
-        final NodeBuilder<E_OUT> nb = Nodes.makeVariableSizeBuilder();
-        helper.into(wrapSink(helper.getStreamFlags(), nb));
-        return nb.build();
-    }
+    // @@@ re-abstract evaluateParallel?
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/util/streams/ops/StreamOp.java	Fri Oct 26 11:07:34 2012 -0400
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package java.util.streams.ops;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.streams.ParallelPipelineHelper;
+import java.util.streams.PipelineHelper;
+import java.util.streams.StreamShape;
+
+/**
+ * An Op whose results can be evaluated directly.  This includes terminal operations, as well as intermediate
+ * stateless and stateful operations.
+ *
+ * @param <E_IN> Type of input elements.
+ * @param <R> Type of result.
+ * @author Brian Goetz
+ */
+public interface StreamOp<E_IN, R> {
+
+    StreamShape inputShape() default { return StreamShape.VALUE; }
+
+    /**
+     * Evaluate the result of the operation in parallel.
+     *
+     * @param helper
+     * @param <P_IN> Type of elements input to the pipeline.
+     * @return the result of the operation.
+     */
+    <P_IN> R evaluateParallel(ParallelPipelineHelper<P_IN, E_IN> helper) default {
+        Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} using computeParallel serial default", getClass().getSimpleName());
+        return evaluateSequential(helper);
+    }
+
+    /**
+     * Evaluate the result of the operation sequentially.
+     *
+     * @param helper
+     * @return the result of the operation.
+     */
+    <P_IN> R evaluateSequential(PipelineHelper<P_IN, E_IN> helper);
+
+}
--- a/src/share/classes/java/util/streams/ops/TerminalOp.java	Fri Oct 26 10:57:35 2012 -0400
+++ b/src/share/classes/java/util/streams/ops/TerminalOp.java	Fri Oct 26 11:07:34 2012 -0400
@@ -24,8 +24,6 @@
  */
 package java.util.streams.ops;
 
-import java.util.streams.StreamShape;
-
 /**
  * A terminal operation.
  *
@@ -33,9 +31,9 @@
  * @param <R>    The type of the result.
  * @author Brian Goetz
  */
-public interface TerminalOp<E_IN, R> extends EvaluableOp<E_IN, R> {
+public interface TerminalOp<E_IN, R> extends StreamOp<E_IN, R> {
 
     boolean isShortCircuit() default { return false; }
 
-    StreamShape inputShape() default { return StreamShape.VALUE; }
+    // @@@ re-abstract evaluateParallel?
 }