-
Notifications
You must be signed in to change notification settings - Fork 668
/
TerminalOp.java
128 lines (120 loc) · 5.27 KB
/
TerminalOp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (c) 2012, 2013, 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.stream;
import java.util.Spliterator;
/**
* An operation in a stream pipeline that takes a stream as input and produces
* a result or side-effect. A {@code TerminalOp} has an input type and stream
* shape, and a result type. A {@code TerminalOp} also has a set of
* <em>operation flags</em> that describes how the operation processes elements
* of the stream (such as short-circuiting or respecting encounter order; see
* {@link StreamOpFlag}).
*
* <p>A {@code TerminalOp} must provide a sequential and parallel implementation
* of the operation relative to a given stream source and set of intermediate
* operations.
*
* @param <E_IN> the type of input elements
* @param <R> the type of the result
*
* @since 1.8
*/
// 终端操作接口
interface TerminalOp<E_IN, R> {
/**
* Performs a sequential evaluation of the operation using the specified
* {@code PipelineHelper}, which describes the upstream intermediate
* operations.
*
* @param helper the pipeline helper
* @param spliterator the source spliterator
*
* @return the result of the evaluation
*/
/*
* 同步处理helper流阶段输出的元素,返回处理后的结果
*
* 为helper构造一个终端sink,并使用该终端sink对spliterator中的数据进行择取,返回最后的处理结果。
* 返回值可能是收集到的元素,也可能只是对过滤后的元素的计数,还可能是其它定制化的结果。
*
* helper : 某个流阶段,通常需要在当前终端操作中处理从helper阶段输出的数据
* spliterator: 待处理的数据的源头,该流迭代器属于helper之前的(depth==0)的流阶段(包含helper阶段)
*/
<P_IN> R evaluateSequential(PipelineHelper<E_IN> helper, Spliterator<P_IN> spliterator);
/**
* Performs a parallel evaluation of the operation using the specified
* {@code PipelineHelper}, which describes the upstream intermediate
* operations.
*
* @param helper the pipeline helper
* @param spliterator the source spliterator
*
* @return the result of the evaluation
*
* @implSpec The default performs a sequential evaluation of the operation
* using the specified {@code PipelineHelper}.
*/
/*
* 并行处理helper流阶段输出的元素,返回处理后的结果
*
* 为helper构造一个终端sink,并使用该终端sink对spliterator中的数据进行择取,返回最后的处理结果。
* 返回值可能是收集到的元素,也可能只是对过滤后的元素的计数,还可能是其它定制化的结果。
*
* helper : 某个流阶段,通常需要在当前终端操作中处理从helper阶段输出的数据
* spliterator: 待处理的数据的源头,该流迭代器属于helper之前的(depth==0)的流阶段(包含helper阶段)
*/
default <P_IN> R evaluateParallel(PipelineHelper<E_IN> helper, Spliterator<P_IN> spliterator) {
if(Tripwire.ENABLED) {
Tripwire.trip(getClass(), "{0} triggering TerminalOp.evaluateParallel serial default");
}
return evaluateSequential(helper, spliterator);
}
/**
* Gets the shape of the input type of this operation.
*
* @return StreamShape of the input type of this operation
*
* @implSpec The default returns {@code StreamShape.REFERENCE}.
*/
// 从当前终端输出的流的形状
default StreamShape inputShape() {
return StreamShape.REFERENCE;
}
/**
* Gets the stream flags of the operation. Terminal operations may set a
* limited subset of the stream flags defined in {@link StreamOpFlag}, and
* these flags are combined with the previously combined stream and
* intermediate operation flags for the pipeline.
*
* @return the stream flags for this operation
*
* @implSpec The default implementation returns zero.
* @see StreamOpFlag
*/
// 返回当前终端操作上的组合参数
default int getOpFlags() {
return 0;
}
}