--- /dev/null 2013-02-14 00:07:37.184020992 -0500 +++ new/src/share/classes/java/util/stream/StatefulOp.java 2013-02-21 14:11:07.000000000 -0500 @@ -0,0 +1,44 @@ +package java.util.stream; + +/** + * A stateful intermediate stream operation ({@link IntermediateOp}). Stateful means that state + * is accumulated as elements are processed. Examples of stateful operations are sorting, extracting a subsequence + * of the input, or removing duplicates. Statefulness has an effect on how the operation can be parallelized. + * Stateless operations parallelize trivially because they are homomorphisms under concatenation: + * + *
+ *     statelessOp(a || b) = statelessOp(a) || statelessOp(b)
+ * 
+ * + * where {@code ||} denotes concatenation. Stateful operations may still be parallelizable, but are not amenable to + * the automatic parallelization of stateless operations. Accordingly, a stateful operation must provide its + * own parallel execution implementation ({@link #evaluateParallel(PipelineHelper)}). + * + * @param Type of input and output elements. + * + * @see IntermediateOp + * @see TerminalOp + * @since 1.8 + */ +interface StatefulOp extends IntermediateOp { + + /** + * @{inheritDoc} + * This method must return {@code true} + * @implSpec The default implementations returns {@code true} + * @return {@code true} + */ + @Override + public default boolean isStateful() { + return true; + } + + /** + * {@inheritDoc} + * + * An implementation of this method must be provided, but it is acceptable if the implementation is sequential. + * A generic sequential implementation is available as + * {@link OpUtils#evaluateSequential(IntermediateOp, PipelineHelper)}. + */ + Node evaluateParallel(PipelineHelper helper); +}