author | psandoz |
Thu, 16 Jan 2014 18:20:31 +0100 | |
changeset 22289 | bb9c71b84919 |
parent 17163 | 6a5e9b4f27d2 |
permissions | -rw-r--r-- |
17163
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
1 |
/* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
4 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
10 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
15 |
* accompanied this code). |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
16 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
20 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
23 |
* questions. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
24 |
*/ |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
25 |
package java.util.stream; |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
26 |
|
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
27 |
import java.util.Spliterator; |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
28 |
|
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
29 |
/** |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
30 |
* An operation in a stream pipeline that takes a stream as input and produces |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
31 |
* a result or side-effect. A {@code TerminalOp} has an input type and stream |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
32 |
* shape, and a result type. A {@code TerminalOp} also has a set of |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
33 |
* <em>operation flags</em> that describes how the operation processes elements |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
34 |
* of the stream (such as short-circuiting or respecting encounter order; see |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
35 |
* {@link StreamOpFlag}). |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
36 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
37 |
* <p>A {@code TerminalOp} must provide a sequential and parallel implementation |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
38 |
* of the operation relative to a given stream source and set of intermediate |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
39 |
* operations. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
40 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
41 |
* @param <E_IN> the type of input elements |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
42 |
* @param <R> the type of the result |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
43 |
* @since 1.8 |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
44 |
*/ |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
45 |
interface TerminalOp<E_IN, R> { |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
46 |
/** |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
47 |
* Gets the shape of the input type of this operation. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
48 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
49 |
* @implSpec The default returns {@code StreamShape.REFERENCE}. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
50 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
51 |
* @return StreamShape of the input type of this operation |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
52 |
*/ |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
53 |
default StreamShape inputShape() { return StreamShape.REFERENCE; } |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
54 |
|
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
55 |
/** |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
56 |
* Gets the stream flags of the operation. Terminal operations may set a |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
57 |
* limited subset of the stream flags defined in {@link StreamOpFlag}, and |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
58 |
* these flags are combined with the previously combined stream and |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
59 |
* intermediate operation flags for the pipeline. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
60 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
61 |
* @implSpec The default implementation returns zero. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
62 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
63 |
* @return the stream flags for this operation |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
64 |
* @see StreamOpFlag |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
65 |
*/ |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
66 |
default int getOpFlags() { return 0; } |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
67 |
|
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
68 |
/** |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
69 |
* Performs a parallel evaluation of the operation using the specified |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
70 |
* {@code PipelineHelper}, which describes the upstream intermediate |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
71 |
* operations. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
72 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
73 |
* @implSpec The default performs a sequential evaluation of the operation |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
74 |
* using the specified {@code PipelineHelper}. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
75 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
76 |
* @param helper the pipeline helper |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
77 |
* @param spliterator the source spliterator |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
78 |
* @return the result of the evaluation |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
79 |
*/ |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
80 |
default <P_IN> R evaluateParallel(PipelineHelper<E_IN> helper, |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
81 |
Spliterator<P_IN> spliterator) { |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
82 |
if (Tripwire.ENABLED) |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
83 |
Tripwire.trip(getClass(), "{0} triggering TerminalOp.evaluateParallel serial default"); |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
84 |
return evaluateSequential(helper, spliterator); |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
85 |
} |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
86 |
|
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
87 |
/** |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
88 |
* Performs a sequential evaluation of the operation using the specified |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
89 |
* {@code PipelineHelper}, which describes the upstream intermediate |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
90 |
* operations. |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
91 |
* |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
92 |
* @param helper the pipeline helper |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
93 |
* @param spliterator the source spliterator |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
94 |
* @return the result of the evaluation |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
95 |
*/ |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
96 |
<P_IN> R evaluateSequential(PipelineHelper<E_IN> helper, |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
97 |
Spliterator<P_IN> spliterator); |
6a5e9b4f27d2
8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff
changeset
|
98 |
} |