author | psandoz |
Fri, 20 May 2016 11:47:39 +0200 | |
changeset 38442 | 387a4457880c |
parent 36223 | de2976b3614c |
child 38444 | a5cdecb7d181 |
permissions | -rw-r--r-- |
17167 | 1 |
/* |
36223
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
2 |
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. |
17167 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
package java.util.stream; |
|
26 |
||
17195 | 27 |
import java.util.Arrays; |
17167 | 28 |
import java.util.IntSummaryStatistics; |
17195 | 29 |
import java.util.Objects; |
17167 | 30 |
import java.util.OptionalDouble; |
31 |
import java.util.OptionalInt; |
|
32 |
import java.util.PrimitiveIterator; |
|
33 |
import java.util.Spliterator; |
|
17195 | 34 |
import java.util.Spliterators; |
17167 | 35 |
import java.util.function.BiConsumer; |
36 |
import java.util.function.Function; |
|
37 |
import java.util.function.IntBinaryOperator; |
|
38 |
import java.util.function.IntConsumer; |
|
39 |
import java.util.function.IntFunction; |
|
40 |
import java.util.function.IntPredicate; |
|
17195 | 41 |
import java.util.function.IntSupplier; |
17167 | 42 |
import java.util.function.IntToDoubleFunction; |
43 |
import java.util.function.IntToLongFunction; |
|
44 |
import java.util.function.IntUnaryOperator; |
|
45 |
import java.util.function.ObjIntConsumer; |
|
46 |
import java.util.function.Supplier; |
|
47 |
||
48 |
/** |
|
21339 | 49 |
* A sequence of primitive int-valued elements supporting sequential and parallel |
50 |
* aggregate operations. This is the {@code int} primitive specialization of |
|
51 |
* {@link Stream}. |
|
52 |
* |
|
53 |
* <p>The following example illustrates an aggregate operation using |
|
54 |
* {@link Stream} and {@link IntStream}, computing the sum of the weights of the |
|
55 |
* red widgets: |
|
19850 | 56 |
* |
57 |
* <pre>{@code |
|
58 |
* int sum = widgets.stream() |
|
59 |
* .filter(w -> w.getColor() == RED) |
|
60 |
* .mapToInt(w -> w.getWeight()) |
|
61 |
* .sum(); |
|
62 |
* }</pre> |
|
63 |
* |
|
21339 | 64 |
* See the class documentation for {@link Stream} and the package documentation |
65 |
* for <a href="package-summary.html">java.util.stream</a> for additional |
|
66 |
* specification of streams, stream operations, stream pipelines, and |
|
67 |
* parallelism. |
|
17167 | 68 |
* |
69 |
* @since 1.8 |
|
21339 | 70 |
* @see Stream |
17167 | 71 |
* @see <a href="package-summary.html">java.util.stream</a> |
72 |
*/ |
|
73 |
public interface IntStream extends BaseStream<Integer, IntStream> { |
|
74 |
||
75 |
/** |
|
76 |
* Returns a stream consisting of the elements of this stream that match |
|
77 |
* the given predicate. |
|
78 |
* |
|
79 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate |
|
80 |
* operation</a>. |
|
81 |
* |
|
21339 | 82 |
* @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, |
83 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
84 |
* predicate to apply to each element to determine if it |
|
85 |
* should be included |
|
17167 | 86 |
* @return the new stream |
87 |
*/ |
|
88 |
IntStream filter(IntPredicate predicate); |
|
89 |
||
90 |
/** |
|
91 |
* Returns a stream consisting of the results of applying the given |
|
92 |
* function to the elements of this stream. |
|
93 |
* |
|
94 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate |
|
95 |
* operation</a>. |
|
96 |
* |
|
21339 | 97 |
* @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, |
98 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
99 |
* function to apply to each element |
|
17167 | 100 |
* @return the new stream |
101 |
*/ |
|
102 |
IntStream map(IntUnaryOperator mapper); |
|
103 |
||
104 |
/** |
|
105 |
* Returns an object-valued {@code Stream} consisting of the results of |
|
106 |
* applying the given function to the elements of this stream. |
|
107 |
* |
|
108 |
* <p>This is an <a href="package-summary.html#StreamOps"> |
|
109 |
* intermediate operation</a>. |
|
110 |
* |
|
111 |
* @param <U> the element type of the new stream |
|
21339 | 112 |
* @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, |
113 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
114 |
* function to apply to each element |
|
17167 | 115 |
* @return the new stream |
116 |
*/ |
|
117 |
<U> Stream<U> mapToObj(IntFunction<? extends U> mapper); |
|
118 |
||
119 |
/** |
|
120 |
* Returns a {@code LongStream} consisting of the results of applying the |
|
121 |
* given function to the elements of this stream. |
|
122 |
* |
|
123 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate |
|
124 |
* operation</a>. |
|
125 |
* |
|
21339 | 126 |
* @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, |
127 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
128 |
* function to apply to each element |
|
17167 | 129 |
* @return the new stream |
130 |
*/ |
|
131 |
LongStream mapToLong(IntToLongFunction mapper); |
|
132 |
||
133 |
/** |
|
134 |
* Returns a {@code DoubleStream} consisting of the results of applying the |
|
135 |
* given function to the elements of this stream. |
|
136 |
* |
|
137 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate |
|
138 |
* operation</a>. |
|
139 |
* |
|
21339 | 140 |
* @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, |
141 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
142 |
* function to apply to each element |
|
17167 | 143 |
* @return the new stream |
144 |
*/ |
|
145 |
DoubleStream mapToDouble(IntToDoubleFunction mapper); |
|
146 |
||
147 |
/** |
|
148 |
* Returns a stream consisting of the results of replacing each element of |
|
22352
ecbf37860ffa
8032190: It's unclear that flatMap will ensure each stream will be closed.
psandoz
parents:
21846
diff
changeset
|
149 |
* this stream with the contents of a mapped stream produced by applying |
ecbf37860ffa
8032190: It's unclear that flatMap will ensure each stream will be closed.
psandoz
parents:
21846
diff
changeset
|
150 |
* the provided mapping function to each element. Each mapped stream is |
ecbf37860ffa
8032190: It's unclear that flatMap will ensure each stream will be closed.
psandoz
parents:
21846
diff
changeset
|
151 |
* {@link java.util.stream.BaseStream#close() closed} after its contents |
ecbf37860ffa
8032190: It's unclear that flatMap will ensure each stream will be closed.
psandoz
parents:
21846
diff
changeset
|
152 |
* have been placed into this stream. (If a mapped stream is {@code null} |
ecbf37860ffa
8032190: It's unclear that flatMap will ensure each stream will be closed.
psandoz
parents:
21846
diff
changeset
|
153 |
* an empty stream is used, instead.) |
17167 | 154 |
* |
155 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate |
|
156 |
* operation</a>. |
|
157 |
* |
|
21339 | 158 |
* @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>, |
159 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
160 |
* function to apply to each element which produces an |
|
161 |
* {@code IntStream} of new values |
|
17167 | 162 |
* @return the new stream |
163 |
* @see Stream#flatMap(Function) |
|
164 |
*/ |
|
165 |
IntStream flatMap(IntFunction<? extends IntStream> mapper); |
|
166 |
||
167 |
/** |
|
168 |
* Returns a stream consisting of the distinct elements of this stream. |
|
169 |
* |
|
170 |
* <p>This is a <a href="package-summary.html#StreamOps">stateful |
|
171 |
* intermediate operation</a>. |
|
172 |
* |
|
173 |
* @return the new stream |
|
174 |
*/ |
|
175 |
IntStream distinct(); |
|
176 |
||
177 |
/** |
|
178 |
* Returns a stream consisting of the elements of this stream in sorted |
|
179 |
* order. |
|
180 |
* |
|
181 |
* <p>This is a <a href="package-summary.html#StreamOps">stateful |
|
182 |
* intermediate operation</a>. |
|
183 |
* |
|
184 |
* @return the new stream |
|
185 |
*/ |
|
186 |
IntStream sorted(); |
|
187 |
||
188 |
/** |
|
189 |
* Returns a stream consisting of the elements of this stream, additionally |
|
190 |
* performing the provided action on each element as elements are consumed |
|
191 |
* from the resulting stream. |
|
192 |
* |
|
193 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate |
|
194 |
* operation</a>. |
|
195 |
* |
|
196 |
* <p>For parallel stream pipelines, the action may be called at |
|
197 |
* whatever time and in whatever thread the element is made available by the |
|
198 |
* upstream operation. If the action modifies shared state, |
|
199 |
* it is responsible for providing the required synchronization. |
|
200 |
* |
|
201 |
* @apiNote This method exists mainly to support debugging, where you want |
|
202 |
* to see the elements as they flow past a certain point in a pipeline: |
|
203 |
* <pre>{@code |
|
21846
c10feb34bc0b
8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents:
21339
diff
changeset
|
204 |
* IntStream.of(1, 2, 3, 4) |
c10feb34bc0b
8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents:
21339
diff
changeset
|
205 |
* .filter(e -> e > 2) |
c10feb34bc0b
8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents:
21339
diff
changeset
|
206 |
* .peek(e -> System.out.println("Filtered value: " + e)) |
c10feb34bc0b
8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents:
21339
diff
changeset
|
207 |
* .map(e -> e * e) |
c10feb34bc0b
8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents:
21339
diff
changeset
|
208 |
* .peek(e -> System.out.println("Mapped value: " + e)) |
c10feb34bc0b
8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents:
21339
diff
changeset
|
209 |
* .sum(); |
17167 | 210 |
* }</pre> |
211 |
* |
|
38442
387a4457880c
8130023: API java.util.stream: explicitly specify guaranteed execution of the pipeline
psandoz
parents:
36223
diff
changeset
|
212 |
* <p>In cases where stream implementation is able to optimize away the |
387a4457880c
8130023: API java.util.stream: explicitly specify guaranteed execution of the pipeline
psandoz
parents:
36223
diff
changeset
|
213 |
* production of some or all the elements (such as with short-circuiting |
387a4457880c
8130023: API java.util.stream: explicitly specify guaranteed execution of the pipeline
psandoz
parents:
36223
diff
changeset
|
214 |
* operations like {@code findFirst}, or in the example described in |
387a4457880c
8130023: API java.util.stream: explicitly specify guaranteed execution of the pipeline
psandoz
parents:
36223
diff
changeset
|
215 |
* {@link #count}), the action will not be invoked for those elements. |
387a4457880c
8130023: API java.util.stream: explicitly specify guaranteed execution of the pipeline
psandoz
parents:
36223
diff
changeset
|
216 |
* |
19850 | 217 |
* @param action a <a href="package-summary.html#NonInterference"> |
218 |
* non-interfering</a> action to perform on the elements as |
|
219 |
* they are consumed from the stream |
|
17167 | 220 |
* @return the new stream |
221 |
*/ |
|
19850 | 222 |
IntStream peek(IntConsumer action); |
17167 | 223 |
|
224 |
/** |
|
225 |
* Returns a stream consisting of the elements of this stream, truncated |
|
226 |
* to be no longer than {@code maxSize} in length. |
|
227 |
* |
|
228 |
* <p>This is a <a href="package-summary.html#StreamOps">short-circuiting |
|
229 |
* stateful intermediate operation</a>. |
|
230 |
* |
|
20866
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
231 |
* @apiNote |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
232 |
* While {@code limit()} is generally a cheap operation on sequential |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
233 |
* stream pipelines, it can be quite expensive on ordered parallel pipelines, |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
234 |
* especially for large values of {@code maxSize}, since {@code limit(n)} |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
235 |
* is constrained to return not just any <em>n</em> elements, but the |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
236 |
* <em>first n</em> elements in the encounter order. Using an unordered |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
237 |
* stream source (such as {@link #generate(IntSupplier)}) or removing the |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
238 |
* ordering constraint with {@link #unordered()} may result in significant |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
239 |
* speedups of {@code limit()} in parallel pipelines, if the semantics of |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
240 |
* your situation permit. If consistency with encounter order is required, |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
241 |
* and you are experiencing poor performance or memory utilization with |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
242 |
* {@code limit()} in parallel pipelines, switching to sequential execution |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
243 |
* with {@link #sequential()} may improve performance. |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
244 |
* |
17167 | 245 |
* @param maxSize the number of elements the stream should be limited to |
246 |
* @return the new stream |
|
247 |
* @throws IllegalArgumentException if {@code maxSize} is negative |
|
248 |
*/ |
|
249 |
IntStream limit(long maxSize); |
|
250 |
||
251 |
/** |
|
252 |
* Returns a stream consisting of the remaining elements of this stream |
|
20866
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
253 |
* after discarding the first {@code n} elements of the stream. |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
254 |
* If this stream contains fewer than {@code n} elements then an |
17167 | 255 |
* empty stream will be returned. |
256 |
* |
|
257 |
* <p>This is a <a href="package-summary.html#StreamOps">stateful |
|
258 |
* intermediate operation</a>. |
|
259 |
* |
|
20866
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
260 |
* @apiNote |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
261 |
* While {@code skip()} is generally a cheap operation on sequential |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
262 |
* stream pipelines, it can be quite expensive on ordered parallel pipelines, |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
263 |
* especially for large values of {@code n}, since {@code skip(n)} |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
264 |
* is constrained to skip not just any <em>n</em> elements, but the |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
265 |
* <em>first n</em> elements in the encounter order. Using an unordered |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
266 |
* stream source (such as {@link #generate(IntSupplier)}) or removing the |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
267 |
* ordering constraint with {@link #unordered()} may result in significant |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
268 |
* speedups of {@code skip()} in parallel pipelines, if the semantics of |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
269 |
* your situation permit. If consistency with encounter order is required, |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
270 |
* and you are experiencing poor performance or memory utilization with |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
271 |
* {@code skip()} in parallel pipelines, switching to sequential execution |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
272 |
* with {@link #sequential()} may improve performance. |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
273 |
* |
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
274 |
* @param n the number of leading elements to skip |
17167 | 275 |
* @return the new stream |
20866
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
276 |
* @throws IllegalArgumentException if {@code n} is negative |
17167 | 277 |
*/ |
20866
36155ee613ef
8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents:
19850
diff
changeset
|
278 |
IntStream skip(long n); |
17167 | 279 |
|
280 |
/** |
|
31644
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
281 |
* Returns, if this stream is ordered, a stream consisting of the longest |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
282 |
* prefix of elements taken from this stream that match the given predicate. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
283 |
* Otherwise returns, if this stream is unordered, a stream consisting of a |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
284 |
* subset of elements taken from this stream that match the given predicate. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
285 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
286 |
* <p>If this stream is ordered then the longest prefix is a contiguous |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
287 |
* sequence of elements of this stream that match the given predicate. The |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
288 |
* first element of the sequence is the first element of this stream, and |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
289 |
* the element immediately following the last element of the sequence does |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
290 |
* not match the given predicate. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
291 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
292 |
* <p>If this stream is unordered, and some (but not all) elements of this |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
293 |
* stream match the given predicate, then the behavior of this operation is |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
294 |
* nondeterministic; it is free to take any subset of matching elements |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
295 |
* (which includes the empty set). |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
296 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
297 |
* <p>Independent of whether this stream is ordered or unordered if all |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
298 |
* elements of this stream match the given predicate then this operation |
32002
e378c0dc767e
8130828: Fix some typos and omissions in the the j.u.stream JavaDoc
psandoz
parents:
31644
diff
changeset
|
299 |
* takes all elements (the result is the same as the input), or if no |
31644
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
300 |
* elements of the stream match the given predicate then no elements are |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
301 |
* taken (the result is an empty stream). |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
302 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
303 |
* <p>This is a <a href="package-summary.html#StreamOps">short-circuiting |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
304 |
* stateful intermediate operation</a>. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
305 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
306 |
* @implSpec |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
307 |
* The default implementation obtains the {@link #spliterator() spliterator} |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
308 |
* of this stream, wraps that spliterator so as to support the semantics |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
309 |
* of this operation on traversal, and returns a new stream associated with |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
310 |
* the wrapped spliterator. The returned stream preserves the execution |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
311 |
* characteristics of this stream (namely parallel or sequential execution |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
312 |
* as per {@link #isParallel()}) but the wrapped spliterator may choose to |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
313 |
* not support splitting. When the returned stream is closed, the close |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
314 |
* handlers for both the returned and this stream are invoked. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
315 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
316 |
* @apiNote |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
317 |
* While {@code takeWhile()} is generally a cheap operation on sequential |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
318 |
* stream pipelines, it can be quite expensive on ordered parallel |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
319 |
* pipelines, since the operation is constrained to return not just any |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
320 |
* valid prefix, but the longest prefix of elements in the encounter order. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
321 |
* Using an unordered stream source (such as {@link #generate(IntSupplier)}) |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
322 |
* or removing the ordering constraint with {@link #unordered()} may result |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
323 |
* in significant speedups of {@code takeWhile()} in parallel pipelines, if |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
324 |
* the semantics of your situation permit. If consistency with encounter |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
325 |
* order is required, and you are experiencing poor performance or memory |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
326 |
* utilization with {@code takeWhile()} in parallel pipelines, switching to |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
327 |
* sequential execution with {@link #sequential()} may improve performance. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
328 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
329 |
* @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
330 |
* <a href="package-summary.html#Statelessness">stateless</a> |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
331 |
* predicate to apply to elements to determine the longest |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
332 |
* prefix of elements. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
333 |
* @return the new stream |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
32002
diff
changeset
|
334 |
* @since 9 |
31644
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
335 |
*/ |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
336 |
default IntStream takeWhile(IntPredicate predicate) { |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
337 |
Objects.requireNonNull(predicate); |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
338 |
// Reuses the unordered spliterator, which, when encounter is present, |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
339 |
// is safe to use as long as it configured not to split |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
340 |
return StreamSupport.intStream( |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
341 |
new WhileOps.UnorderedWhileSpliterator.OfInt.Taking(spliterator(), true, predicate), |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
342 |
isParallel()).onClose(this::close); |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
343 |
} |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
344 |
|
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
345 |
/** |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
346 |
* Returns, if this stream is ordered, a stream consisting of the remaining |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
347 |
* elements of this stream after dropping the longest prefix of elements |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
348 |
* that match the given predicate. Otherwise returns, if this stream is |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
349 |
* unordered, a stream consisting of the remaining elements of this stream |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
350 |
* after dropping a subset of elements that match the given predicate. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
351 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
352 |
* <p>If this stream is ordered then the longest prefix is a contiguous |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
353 |
* sequence of elements of this stream that match the given predicate. The |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
354 |
* first element of the sequence is the first element of this stream, and |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
355 |
* the element immediately following the last element of the sequence does |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
356 |
* not match the given predicate. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
357 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
358 |
* <p>If this stream is unordered, and some (but not all) elements of this |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
359 |
* stream match the given predicate, then the behavior of this operation is |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
360 |
* nondeterministic; it is free to drop any subset of matching elements |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
361 |
* (which includes the empty set). |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
362 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
363 |
* <p>Independent of whether this stream is ordered or unordered if all |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
364 |
* elements of this stream match the given predicate then this operation |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
365 |
* drops all elements (the result is an empty stream), or if no elements of |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
366 |
* the stream match the given predicate then no elements are dropped (the |
32002
e378c0dc767e
8130828: Fix some typos and omissions in the the j.u.stream JavaDoc
psandoz
parents:
31644
diff
changeset
|
367 |
* result is the same as the input). |
31644
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
368 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
369 |
* <p>This is a <a href="package-summary.html#StreamOps">stateful |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
370 |
* intermediate operation</a>. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
371 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
372 |
* @implSpec |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
373 |
* The default implementation obtains the {@link #spliterator() spliterator} |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
374 |
* of this stream, wraps that spliterator so as to support the semantics |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
375 |
* of this operation on traversal, and returns a new stream associated with |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
376 |
* the wrapped spliterator. The returned stream preserves the execution |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
377 |
* characteristics of this stream (namely parallel or sequential execution |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
378 |
* as per {@link #isParallel()}) but the wrapped spliterator may choose to |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
379 |
* not support splitting. When the returned stream is closed, the close |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
380 |
* handlers for both the returned and this stream are invoked. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
381 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
382 |
* @apiNote |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
383 |
* While {@code dropWhile()} is generally a cheap operation on sequential |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
384 |
* stream pipelines, it can be quite expensive on ordered parallel |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
385 |
* pipelines, since the operation is constrained to return not just any |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
386 |
* valid prefix, but the longest prefix of elements in the encounter order. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
387 |
* Using an unordered stream source (such as {@link #generate(IntSupplier)}) |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
388 |
* or removing the ordering constraint with {@link #unordered()} may result |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
389 |
* in significant speedups of {@code dropWhile()} in parallel pipelines, if |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
390 |
* the semantics of your situation permit. If consistency with encounter |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
391 |
* order is required, and you are experiencing poor performance or memory |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
392 |
* utilization with {@code dropWhile()} in parallel pipelines, switching to |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
393 |
* sequential execution with {@link #sequential()} may improve performance. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
394 |
* |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
395 |
* @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
396 |
* <a href="package-summary.html#Statelessness">stateless</a> |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
397 |
* predicate to apply to elements to determine the longest |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
398 |
* prefix of elements. |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
399 |
* @return the new stream |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
32002
diff
changeset
|
400 |
* @since 9 |
31644
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
401 |
*/ |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
402 |
default IntStream dropWhile(IntPredicate predicate) { |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
403 |
Objects.requireNonNull(predicate); |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
404 |
// Reuses the unordered spliterator, which, when encounter is present, |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
405 |
// is safe to use as long as it configured not to split |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
406 |
return StreamSupport.intStream( |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
407 |
new WhileOps.UnorderedWhileSpliterator.OfInt.Dropping(spliterator(), true, predicate), |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
408 |
isParallel()).onClose(this::close); |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
409 |
} |
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
410 |
|
dbca10d053fd
8071597: Add Stream dropWhile and takeWhile operations
psandoz
parents:
29489
diff
changeset
|
411 |
/** |
17167 | 412 |
* Performs an action for each element of this stream. |
413 |
* |
|
414 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
|
415 |
* operation</a>. |
|
416 |
* |
|
417 |
* <p>For parallel stream pipelines, this operation does <em>not</em> |
|
418 |
* guarantee to respect the encounter order of the stream, as doing so |
|
419 |
* would sacrifice the benefit of parallelism. For any given element, the |
|
420 |
* action may be performed at whatever time and in whatever thread the |
|
421 |
* library chooses. If the action accesses shared state, it is |
|
422 |
* responsible for providing the required synchronization. |
|
423 |
* |
|
424 |
* @param action a <a href="package-summary.html#NonInterference"> |
|
425 |
* non-interfering</a> action to perform on the elements |
|
426 |
*/ |
|
427 |
void forEach(IntConsumer action); |
|
428 |
||
429 |
/** |
|
430 |
* Performs an action for each element of this stream, guaranteeing that |
|
431 |
* each element is processed in encounter order for streams that have a |
|
432 |
* defined encounter order. |
|
433 |
* |
|
434 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
|
435 |
* operation</a>. |
|
436 |
* |
|
437 |
* @param action a <a href="package-summary.html#NonInterference"> |
|
438 |
* non-interfering</a> action to perform on the elements |
|
439 |
* @see #forEach(IntConsumer) |
|
440 |
*/ |
|
441 |
void forEachOrdered(IntConsumer action); |
|
442 |
||
443 |
/** |
|
444 |
* Returns an array containing the elements of this stream. |
|
445 |
* |
|
446 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
|
447 |
* operation</a>. |
|
448 |
* |
|
449 |
* @return an array containing the elements of this stream |
|
450 |
*/ |
|
451 |
int[] toArray(); |
|
452 |
||
453 |
/** |
|
454 |
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the |
|
455 |
* elements of this stream, using the provided identity value and an |
|
456 |
* <a href="package-summary.html#Associativity">associative</a> |
|
457 |
* accumulation function, and returns the reduced value. This is equivalent |
|
458 |
* to: |
|
459 |
* <pre>{@code |
|
460 |
* int result = identity; |
|
461 |
* for (int element : this stream) |
|
22996
0ce70f4ef909
8029944: Primitive Stream reduce method documentation pseudo code misidentifies apply method
michaelm
parents:
22352
diff
changeset
|
462 |
* result = accumulator.applyAsInt(result, element) |
17167 | 463 |
* return result; |
464 |
* }</pre> |
|
465 |
* |
|
466 |
* but is not constrained to execute sequentially. |
|
467 |
* |
|
468 |
* <p>The {@code identity} value must be an identity for the accumulator |
|
469 |
* function. This means that for all {@code x}, |
|
470 |
* {@code accumulator.apply(identity, x)} is equal to {@code x}. |
|
471 |
* The {@code accumulator} function must be an |
|
472 |
* <a href="package-summary.html#Associativity">associative</a> function. |
|
473 |
* |
|
474 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
|
475 |
* operation</a>. |
|
476 |
* |
|
477 |
* @apiNote Sum, min, max, and average are all special cases of reduction. |
|
478 |
* Summing a stream of numbers can be expressed as: |
|
479 |
* |
|
480 |
* <pre>{@code |
|
481 |
* int sum = integers.reduce(0, (a, b) -> a+b); |
|
482 |
* }</pre> |
|
483 |
* |
|
484 |
* or more compactly: |
|
485 |
* |
|
486 |
* <pre>{@code |
|
487 |
* int sum = integers.reduce(0, Integer::sum); |
|
488 |
* }</pre> |
|
489 |
* |
|
490 |
* <p>While this may seem a more roundabout way to perform an aggregation |
|
491 |
* compared to simply mutating a running total in a loop, reduction |
|
492 |
* operations parallelize more gracefully, without needing additional |
|
493 |
* synchronization and with greatly reduced risk of data races. |
|
494 |
* |
|
495 |
* @param identity the identity value for the accumulating function |
|
21339 | 496 |
* @param op an <a href="package-summary.html#Associativity">associative</a>, |
497 |
* <a href="package-summary.html#NonInterference">non-interfering</a>, |
|
498 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
499 |
* function for combining two values |
|
17167 | 500 |
* @return the result of the reduction |
501 |
* @see #sum() |
|
502 |
* @see #min() |
|
503 |
* @see #max() |
|
504 |
* @see #average() |
|
505 |
*/ |
|
506 |
int reduce(int identity, IntBinaryOperator op); |
|
507 |
||
508 |
/** |
|
509 |
* Performs a <a href="package-summary.html#Reduction">reduction</a> on the |
|
510 |
* elements of this stream, using an |
|
511 |
* <a href="package-summary.html#Associativity">associative</a> accumulation |
|
512 |
* function, and returns an {@code OptionalInt} describing the reduced value, |
|
513 |
* if any. This is equivalent to: |
|
514 |
* <pre>{@code |
|
515 |
* boolean foundAny = false; |
|
516 |
* int result = null; |
|
517 |
* for (int element : this stream) { |
|
518 |
* if (!foundAny) { |
|
519 |
* foundAny = true; |
|
520 |
* result = element; |
|
521 |
* } |
|
522 |
* else |
|
22996
0ce70f4ef909
8029944: Primitive Stream reduce method documentation pseudo code misidentifies apply method
michaelm
parents:
22352
diff
changeset
|
523 |
* result = accumulator.applyAsInt(result, element); |
17167 | 524 |
* } |
525 |
* return foundAny ? OptionalInt.of(result) : OptionalInt.empty(); |
|
526 |
* }</pre> |
|
527 |
* |
|
528 |
* but is not constrained to execute sequentially. |
|
529 |
* |
|
530 |
* <p>The {@code accumulator} function must be an |
|
531 |
* <a href="package-summary.html#Associativity">associative</a> function. |
|
532 |
* |
|
533 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
|
534 |
* operation</a>. |
|
535 |
* |
|
21339 | 536 |
* @param op an <a href="package-summary.html#Associativity">associative</a>, |
537 |
* <a href="package-summary.html#NonInterference">non-interfering</a>, |
|
538 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
539 |
* function for combining two values |
|
17167 | 540 |
* @return the result of the reduction |
541 |
* @see #reduce(int, IntBinaryOperator) |
|
542 |
*/ |
|
543 |
OptionalInt reduce(IntBinaryOperator op); |
|
544 |
||
545 |
/** |
|
546 |
* Performs a <a href="package-summary.html#MutableReduction">mutable |
|
547 |
* reduction</a> operation on the elements of this stream. A mutable |
|
19850 | 548 |
* reduction is one in which the reduced value is a mutable result container, |
17167 | 549 |
* such as an {@code ArrayList}, and elements are incorporated by updating |
19850 | 550 |
* the state of the result rather than by replacing the result. This |
17167 | 551 |
* produces a result equivalent to: |
552 |
* <pre>{@code |
|
19850 | 553 |
* R result = supplier.get(); |
17167 | 554 |
* for (int element : this stream) |
555 |
* accumulator.accept(result, element); |
|
556 |
* return result; |
|
557 |
* }</pre> |
|
558 |
* |
|
559 |
* <p>Like {@link #reduce(int, IntBinaryOperator)}, {@code collect} operations |
|
560 |
* can be parallelized without requiring additional synchronization. |
|
561 |
* |
|
562 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
|
563 |
* operation</a>. |
|
564 |
* |
|
565 |
* @param <R> type of the result |
|
19850 | 566 |
* @param supplier a function that creates a new result container. For a |
567 |
* parallel execution, this function may be called |
|
568 |
* multiple times and must return a fresh value each time. |
|
21339 | 569 |
* @param accumulator an <a href="package-summary.html#Associativity">associative</a>, |
570 |
* <a href="package-summary.html#NonInterference">non-interfering</a>, |
|
571 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
572 |
* function for incorporating an additional element into a result |
|
573 |
* @param combiner an <a href="package-summary.html#Associativity">associative</a>, |
|
574 |
* <a href="package-summary.html#NonInterference">non-interfering</a>, |
|
575 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
576 |
* function for combining two values, which must be |
|
577 |
* compatible with the accumulator function |
|
17167 | 578 |
* @return the result of the reduction |
579 |
* @see Stream#collect(Supplier, BiConsumer, BiConsumer) |
|
580 |
*/ |
|
19850 | 581 |
<R> R collect(Supplier<R> supplier, |
17167 | 582 |
ObjIntConsumer<R> accumulator, |
583 |
BiConsumer<R, R> combiner); |
|
584 |
||
585 |
/** |
|
586 |
* Returns the sum of elements in this stream. This is a special case |
|
19850 | 587 |
* of a <a href="package-summary.html#Reduction">reduction</a> |
17167 | 588 |
* and is equivalent to: |
589 |
* <pre>{@code |
|
590 |
* return reduce(0, Integer::sum); |
|
591 |
* }</pre> |
|
592 |
* |
|
19850 | 593 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
594 |
* operation</a>. |
|
595 |
* |
|
17167 | 596 |
* @return the sum of elements in this stream |
597 |
*/ |
|
598 |
int sum(); |
|
599 |
||
600 |
/** |
|
601 |
* Returns an {@code OptionalInt} describing the minimum element of this |
|
602 |
* stream, or an empty optional if this stream is empty. This is a special |
|
19850 | 603 |
* case of a <a href="package-summary.html#Reduction">reduction</a> |
17167 | 604 |
* and is equivalent to: |
605 |
* <pre>{@code |
|
606 |
* return reduce(Integer::min); |
|
607 |
* }</pre> |
|
608 |
* |
|
609 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal operation</a>. |
|
610 |
* |
|
611 |
* @return an {@code OptionalInt} containing the minimum element of this |
|
612 |
* stream, or an empty {@code OptionalInt} if the stream is empty |
|
613 |
*/ |
|
614 |
OptionalInt min(); |
|
615 |
||
616 |
/** |
|
617 |
* Returns an {@code OptionalInt} describing the maximum element of this |
|
618 |
* stream, or an empty optional if this stream is empty. This is a special |
|
19850 | 619 |
* case of a <a href="package-summary.html#Reduction">reduction</a> |
17167 | 620 |
* and is equivalent to: |
621 |
* <pre>{@code |
|
622 |
* return reduce(Integer::max); |
|
623 |
* }</pre> |
|
624 |
* |
|
625 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
|
626 |
* operation</a>. |
|
627 |
* |
|
628 |
* @return an {@code OptionalInt} containing the maximum element of this |
|
629 |
* stream, or an empty {@code OptionalInt} if the stream is empty |
|
630 |
*/ |
|
631 |
OptionalInt max(); |
|
632 |
||
633 |
/** |
|
634 |
* Returns the count of elements in this stream. This is a special case of |
|
19850 | 635 |
* a <a href="package-summary.html#Reduction">reduction</a> and is |
17167 | 636 |
* equivalent to: |
637 |
* <pre>{@code |
|
638 |
* return mapToLong(e -> 1L).sum(); |
|
639 |
* }</pre> |
|
640 |
* |
|
641 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal operation</a>. |
|
642 |
* |
|
29489 | 643 |
* @apiNote |
644 |
* An implementation may choose to not execute the stream pipeline (either |
|
645 |
* sequentially or in parallel) if it is capable of computing the count |
|
646 |
* directly from the stream source. In such cases no source elements will |
|
647 |
* be traversed and no intermediate operations will be evaluated. |
|
648 |
* Behavioral parameters with side-effects, which are strongly discouraged |
|
649 |
* except for harmless cases such as debugging, may be affected. For |
|
650 |
* example, consider the following stream: |
|
651 |
* <pre>{@code |
|
652 |
* IntStream s = IntStream.of(1, 2, 3, 4); |
|
653 |
* long count = s.peek(System.out::println).count(); |
|
654 |
* }</pre> |
|
655 |
* The number of elements covered by the stream source is known and the |
|
656 |
* intermediate operation, {@code peek}, does not inject into or remove |
|
657 |
* elements from the stream (as may be the case for {@code flatMap} or |
|
658 |
* {@code filter} operations). Thus the count is 4 and there is no need to |
|
659 |
* execute the pipeline and, as a side-effect, print out the elements. |
|
660 |
* |
|
17167 | 661 |
* @return the count of elements in this stream |
662 |
*/ |
|
663 |
long count(); |
|
664 |
||
665 |
/** |
|
19214
e5901820c3c1
8015318: Extend Collector with 'finish' operation
briangoetz
parents:
18825
diff
changeset
|
666 |
* Returns an {@code OptionalDouble} describing the arithmetic mean of elements of |
17167 | 667 |
* this stream, or an empty optional if this stream is empty. This is a |
668 |
* special case of a |
|
19850 | 669 |
* <a href="package-summary.html#Reduction">reduction</a>. |
670 |
* |
|
671 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
|
672 |
* operation</a>. |
|
17167 | 673 |
* |
674 |
* @return an {@code OptionalDouble} containing the average element of this |
|
675 |
* stream, or an empty optional if the stream is empty |
|
676 |
*/ |
|
677 |
OptionalDouble average(); |
|
678 |
||
679 |
/** |
|
680 |
* Returns an {@code IntSummaryStatistics} describing various |
|
681 |
* summary data about the elements of this stream. This is a special |
|
19850 | 682 |
* case of a <a href="package-summary.html#Reduction">reduction</a>. |
683 |
* |
|
684 |
* <p>This is a <a href="package-summary.html#StreamOps">terminal |
|
685 |
* operation</a>. |
|
17167 | 686 |
* |
687 |
* @return an {@code IntSummaryStatistics} describing various summary data |
|
688 |
* about the elements of this stream |
|
689 |
*/ |
|
690 |
IntSummaryStatistics summaryStatistics(); |
|
691 |
||
692 |
/** |
|
693 |
* Returns whether any elements of this stream match the provided |
|
694 |
* predicate. May not evaluate the predicate on all elements if not |
|
21339 | 695 |
* necessary for determining the result. If the stream is empty then |
696 |
* {@code false} is returned and the predicate is not evaluated. |
|
17167 | 697 |
* |
698 |
* <p>This is a <a href="package-summary.html#StreamOps">short-circuiting |
|
699 |
* terminal operation</a>. |
|
700 |
* |
|
21339 | 701 |
* @apiNote |
702 |
* This method evaluates the <em>existential quantification</em> of the |
|
703 |
* predicate over the elements of the stream (for some x P(x)). |
|
704 |
* |
|
705 |
* @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, |
|
706 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
707 |
* predicate to apply to elements of this stream |
|
17167 | 708 |
* @return {@code true} if any elements of the stream match the provided |
21339 | 709 |
* predicate, otherwise {@code false} |
17167 | 710 |
*/ |
711 |
boolean anyMatch(IntPredicate predicate); |
|
712 |
||
713 |
/** |
|
714 |
* Returns whether all elements of this stream match the provided predicate. |
|
715 |
* May not evaluate the predicate on all elements if not necessary for |
|
21339 | 716 |
* determining the result. If the stream is empty then {@code true} is |
717 |
* returned and the predicate is not evaluated. |
|
17167 | 718 |
* |
719 |
* <p>This is a <a href="package-summary.html#StreamOps">short-circuiting |
|
720 |
* terminal operation</a>. |
|
721 |
* |
|
21339 | 722 |
* @apiNote |
723 |
* This method evaluates the <em>universal quantification</em> of the |
|
724 |
* predicate over the elements of the stream (for all x P(x)). If the |
|
725 |
* stream is empty, the quantification is said to be <em>vacuously |
|
726 |
* satisfied</em> and is always {@code true} (regardless of P(x)). |
|
727 |
* |
|
728 |
* @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, |
|
729 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
730 |
* predicate to apply to elements of this stream |
|
731 |
* @return {@code true} if either all elements of the stream match the |
|
732 |
* provided predicate or the stream is empty, otherwise {@code false} |
|
17167 | 733 |
*/ |
734 |
boolean allMatch(IntPredicate predicate); |
|
735 |
||
736 |
/** |
|
737 |
* Returns whether no elements of this stream match the provided predicate. |
|
738 |
* May not evaluate the predicate on all elements if not necessary for |
|
21339 | 739 |
* determining the result. If the stream is empty then {@code true} is |
740 |
* returned and the predicate is not evaluated. |
|
17167 | 741 |
* |
742 |
* <p>This is a <a href="package-summary.html#StreamOps">short-circuiting |
|
743 |
* terminal operation</a>. |
|
744 |
* |
|
21339 | 745 |
* @apiNote |
746 |
* This method evaluates the <em>universal quantification</em> of the |
|
747 |
* negated predicate over the elements of the stream (for all x ~P(x)). If |
|
748 |
* the stream is empty, the quantification is said to be vacuously satisfied |
|
749 |
* and is always {@code true}, regardless of P(x). |
|
750 |
* |
|
751 |
* @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>, |
|
752 |
* <a href="package-summary.html#Statelessness">stateless</a> |
|
753 |
* predicate to apply to elements of this stream |
|
754 |
* @return {@code true} if either no elements of the stream match the |
|
755 |
* provided predicate or the stream is empty, otherwise {@code false} |
|
17167 | 756 |
*/ |
757 |
boolean noneMatch(IntPredicate predicate); |
|
758 |
||
759 |
/** |
|
760 |
* Returns an {@link OptionalInt} describing the first element of this |
|
19850 | 761 |
* stream, or an empty {@code OptionalInt} if the stream is empty. If the |
762 |
* stream has no encounter order, then any element may be returned. |
|
17167 | 763 |
* |
764 |
* <p>This is a <a href="package-summary.html#StreamOps">short-circuiting |
|
765 |
* terminal operation</a>. |
|
766 |
* |
|
767 |
* @return an {@code OptionalInt} describing the first element of this stream, |
|
768 |
* or an empty {@code OptionalInt} if the stream is empty |
|
769 |
*/ |
|
770 |
OptionalInt findFirst(); |
|
771 |
||
772 |
/** |
|
773 |
* Returns an {@link OptionalInt} describing some element of the stream, or |
|
774 |
* an empty {@code OptionalInt} if the stream is empty. |
|
775 |
* |
|
776 |
* <p>This is a <a href="package-summary.html#StreamOps">short-circuiting |
|
777 |
* terminal operation</a>. |
|
778 |
* |
|
779 |
* <p>The behavior of this operation is explicitly nondeterministic; it is |
|
780 |
* free to select any element in the stream. This is to allow for maximal |
|
781 |
* performance in parallel operations; the cost is that multiple invocations |
|
19850 | 782 |
* on the same source may not return the same result. (If a stable result |
783 |
* is desired, use {@link #findFirst()} instead.) |
|
17167 | 784 |
* |
785 |
* @return an {@code OptionalInt} describing some element of this stream, or |
|
786 |
* an empty {@code OptionalInt} if the stream is empty |
|
787 |
* @see #findFirst() |
|
788 |
*/ |
|
789 |
OptionalInt findAny(); |
|
790 |
||
791 |
/** |
|
792 |
* Returns a {@code LongStream} consisting of the elements of this stream, |
|
793 |
* converted to {@code long}. |
|
794 |
* |
|
19850 | 795 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate |
796 |
* operation</a>. |
|
797 |
* |
|
17167 | 798 |
* @return a {@code LongStream} consisting of the elements of this stream, |
799 |
* converted to {@code long} |
|
800 |
*/ |
|
18154
5ede18269905
8015798: Rename IntStream.longs/doubles and LongStream.doubles to asXxxStream
psandoz
parents:
17914
diff
changeset
|
801 |
LongStream asLongStream(); |
17167 | 802 |
|
803 |
/** |
|
804 |
* Returns a {@code DoubleStream} consisting of the elements of this stream, |
|
805 |
* converted to {@code double}. |
|
806 |
* |
|
19850 | 807 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate |
808 |
* operation</a>. |
|
809 |
* |
|
17167 | 810 |
* @return a {@code DoubleStream} consisting of the elements of this stream, |
811 |
* converted to {@code double} |
|
812 |
*/ |
|
18154
5ede18269905
8015798: Rename IntStream.longs/doubles and LongStream.doubles to asXxxStream
psandoz
parents:
17914
diff
changeset
|
813 |
DoubleStream asDoubleStream(); |
17167 | 814 |
|
815 |
/** |
|
816 |
* Returns a {@code Stream} consisting of the elements of this stream, |
|
817 |
* each boxed to an {@code Integer}. |
|
818 |
* |
|
19850 | 819 |
* <p>This is an <a href="package-summary.html#StreamOps">intermediate |
820 |
* operation</a>. |
|
821 |
* |
|
17167 | 822 |
* @return a {@code Stream} consistent of the elements of this stream, |
823 |
* each boxed to an {@code Integer} |
|
824 |
*/ |
|
825 |
Stream<Integer> boxed(); |
|
826 |
||
827 |
@Override |
|
828 |
IntStream sequential(); |
|
829 |
||
830 |
@Override |
|
831 |
IntStream parallel(); |
|
832 |
||
833 |
@Override |
|
834 |
PrimitiveIterator.OfInt iterator(); |
|
835 |
||
836 |
@Override |
|
837 |
Spliterator.OfInt spliterator(); |
|
17195 | 838 |
|
839 |
// Static factories |
|
840 |
||
841 |
/** |
|
842 |
* Returns a builder for an {@code IntStream}. |
|
843 |
* |
|
844 |
* @return a stream builder |
|
845 |
*/ |
|
18825
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
846 |
public static Builder builder() { |
17195 | 847 |
return new Streams.IntStreamBuilderImpl(); |
848 |
} |
|
849 |
||
850 |
/** |
|
851 |
* Returns an empty sequential {@code IntStream}. |
|
852 |
* |
|
853 |
* @return an empty sequential stream |
|
854 |
*/ |
|
855 |
public static IntStream empty() { |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
18820
diff
changeset
|
856 |
return StreamSupport.intStream(Spliterators.emptyIntSpliterator(), false); |
17195 | 857 |
} |
858 |
||
859 |
/** |
|
860 |
* Returns a sequential {@code IntStream} containing a single element. |
|
861 |
* |
|
862 |
* @param t the single element |
|
863 |
* @return a singleton sequential stream |
|
864 |
*/ |
|
865 |
public static IntStream of(int t) { |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
18820
diff
changeset
|
866 |
return StreamSupport.intStream(new Streams.IntStreamBuilderImpl(t), false); |
17195 | 867 |
} |
868 |
||
869 |
/** |
|
19850 | 870 |
* Returns a sequential ordered stream whose elements are the specified values. |
17195 | 871 |
* |
872 |
* @param values the elements of the new stream |
|
873 |
* @return the new stream |
|
874 |
*/ |
|
875 |
public static IntStream of(int... values) { |
|
876 |
return Arrays.stream(values); |
|
877 |
} |
|
878 |
||
879 |
/** |
|
19850 | 880 |
* Returns an infinite sequential ordered {@code IntStream} produced by iterative |
17195 | 881 |
* application of a function {@code f} to an initial element {@code seed}, |
882 |
* producing a {@code Stream} consisting of {@code seed}, {@code f(seed)}, |
|
883 |
* {@code f(f(seed))}, etc. |
|
884 |
* |
|
885 |
* <p>The first element (position {@code 0}) in the {@code IntStream} will be |
|
886 |
* the provided {@code seed}. For {@code n > 0}, the element at position |
|
887 |
* {@code n}, will be the result of applying the function {@code f} to the |
|
888 |
* element at position {@code n - 1}. |
|
889 |
* |
|
890 |
* @param seed the initial element |
|
25526 | 891 |
* @param f a function to be applied to the previous element to produce |
17195 | 892 |
* a new element |
36223
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
893 |
* @return a new sequential {@code IntStream} |
17195 | 894 |
*/ |
895 |
public static IntStream iterate(final int seed, final IntUnaryOperator f) { |
|
896 |
Objects.requireNonNull(f); |
|
36223
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
897 |
Spliterator.OfInt spliterator = new Spliterators.AbstractIntSpliterator(Long.MAX_VALUE, |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
898 |
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
899 |
int prev; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
900 |
boolean started; |
17195 | 901 |
|
902 |
@Override |
|
36223
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
903 |
public boolean tryAdvance(IntConsumer action) { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
904 |
Objects.requireNonNull(action); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
905 |
int t; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
906 |
if (started) |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
907 |
t = f.applyAsInt(prev); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
908 |
else { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
909 |
t = seed; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
910 |
started = true; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
911 |
} |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
912 |
action.accept(prev = t); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
913 |
return true; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
914 |
} |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
915 |
}; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
916 |
return StreamSupport.intStream(spliterator, false); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
917 |
} |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
918 |
|
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
919 |
/** |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
920 |
* Returns a sequential ordered {@code IntStream} produced by iterative |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
921 |
* application of a function to an initial element, conditioned on |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
922 |
* satisfying the supplied predicate. The stream terminates as soon as |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
923 |
* the predicate returns false. |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
924 |
* |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
925 |
* <p> |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
926 |
* {@code IntStream.iterate} should produce the same sequence of elements |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
927 |
* as produced by the corresponding for-loop: |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
928 |
* <pre>{@code |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
929 |
* for (int index=seed; predicate.test(index); index = f.apply(index)) { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
930 |
* ... |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
931 |
* } |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
932 |
* }</pre> |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
933 |
* |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
934 |
* <p> |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
935 |
* The resulting sequence may be empty if the predicate does not hold on |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
936 |
* the seed value. Otherwise the first element will be the supplied seed |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
937 |
* value, the next element (if present) will be the result of applying the |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
938 |
* function f to the seed value, and so on iteratively until the predicate |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
939 |
* indicates that the stream should terminate. |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
940 |
* |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
941 |
* @param seed the initial element |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
942 |
* @param predicate a predicate to apply to elements to determine when the |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
943 |
* stream must terminate. |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
944 |
* @param f a function to be applied to the previous element to produce |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
945 |
* a new element |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
946 |
* @return a new sequential {@code IntStream} |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
947 |
* @since 9 |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
948 |
*/ |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
949 |
public static IntStream iterate(int seed, IntPredicate predicate, IntUnaryOperator f) { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
950 |
Objects.requireNonNull(f); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
951 |
Objects.requireNonNull(predicate); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
952 |
Spliterator.OfInt spliterator = new Spliterators.AbstractIntSpliterator(Long.MAX_VALUE, |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
953 |
Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
954 |
int prev; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
955 |
boolean started, finished; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
956 |
|
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
957 |
@Override |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
958 |
public boolean tryAdvance(IntConsumer action) { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
959 |
Objects.requireNonNull(action); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
960 |
if (finished) |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
961 |
return false; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
962 |
int t; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
963 |
if (started) |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
964 |
t = f.applyAsInt(prev); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
965 |
else { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
966 |
t = seed; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
967 |
started = true; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
968 |
} |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
969 |
if (!predicate.test(t)) { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
970 |
finished = true; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
971 |
return false; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
972 |
} |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
973 |
action.accept(prev = t); |
17195 | 974 |
return true; |
975 |
} |
|
976 |
||
977 |
@Override |
|
36223
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
978 |
public void forEachRemaining(IntConsumer action) { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
979 |
Objects.requireNonNull(action); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
980 |
if (finished) |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
981 |
return; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
982 |
finished = true; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
983 |
int t = started ? f.applyAsInt(prev) : seed; |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
984 |
while (predicate.test(t)) { |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
985 |
action.accept(t); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
986 |
t = f.applyAsInt(t); |
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
987 |
} |
17195 | 988 |
} |
989 |
}; |
|
36223
de2976b3614c
8072727: add variation of Stream.iterate() that's finite
tvaleev
parents:
35302
diff
changeset
|
990 |
return StreamSupport.intStream(spliterator, false); |
17195 | 991 |
} |
992 |
||
993 |
/** |
|
21339 | 994 |
* Returns an infinite sequential unordered stream where each element is |
995 |
* generated by the provided {@code IntSupplier}. This is suitable for |
|
996 |
* generating constant streams, streams of random elements, etc. |
|
17195 | 997 |
* |
998 |
* @param s the {@code IntSupplier} for generated elements |
|
21339 | 999 |
* @return a new infinite sequential unordered {@code IntStream} |
17195 | 1000 |
*/ |
1001 |
public static IntStream generate(IntSupplier s) { |
|
1002 |
Objects.requireNonNull(s); |
|
18572
53b8b8c30086
8012987: Optimizations for Stream.limit/substream
psandoz
parents:
18158
diff
changeset
|
1003 |
return StreamSupport.intStream( |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
18820
diff
changeset
|
1004 |
new StreamSpliterators.InfiniteSupplyingSpliterator.OfInt(Long.MAX_VALUE, s), false); |
17195 | 1005 |
} |
1006 |
||
1007 |
/** |
|
19850 | 1008 |
* Returns a sequential ordered {@code IntStream} from {@code startInclusive} |
17195 | 1009 |
* (inclusive) to {@code endExclusive} (exclusive) by an incremental step of |
18158 | 1010 |
* {@code 1}. |
17195 | 1011 |
* |
18158 | 1012 |
* @apiNote |
1013 |
* <p>An equivalent sequence of increasing values can be produced |
|
1014 |
* sequentially using a {@code for} loop as follows: |
|
17195 | 1015 |
* <pre>{@code |
18158 | 1016 |
* for (int i = startInclusive; i < endExclusive ; i++) { ... } |
17195 | 1017 |
* }</pre> |
1018 |
* |
|
1019 |
* @param startInclusive the (inclusive) initial value |
|
1020 |
* @param endExclusive the exclusive upper bound |
|
1021 |
* @return a sequential {@code IntStream} for the range of {@code int} |
|
1022 |
* elements |
|
1023 |
*/ |
|
1024 |
public static IntStream range(int startInclusive, int endExclusive) { |
|
18158 | 1025 |
if (startInclusive >= endExclusive) { |
1026 |
return empty(); |
|
1027 |
} else { |
|
1028 |
return StreamSupport.intStream( |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
18820
diff
changeset
|
1029 |
new Streams.RangeIntSpliterator(startInclusive, endExclusive, false), false); |
18158 | 1030 |
} |
17195 | 1031 |
} |
1032 |
||
1033 |
/** |
|
19850 | 1034 |
* Returns a sequential ordered {@code IntStream} from {@code startInclusive} |
18158 | 1035 |
* (inclusive) to {@code endInclusive} (inclusive) by an incremental step of |
1036 |
* {@code 1}. |
|
17195 | 1037 |
* |
18158 | 1038 |
* @apiNote |
17195 | 1039 |
* <p>An equivalent sequence of increasing values can be produced |
1040 |
* sequentially using a {@code for} loop as follows: |
|
1041 |
* <pre>{@code |
|
18158 | 1042 |
* for (int i = startInclusive; i <= endInclusive ; i++) { ... } |
17195 | 1043 |
* }</pre> |
1044 |
* |
|
1045 |
* @param startInclusive the (inclusive) initial value |
|
18158 | 1046 |
* @param endInclusive the inclusive upper bound |
17195 | 1047 |
* @return a sequential {@code IntStream} for the range of {@code int} |
1048 |
* elements |
|
1049 |
*/ |
|
18158 | 1050 |
public static IntStream rangeClosed(int startInclusive, int endInclusive) { |
1051 |
if (startInclusive > endInclusive) { |
|
17195 | 1052 |
return empty(); |
1053 |
} else { |
|
18158 | 1054 |
return StreamSupport.intStream( |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
18820
diff
changeset
|
1055 |
new Streams.RangeIntSpliterator(startInclusive, endInclusive, true), false); |
17195 | 1056 |
} |
1057 |
} |
|
18820 | 1058 |
|
1059 |
/** |
|
19850 | 1060 |
* Creates a lazily concatenated stream whose elements are all the |
1061 |
* elements of the first stream followed by all the elements of the |
|
21339 | 1062 |
* second stream. The resulting stream is ordered if both |
18820 | 1063 |
* of the input streams are ordered, and parallel if either of the input |
19800 | 1064 |
* streams is parallel. When the resulting stream is closed, the close |
1065 |
* handlers for both input streams are invoked. |
|
18820 | 1066 |
* |
21339 | 1067 |
* @implNote |
1068 |
* Use caution when constructing streams from repeated concatenation. |
|
1069 |
* Accessing an element of a deeply concatenated stream can result in deep |
|
29103
1dbde34ad64c
8073779: StackOverflowError called StackOverflowException in javadoc
igerasim
parents:
25859
diff
changeset
|
1070 |
* call chains, or even {@code StackOverflowError}. |
21339 | 1071 |
* |
18820 | 1072 |
* @param a the first stream |
19850 | 1073 |
* @param b the second stream |
1074 |
* @return the concatenation of the two input streams |
|
18820 | 1075 |
*/ |
1076 |
public static IntStream concat(IntStream a, IntStream b) { |
|
1077 |
Objects.requireNonNull(a); |
|
1078 |
Objects.requireNonNull(b); |
|
1079 |
||
1080 |
Spliterator.OfInt split = new Streams.ConcatSpliterator.OfInt( |
|
1081 |
a.spliterator(), b.spliterator()); |
|
19800 | 1082 |
IntStream stream = StreamSupport.intStream(split, a.isParallel() || b.isParallel()); |
1083 |
return stream.onClose(Streams.composedClose(a, b)); |
|
18820 | 1084 |
} |
18825
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1085 |
|
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1086 |
/** |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1087 |
* A mutable builder for an {@code IntStream}. |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1088 |
* |
19850 | 1089 |
* <p>A stream builder has a lifecycle, which starts in a building |
1090 |
* phase, during which elements can be added, and then transitions to a built |
|
1091 |
* phase, after which elements may not be added. The built phase |
|
18825
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1092 |
* begins when the {@link #build()} method is called, which creates an |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1093 |
* ordered stream whose elements are the elements that were added to the |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1094 |
* stream builder, in the order they were added. |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1095 |
* |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1096 |
* @see IntStream#builder() |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1097 |
* @since 1.8 |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1098 |
*/ |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1099 |
public interface Builder extends IntConsumer { |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1100 |
|
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1101 |
/** |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1102 |
* Adds an element to the stream being built. |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1103 |
* |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1104 |
* @throws IllegalStateException if the builder has already transitioned |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1105 |
* to the built state |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1106 |
*/ |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1107 |
@Override |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1108 |
void accept(int t); |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1109 |
|
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1110 |
/** |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1111 |
* Adds an element to the stream being built. |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1112 |
* |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1113 |
* @implSpec |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1114 |
* The default implementation behaves as if: |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1115 |
* <pre>{@code |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1116 |
* accept(t) |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1117 |
* return this; |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1118 |
* }</pre> |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1119 |
* |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1120 |
* @param t the element to add |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1121 |
* @return {@code this} builder |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1122 |
* @throws IllegalStateException if the builder has already transitioned |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1123 |
* to the built state |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1124 |
*/ |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1125 |
default Builder add(int t) { |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1126 |
accept(t); |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1127 |
return this; |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1128 |
} |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1129 |
|
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1130 |
/** |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1131 |
* Builds the stream, transitioning this builder to the built state. |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1132 |
* An {@code IllegalStateException} is thrown if there are further |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1133 |
* attempts to operate on the builder after it has entered the built |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1134 |
* state. |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1135 |
* |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1136 |
* @return the built stream |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1137 |
* @throws IllegalStateException if the builder has already transitioned to |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1138 |
* the built state |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1139 |
*/ |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1140 |
IntStream build(); |
06636235cd12
8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents:
18822
diff
changeset
|
1141 |
} |
17167 | 1142 |
} |