17182
|
1 |
/*
|
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
|
|
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 |
|
|
27 |
import java.util.Objects;
|
|
28 |
import java.util.Spliterator;
|
|
29 |
import java.util.function.Supplier;
|
|
30 |
|
|
31 |
/**
|
|
32 |
* Low-level utility methods for creating and manipulating streams.
|
|
33 |
*
|
|
34 |
* <p>This class is mostly for library writers presenting stream views
|
|
35 |
* of their data structures; most static stream methods for end users are in
|
|
36 |
* {@link Streams}.
|
|
37 |
*
|
|
38 |
* <p>Unless otherwise stated, streams are created as sequential
|
|
39 |
* streams. A sequential stream can be transformed into a parallel stream by
|
|
40 |
* calling the {@code parallel()} method on the created stream.
|
|
41 |
*
|
|
42 |
* @since 1.8
|
|
43 |
*/
|
|
44 |
public class StreamSupport {
|
|
45 |
/**
|
|
46 |
* Creates a new sequential {@code Stream} from a {@code Spliterator}.
|
|
47 |
*
|
|
48 |
* <p>The spliterator is only traversed, split, or queried for estimated
|
|
49 |
* size after the terminal operation of the stream pipeline commences.
|
|
50 |
*
|
|
51 |
* <p>It is strongly recommended the spliterator report a characteristic of
|
|
52 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be
|
|
53 |
* <a href="Spliterator.html#binding">late-binding</a>. Otherwise,
|
|
54 |
* {@link #stream(Supplier, int)} should be used to
|
|
55 |
* reduce the scope of potential interference with the source. See
|
|
56 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
57 |
* more details.
|
|
58 |
*
|
|
59 |
* @param <T> the type of stream elements
|
|
60 |
* @param spliterator a {@code Spliterator} describing the stream elements
|
|
61 |
* @return a new sequential {@code Stream}
|
|
62 |
*/
|
|
63 |
public static <T> Stream<T> stream(Spliterator<T> spliterator) {
|
|
64 |
Objects.requireNonNull(spliterator);
|
|
65 |
return new ReferencePipeline.Head<>(spliterator,
|
|
66 |
StreamOpFlag.fromCharacteristics(spliterator),
|
|
67 |
false);
|
|
68 |
}
|
|
69 |
|
|
70 |
/**
|
|
71 |
* Creates a new parallel {@code Stream} from a {@code Spliterator}.
|
|
72 |
*
|
|
73 |
* <p>The spliterator is only traversed, split, or queried for estimated
|
|
74 |
* size after the terminal operation of the stream pipeline commences.
|
|
75 |
*
|
|
76 |
* <p>It is strongly recommended the spliterator report a characteristic of
|
|
77 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be
|
|
78 |
* <a href="Spliterator.html#binding">late-binding</a>. Otherwise,
|
|
79 |
* {@link #stream(Supplier, int)} should be used to
|
|
80 |
* reduce the scope of potential interference with the source. See
|
|
81 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
82 |
* more details.
|
|
83 |
*
|
|
84 |
* @param <T> the type of stream elements
|
|
85 |
* @param spliterator a {@code Spliterator} describing the stream elements
|
|
86 |
* @return a new parallel {@code Stream}
|
|
87 |
*/
|
|
88 |
public static <T> Stream<T> parallelStream(Spliterator<T> spliterator) {
|
|
89 |
Objects.requireNonNull(spliterator);
|
|
90 |
return new ReferencePipeline.Head<>(spliterator,
|
|
91 |
StreamOpFlag.fromCharacteristics(spliterator),
|
|
92 |
true);
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
* Creates a new sequential {@code Stream} from a {@code Supplier} of
|
|
97 |
* {@code Spliterator}.
|
|
98 |
*
|
|
99 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no
|
|
100 |
* more than once, and after the terminal operation of the stream pipeline
|
|
101 |
* commences.
|
|
102 |
*
|
|
103 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE}
|
|
104 |
* or {@code CONCURRENT}, or that are
|
|
105 |
* <a href="Spliterator.html#binding">late-binding</a>, it is likely
|
|
106 |
* more efficient to use {@link #stream(java.util.Spliterator)} instead.
|
|
107 |
* The use of a {@code Supplier} in this form provides a level of
|
|
108 |
* indirection that reduces the scope of potential interference with the
|
|
109 |
* source. Since the supplier is only invoked after the terminal operation
|
|
110 |
* commences, any modifications to the source up to the start of the
|
|
111 |
* terminal operation are reflected in the stream result. See
|
|
112 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
113 |
* more details.
|
|
114 |
*
|
|
115 |
* @param <T> the type of stream elements
|
|
116 |
* @param supplier a {@code Supplier} of a {@code Spliterator}
|
|
117 |
* @param characteristics Spliterator characteristics of the supplied
|
|
118 |
* {@code Spliterator}. The characteristics must be equal to
|
|
119 |
* {@code source.get().getCharacteristics()}.
|
|
120 |
* @return a new sequential {@code Stream}
|
|
121 |
* @see #stream(Spliterator)
|
|
122 |
*/
|
|
123 |
public static <T> Stream<T> stream(Supplier<? extends Spliterator<T>> supplier,
|
|
124 |
int characteristics) {
|
|
125 |
Objects.requireNonNull(supplier);
|
|
126 |
return new ReferencePipeline.Head<>(supplier,
|
|
127 |
StreamOpFlag.fromCharacteristics(characteristics),
|
|
128 |
false);
|
|
129 |
}
|
|
130 |
|
|
131 |
/**
|
|
132 |
* Creates a new parallel {@code Stream} from a {@code Supplier} of
|
|
133 |
* {@code Spliterator}.
|
|
134 |
*
|
|
135 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no
|
|
136 |
* more than once, and after the terminal operation of the stream pipeline
|
|
137 |
* commences.
|
|
138 |
*
|
|
139 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE}
|
|
140 |
* or {@code CONCURRENT}, or that are
|
|
141 |
* <a href="Spliterator.html#binding">late-binding</a>, it is likely
|
|
142 |
* more efficient to use {@link #stream(Spliterator)} instead.
|
|
143 |
* The use of a {@code Supplier} in this form provides a level of
|
|
144 |
* indirection that reduces the scope of potential interference with the
|
|
145 |
* source. Since the supplier is only invoked after the terminal operation
|
|
146 |
* commences, any modifications to the source up to the start of the
|
|
147 |
* terminal operation are reflected in the stream result. See
|
|
148 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
149 |
* more details.
|
|
150 |
*
|
|
151 |
* @param <T> the type of stream elements
|
|
152 |
* @param supplier a {@code Supplier} of a {@code Spliterator}
|
|
153 |
* @param characteristics Spliterator characteristics of the supplied
|
|
154 |
* {@code Spliterator}. The characteristics must be equal to
|
|
155 |
* {@code source.get().getCharacteristics()}
|
|
156 |
* @return a new parallel {@code Stream}
|
|
157 |
* @see #parallelStream(Spliterator)
|
|
158 |
*/
|
|
159 |
public static <T> Stream<T> parallelStream(Supplier<? extends Spliterator<T>> supplier,
|
|
160 |
int characteristics) {
|
|
161 |
Objects.requireNonNull(supplier);
|
|
162 |
return new ReferencePipeline.Head<>(supplier,
|
|
163 |
StreamOpFlag.fromCharacteristics(characteristics),
|
|
164 |
true);
|
|
165 |
}
|
|
166 |
|
|
167 |
/**
|
|
168 |
* Creates a new sequential {@code IntStream} from a {@code Spliterator.OfInt}.
|
|
169 |
*
|
|
170 |
* <p>The spliterator is only traversed, split, or queried for estimated size
|
|
171 |
* after the terminal operation of the stream pipeline commences.
|
|
172 |
*
|
|
173 |
* <p>It is strongly recommended the spliterator report a characteristic of
|
|
174 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be
|
|
175 |
* <a href="Spliterator.html#binding">late-binding</a>. Otherwise,
|
|
176 |
* {@link #stream(Supplier, int)}} should be used to
|
|
177 |
* reduce the scope of potential interference with the source. See
|
|
178 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
179 |
* more details.
|
|
180 |
*
|
|
181 |
* @param spliterator a {@code Spliterator.OfInt} describing the stream elements
|
|
182 |
* @return a new sequential {@code IntStream}
|
|
183 |
*/
|
|
184 |
public static IntStream intStream(Spliterator.OfInt spliterator) {
|
|
185 |
return new IntPipeline.Head<>(spliterator,
|
|
186 |
StreamOpFlag.fromCharacteristics(spliterator),
|
|
187 |
false);
|
|
188 |
}
|
|
189 |
|
|
190 |
/**
|
|
191 |
* Creates a new parallel {@code IntStream} from a {@code Spliterator.OfInt}.
|
|
192 |
*
|
|
193 |
* <p>he spliterator is only traversed, split, or queried for estimated size
|
|
194 |
* after the terminal operation of the stream pipeline commences.
|
|
195 |
*
|
|
196 |
* <p>It is strongly recommended the spliterator report a characteristic of
|
|
197 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be
|
|
198 |
* <a href="Spliterator.html#binding">late-binding</a>. Otherwise,
|
|
199 |
* {@link #stream(Supplier, int)}} should be used to
|
|
200 |
* reduce the scope of potential interference with the source. See
|
|
201 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
202 |
* more details.
|
|
203 |
*
|
|
204 |
* @param spliterator a {@code Spliterator.OfInt} describing the stream elements
|
|
205 |
* @return a new parallel {@code IntStream}
|
|
206 |
*/
|
|
207 |
public static IntStream intParallelStream(Spliterator.OfInt spliterator) {
|
|
208 |
return new IntPipeline.Head<>(spliterator,
|
|
209 |
StreamOpFlag.fromCharacteristics(spliterator),
|
|
210 |
true);
|
|
211 |
}
|
|
212 |
|
|
213 |
/**
|
|
214 |
* Creates a new sequential {@code IntStream} from a {@code Supplier} of
|
|
215 |
* {@code Spliterator.OfInt}.
|
|
216 |
*
|
|
217 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no
|
|
218 |
* more than once, and after the terminal operation of the stream pipeline
|
|
219 |
* commences.
|
|
220 |
*
|
|
221 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE}
|
|
222 |
* or {@code CONCURRENT}, or that are
|
|
223 |
* <a href="Spliterator.html#binding">late-binding</a>, it is likely
|
|
224 |
* more efficient to use {@link #intStream(Spliterator.OfInt)} instead.
|
|
225 |
* The use of a {@code Supplier} in this form provides a level of
|
|
226 |
* indirection that reduces the scope of potential interference with the
|
|
227 |
* source. Since the supplier is only invoked after the terminal operation
|
|
228 |
* commences, any modifications to the source up to the start of the
|
|
229 |
* terminal operation are reflected in the stream result. See
|
|
230 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
231 |
* more details.
|
|
232 |
*
|
|
233 |
* @param supplier a {@code Supplier} of a {@code Spliterator.OfInt}
|
|
234 |
* @param characteristics Spliterator characteristics of the supplied
|
|
235 |
* {@code Spliterator.OfInt}. The characteristics must be equal to
|
|
236 |
* {@code source.get().getCharacteristics()}
|
|
237 |
* @return a new sequential {@code IntStream}
|
|
238 |
* @see #intStream(Spliterator.OfInt)
|
|
239 |
*/
|
|
240 |
public static IntStream intStream(Supplier<? extends Spliterator.OfInt> supplier,
|
|
241 |
int characteristics) {
|
|
242 |
return new IntPipeline.Head<>(supplier,
|
|
243 |
StreamOpFlag.fromCharacteristics(characteristics),
|
|
244 |
false);
|
|
245 |
}
|
|
246 |
|
|
247 |
/**
|
|
248 |
* Creates a new parallel {@code IntStream} from a {@code Supplier} of
|
|
249 |
* {@code Spliterator.OfInt}.
|
|
250 |
*
|
|
251 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no
|
|
252 |
* more than once, and after the terminal operation of the stream pipeline
|
|
253 |
* commences.
|
|
254 |
*
|
|
255 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE}
|
|
256 |
* or {@code CONCURRENT}, or that are
|
|
257 |
* <a href="Spliterator.html#binding">late-binding</a>, it is likely
|
|
258 |
* more efficient to use {@link #intStream(Spliterator.OfInt)} instead.
|
|
259 |
* The use of a {@code Supplier} in this form provides a level of
|
|
260 |
* indirection that reduces the scope of potential interference with the
|
|
261 |
* source. Since the supplier is only invoked after the terminal operation
|
|
262 |
* commences, any modifications to the source up to the start of the
|
|
263 |
* terminal operation are reflected in the stream result. See
|
|
264 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
265 |
* more details.
|
|
266 |
*
|
|
267 |
* @param supplier a {@code Supplier} of a {@code Spliterator.OfInt}
|
|
268 |
* @param characteristics Spliterator characteristics of the supplied
|
|
269 |
* {@code Spliterator.OfInt}. The characteristics must be equal to
|
|
270 |
* {@code source.get().getCharacteristics()}
|
|
271 |
* @return a new parallel {@code IntStream}
|
|
272 |
* @see #intParallelStream(Spliterator.OfInt)
|
|
273 |
*/
|
|
274 |
public static IntStream intParallelStream(Supplier<? extends Spliterator.OfInt> supplier,
|
|
275 |
int characteristics) {
|
|
276 |
return new IntPipeline.Head<>(supplier,
|
|
277 |
StreamOpFlag.fromCharacteristics(characteristics),
|
|
278 |
true);
|
|
279 |
}
|
|
280 |
|
|
281 |
/**
|
|
282 |
* Creates a new sequential {@code LongStream} from a {@code Spliterator.OfLong}.
|
|
283 |
*
|
|
284 |
* <p>The spliterator is only traversed, split, or queried for estimated
|
|
285 |
* size after the terminal operation of the stream pipeline commences.
|
|
286 |
*
|
|
287 |
* <p>It is strongly recommended the spliterator report a characteristic of
|
|
288 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be
|
|
289 |
* <a href="Spliterator.html#binding">late-binding</a>. Otherwise,
|
|
290 |
* {@link #stream(Supplier, int)} should be used to
|
|
291 |
* reduce the scope of potential interference with the source. See
|
|
292 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
293 |
* more details.
|
|
294 |
*
|
|
295 |
* @param spliterator a {@code Spliterator.OfLong} describing the stream
|
|
296 |
* elements
|
|
297 |
* @return a new sequential {@code LongStream}
|
|
298 |
*/
|
|
299 |
public static LongStream longStream(Spliterator.OfLong spliterator) {
|
|
300 |
return new LongPipeline.Head<>(spliterator,
|
|
301 |
StreamOpFlag.fromCharacteristics(spliterator),
|
|
302 |
false);
|
|
303 |
}
|
|
304 |
|
|
305 |
/**
|
|
306 |
* Creates a new parallel {@code LongStream} from a {@code Spliterator.OfLong}.
|
|
307 |
*
|
|
308 |
* <p>The spliterator is only traversed, split, or queried for estimated
|
|
309 |
* size after the terminal operation of the stream pipeline commences.
|
|
310 |
*
|
|
311 |
* <p>It is strongly recommended the spliterator report a characteristic of
|
|
312 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be
|
|
313 |
* <a href="Spliterator.html#binding">late-binding</a>. Otherwise,
|
|
314 |
* {@link #stream(Supplier, int)} should be used to
|
|
315 |
* reduce the scope of potential interference with the source. See
|
|
316 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
317 |
* more details.
|
|
318 |
*
|
|
319 |
* @param spliterator a {@code Spliterator.OfLong} describing the stream elements
|
|
320 |
* @return a new parallel {@code LongStream}
|
|
321 |
*/
|
|
322 |
public static LongStream longParallelStream(Spliterator.OfLong spliterator) {
|
|
323 |
return new LongPipeline.Head<>(spliterator,
|
|
324 |
StreamOpFlag.fromCharacteristics(spliterator),
|
|
325 |
true);
|
|
326 |
}
|
|
327 |
|
|
328 |
/**
|
|
329 |
* Creates a new sequential {@code LongStream} from a {@code Supplier} of
|
|
330 |
* {@code Spliterator.OfLong}.
|
|
331 |
*
|
|
332 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no
|
|
333 |
* more than once, and after the terminal operation of the stream pipeline
|
|
334 |
* commences.
|
|
335 |
*
|
|
336 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE}
|
|
337 |
* or {@code CONCURRENT}, or that are
|
|
338 |
* <a href="Spliterator.html#binding">late-binding</a>, it is likely
|
|
339 |
* more efficient to use {@link #longStream(Spliterator.OfLong)} instead.
|
|
340 |
* The use of a {@code Supplier} in this form provides a level of
|
|
341 |
* indirection that reduces the scope of potential interference with the
|
|
342 |
* source. Since the supplier is only invoked after the terminal operation
|
|
343 |
* commences, any modifications to the source up to the start of the
|
|
344 |
* terminal operation are reflected in the stream result. See
|
|
345 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
346 |
* more details.
|
|
347 |
*
|
|
348 |
* @param supplier a {@code Supplier} of a {@code Spliterator.OfLong}
|
|
349 |
* @param characteristics Spliterator characteristics of the supplied
|
|
350 |
* {@code Spliterator.OfLong}. The characteristics must be equal to
|
|
351 |
* {@code source.get().getCharacteristics()}
|
|
352 |
* @return a new sequential {@code LongStream}
|
|
353 |
* @see #longStream(Spliterator.OfLong)
|
|
354 |
*/
|
|
355 |
public static LongStream longStream(Supplier<? extends Spliterator.OfLong> supplier,
|
|
356 |
int characteristics) {
|
|
357 |
return new LongPipeline.Head<>(supplier,
|
|
358 |
StreamOpFlag.fromCharacteristics(characteristics),
|
|
359 |
false);
|
|
360 |
}
|
|
361 |
|
|
362 |
/**
|
|
363 |
* Creates a new parallel {@code LongStream} from a {@code Supplier} of
|
|
364 |
* {@code Spliterator.OfLong}.
|
|
365 |
*
|
|
366 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no
|
|
367 |
* more than once, and after the terminal operation of the stream pipeline
|
|
368 |
* commences.
|
|
369 |
*
|
|
370 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE}
|
|
371 |
* or {@code CONCURRENT}, or that are
|
|
372 |
* <a href="Spliterator.html#binding">late-binding</a>, it is likely
|
|
373 |
* more efficient to use {@link #longStream(Spliterator.OfLong)} instead.
|
|
374 |
* The use of a {@code Supplier} in this form provides a level of
|
|
375 |
* indirection that reduces the scope of potential interference with the
|
|
376 |
* source. Since the supplier is only invoked after the terminal operation
|
|
377 |
* commences, any modifications to the source up to the start of the
|
|
378 |
* terminal operation are reflected in the stream result. See
|
|
379 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
380 |
* more details.
|
|
381 |
*
|
|
382 |
* @param supplier A {@code Supplier} of a {@code Spliterator.OfLong}
|
|
383 |
* @param characteristics Spliterator characteristics of the supplied
|
|
384 |
* {@code Spliterator.OfLong}. The characteristics must be equal to
|
|
385 |
* {@code source.get().getCharacteristics()}
|
|
386 |
* @return A new parallel {@code LongStream}
|
|
387 |
* @see #longParallelStream(Spliterator.OfLong)
|
|
388 |
*/
|
|
389 |
public static LongStream longParallelStream(Supplier<? extends Spliterator.OfLong> supplier,
|
|
390 |
int characteristics) {
|
|
391 |
return new LongPipeline.Head<>(supplier,
|
|
392 |
StreamOpFlag.fromCharacteristics(characteristics),
|
|
393 |
true);
|
|
394 |
}
|
|
395 |
|
|
396 |
/**
|
|
397 |
* Creates a new sequential {@code DoubleStream} from a
|
|
398 |
* {@code Spliterator.OfDouble}.
|
|
399 |
*
|
|
400 |
* <p>The spliterator is only traversed, split, or queried for estimated size
|
|
401 |
* after the terminal operation of the stream pipeline commences.
|
|
402 |
*
|
|
403 |
* <p>It is strongly recommended the spliterator report a characteristic of
|
|
404 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be
|
|
405 |
* <a href="Spliterator.html#binding">late-binding</a>. Otherwise,
|
|
406 |
* {@link #stream(Supplier, int)} should be used to
|
|
407 |
* reduce the scope of potential interference with the source. See
|
|
408 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
409 |
* more details.
|
|
410 |
*
|
|
411 |
* @param spliterator A {@code Spliterator.OfDouble} describing the stream elements
|
|
412 |
* @return A new sequential {@code DoubleStream}
|
|
413 |
*/
|
|
414 |
public static DoubleStream doubleStream(Spliterator.OfDouble spliterator) {
|
|
415 |
return new DoublePipeline.Head<>(spliterator,
|
|
416 |
StreamOpFlag.fromCharacteristics(spliterator),
|
|
417 |
false);
|
|
418 |
}
|
|
419 |
|
|
420 |
/**
|
|
421 |
* Creates a new parallel {@code DoubleStream} from a
|
|
422 |
* {@code Spliterator.OfDouble}.
|
|
423 |
*
|
|
424 |
* <p>The spliterator is only traversed, split, or queried for estimated size
|
|
425 |
* after the terminal operation of the stream pipeline commences.
|
|
426 |
*
|
|
427 |
* <p>It is strongly recommended the spliterator report a characteristic of
|
|
428 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be
|
|
429 |
* <a href="Spliterator.html#binding">late-binding</a>. Otherwise,
|
|
430 |
* {@link #stream(Supplier, int)} should be used to
|
|
431 |
* reduce the scope of potential interference with the source. See
|
|
432 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
433 |
* more details.
|
|
434 |
*
|
|
435 |
* @param spliterator A {@code Spliterator.OfDouble} describing the stream elements
|
|
436 |
* @return A new parallel {@code DoubleStream}
|
|
437 |
*/
|
|
438 |
public static DoubleStream doubleParallelStream(Spliterator.OfDouble spliterator) {
|
|
439 |
return new DoublePipeline.Head<>(spliterator,
|
|
440 |
StreamOpFlag.fromCharacteristics(spliterator),
|
|
441 |
true);
|
|
442 |
}
|
|
443 |
|
|
444 |
/**
|
|
445 |
* Creates a new sequential {@code DoubleStream} from a {@code Supplier} of
|
|
446 |
* {@code Spliterator.OfDouble}.
|
|
447 |
* <p>
|
|
448 |
* The {@link Supplier#get()} method will be invoked on the supplier no
|
|
449 |
* more than once, and after the terminal operation of the stream pipeline
|
|
450 |
* commences.
|
|
451 |
* <p>
|
|
452 |
* For spliterators that report a characteristic of {@code IMMUTABLE}
|
|
453 |
* or {@code CONCURRENT}, or that are
|
|
454 |
* <a href="Spliterator.html#binding">late-binding</a>, it is likely
|
|
455 |
* more efficient to use {@link #doubleStream(Spliterator.OfDouble)} instead.
|
|
456 |
* The use of a {@code Supplier} in this form provides a level of
|
|
457 |
* indirection that reduces the scope of potential interference with the
|
|
458 |
* source. Since the supplier is only invoked after the terminal operation
|
|
459 |
* commences, any modifications to the source up to the start of the
|
|
460 |
* terminal operation are reflected in the stream result. See
|
|
461 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
462 |
* more details.
|
|
463 |
*
|
|
464 |
* @param supplier A {@code Supplier} of a {@code Spliterator.OfDouble}
|
|
465 |
* @param characteristics Spliterator characteristics of the supplied
|
|
466 |
* {@code Spliterator.OfDouble}. The characteristics must be equal to
|
|
467 |
* {@code source.get().getCharacteristics()}
|
|
468 |
* @return A new sequential {@code DoubleStream}
|
|
469 |
* @see #doubleStream(Spliterator.OfDouble)
|
|
470 |
*/
|
|
471 |
public static DoubleStream doubleStream(Supplier<? extends Spliterator.OfDouble> supplier,
|
|
472 |
int characteristics) {
|
|
473 |
return new DoublePipeline.Head<>(supplier,
|
|
474 |
StreamOpFlag.fromCharacteristics(characteristics),
|
|
475 |
false);
|
|
476 |
}
|
|
477 |
|
|
478 |
/**
|
|
479 |
* Creates a new parallel {@code DoubleStream} from a {@code Supplier} of
|
|
480 |
* {@code Spliterator.OfDouble}.
|
|
481 |
*
|
|
482 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no
|
|
483 |
* more than once, and after the terminal operation of the stream pipeline
|
|
484 |
* commences.
|
|
485 |
*
|
|
486 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE}
|
|
487 |
* or {@code CONCURRENT}, or that are
|
|
488 |
* <a href="Spliterator.html#binding">late-binding</a>, it is likely
|
|
489 |
* more efficient to use {@link #doubleStream(Spliterator.OfDouble)} instead.
|
|
490 |
* The use of a {@code Supplier} in this form provides a level of
|
|
491 |
* indirection that reduces the scope of potential interference with the
|
|
492 |
* source. Since the supplier is only invoked after the terminal operation
|
|
493 |
* commences, any modifications to the source up to the start of the
|
|
494 |
* terminal operation are reflected in the stream result. See
|
|
495 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for
|
|
496 |
* more details.
|
|
497 |
*
|
|
498 |
* @param supplier a {@code Supplier} of a {@code Spliterator.OfDouble}
|
|
499 |
* @param characteristics Spliterator characteristics of the supplied
|
|
500 |
* {@code Spliterator.OfDouble}. The characteristics must be equal to
|
|
501 |
* {@code source.get().getCharacteristics()}
|
|
502 |
* @return a new parallel {@code DoubleStream}
|
|
503 |
* @see #doubleParallelStream(Spliterator.OfDouble)
|
|
504 |
*/
|
|
505 |
public static DoubleStream doubleParallelStream(Supplier<? extends Spliterator.OfDouble> supplier,
|
|
506 |
int characteristics) {
|
|
507 |
return new DoublePipeline.Head<>(supplier,
|
|
508 |
StreamOpFlag.fromCharacteristics(characteristics),
|
|
509 |
true);
|
|
510 |
}
|
|
511 |
}
|