author | henryjen |
Tue, 03 Sep 2013 12:16:01 -0700 | |
changeset 19800 | 6e1fef53ea55 |
parent 19047 | 08210fe86260 |
child 19850 | 93b368e54c1c |
permissions | -rw-r--r-- |
17182 | 1 |
/* |
19047
08210fe86260
8021408: Fix misc doclint issues in java.util and java.io
darcy
parents:
18822
diff
changeset
|
2 |
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
17182 | 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 |
*/ |
|
17931
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
44 |
public final class StreamSupport { |
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
45 |
|
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
46 |
// Suppresses default constructor, ensuring non-instantiability. |
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
47 |
private StreamSupport() {} |
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
48 |
|
17182 | 49 |
/** |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
50 |
* Creates a new sequential or parallel {@code Stream} from a |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
51 |
* {@code Spliterator}. |
17182 | 52 |
* |
53 |
* <p>The spliterator is only traversed, split, or queried for estimated |
|
54 |
* size after the terminal operation of the stream pipeline commences. |
|
55 |
* |
|
56 |
* <p>It is strongly recommended the spliterator report a characteristic of |
|
57 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be |
|
17931
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
58 |
* <a href="../Spliterator.html#binding">late-binding</a>. Otherwise, |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
59 |
* {@link #stream(java.util.function.Supplier, int, boolean)} should be used |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
60 |
* to reduce the scope of potential interference with the source. See |
17182 | 61 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for |
62 |
* more details. |
|
63 |
* |
|
64 |
* @param <T> the type of stream elements |
|
65 |
* @param spliterator a {@code Spliterator} describing the stream elements |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
66 |
* @param parallel if {@code true} then the returned stream is a parallel |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
67 |
* stream; if {@code false} the returned stream is a sequential |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
68 |
* stream. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
69 |
* @return a new sequential or parallel {@code Stream} |
17182 | 70 |
*/ |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
71 |
public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel) { |
17182 | 72 |
Objects.requireNonNull(spliterator); |
73 |
return new ReferencePipeline.Head<>(spliterator, |
|
74 |
StreamOpFlag.fromCharacteristics(spliterator), |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
75 |
parallel); |
17182 | 76 |
} |
77 |
||
78 |
/** |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
79 |
* Creates a new sequential or parallel {@code Stream} from a |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
80 |
* {@code Supplier} of {@code Spliterator}. |
17182 | 81 |
* |
82 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no |
|
83 |
* more than once, and after the terminal operation of the stream pipeline |
|
84 |
* commences. |
|
85 |
* |
|
86 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE} |
|
87 |
* or {@code CONCURRENT}, or that are |
|
17931
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
88 |
* <a href="../Spliterator.html#binding">late-binding</a>, it is likely |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
89 |
* more efficient to use {@link #stream(java.util.Spliterator, boolean)} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
90 |
* instead. |
17182 | 91 |
* The use of a {@code Supplier} in this form provides a level of |
92 |
* indirection that reduces the scope of potential interference with the |
|
93 |
* source. Since the supplier is only invoked after the terminal operation |
|
94 |
* commences, any modifications to the source up to the start of the |
|
95 |
* terminal operation are reflected in the stream result. See |
|
96 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for |
|
97 |
* more details. |
|
98 |
* |
|
19047
08210fe86260
8021408: Fix misc doclint issues in java.util and java.io
darcy
parents:
18822
diff
changeset
|
99 |
* @param <T> the type of stream elements |
17182 | 100 |
* @param supplier a {@code Supplier} of a {@code Spliterator} |
101 |
* @param characteristics Spliterator characteristics of the supplied |
|
102 |
* {@code Spliterator}. The characteristics must be equal to |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
103 |
* {@code supplier.get().characteristics()}. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
104 |
* @param parallel if {@code true} then the returned stream is a parallel |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
105 |
* stream; if {@code false} the returned stream is a sequential |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
106 |
* stream. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
107 |
* @return a new sequential or parallel {@code Stream} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
108 |
* @see #stream(java.util.Spliterator, boolean) |
17182 | 109 |
*/ |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
110 |
public static <T> Stream<T> stream(Supplier<? extends Spliterator<T>> supplier, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
111 |
int characteristics, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
112 |
boolean parallel) { |
17182 | 113 |
Objects.requireNonNull(supplier); |
114 |
return new ReferencePipeline.Head<>(supplier, |
|
115 |
StreamOpFlag.fromCharacteristics(characteristics), |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
116 |
parallel); |
17182 | 117 |
} |
118 |
||
119 |
/** |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
120 |
* Creates a new sequential or parallel {@code IntStream} from a |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
121 |
* {@code Spliterator.OfInt}. |
17182 | 122 |
* |
123 |
* <p>The spliterator is only traversed, split, or queried for estimated size |
|
124 |
* after the terminal operation of the stream pipeline commences. |
|
125 |
* |
|
126 |
* <p>It is strongly recommended the spliterator report a characteristic of |
|
127 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be |
|
17931
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
128 |
* <a href="../Spliterator.html#binding">late-binding</a>. Otherwise, |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
129 |
* {@link #intStream(java.util.function.Supplier, int, boolean)} should be |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
130 |
* used to reduce the scope of potential interference with the source. See |
17182 | 131 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for |
132 |
* more details. |
|
133 |
* |
|
134 |
* @param spliterator a {@code Spliterator.OfInt} describing the stream elements |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
135 |
* @param parallel if {@code true} then the returned stream is a parallel |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
136 |
* stream; if {@code false} the returned stream is a sequential |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
137 |
* stream. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
138 |
* @return a new sequential or parallel {@code IntStream} |
17182 | 139 |
*/ |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
140 |
public static IntStream intStream(Spliterator.OfInt spliterator, boolean parallel) { |
17182 | 141 |
return new IntPipeline.Head<>(spliterator, |
142 |
StreamOpFlag.fromCharacteristics(spliterator), |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
143 |
parallel); |
17182 | 144 |
} |
145 |
||
146 |
/** |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
147 |
* Creates a new sequential or parallel {@code IntStream} from a |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
148 |
* {@code Supplier} of {@code Spliterator.OfInt}. |
17182 | 149 |
* |
150 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no |
|
151 |
* more than once, and after the terminal operation of the stream pipeline |
|
152 |
* commences. |
|
153 |
* |
|
154 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE} |
|
155 |
* or {@code CONCURRENT}, or that are |
|
17931
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
156 |
* <a href="../Spliterator.html#binding">late-binding</a>, it is likely |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
157 |
* more efficient to use {@link #intStream(java.util.Spliterator.OfInt, boolean)} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
158 |
* instead. |
17182 | 159 |
* The use of a {@code Supplier} in this form provides a level of |
160 |
* indirection that reduces the scope of potential interference with the |
|
161 |
* source. Since the supplier is only invoked after the terminal operation |
|
162 |
* commences, any modifications to the source up to the start of the |
|
163 |
* terminal operation are reflected in the stream result. See |
|
164 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for |
|
165 |
* more details. |
|
166 |
* |
|
167 |
* @param supplier a {@code Supplier} of a {@code Spliterator.OfInt} |
|
168 |
* @param characteristics Spliterator characteristics of the supplied |
|
169 |
* {@code Spliterator.OfInt}. The characteristics must be equal to |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
170 |
* {@code supplier.get().characteristics()} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
171 |
* @param parallel if {@code true} then the returned stream is a parallel |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
172 |
* stream; if {@code false} the returned stream is a sequential |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
173 |
* stream. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
174 |
* @return a new sequential or parallel {@code IntStream} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
175 |
* @see #intStream(java.util.Spliterator.OfInt, boolean) |
17182 | 176 |
*/ |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
177 |
public static IntStream intStream(Supplier<? extends Spliterator.OfInt> supplier, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
178 |
int characteristics, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
179 |
boolean parallel) { |
17182 | 180 |
return new IntPipeline.Head<>(supplier, |
181 |
StreamOpFlag.fromCharacteristics(characteristics), |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
182 |
parallel); |
17182 | 183 |
} |
184 |
||
185 |
/** |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
186 |
* Creates a new sequential or parallel {@code LongStream} from a |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
187 |
* {@code Spliterator.OfLong}. |
17182 | 188 |
* |
189 |
* <p>The spliterator is only traversed, split, or queried for estimated |
|
190 |
* size after the terminal operation of the stream pipeline commences. |
|
191 |
* |
|
192 |
* <p>It is strongly recommended the spliterator report a characteristic of |
|
193 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be |
|
17931
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
194 |
* <a href="../Spliterator.html#binding">late-binding</a>. Otherwise, |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
195 |
* {@link #longStream(java.util.function.Supplier, int, boolean)} should be |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
196 |
* used to reduce the scope of potential interference with the source. See |
17182 | 197 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for |
198 |
* more details. |
|
199 |
* |
|
200 |
* @param spliterator a {@code Spliterator.OfLong} describing the stream elements |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
201 |
* @param parallel if {@code true} then the returned stream is a parallel |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
202 |
* stream; if {@code false} the returned stream is a sequential |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
203 |
* stream. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
204 |
* @return a new sequential or parallel {@code LongStream} |
17182 | 205 |
*/ |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
206 |
public static LongStream longStream(Spliterator.OfLong spliterator, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
207 |
boolean parallel) { |
17182 | 208 |
return new LongPipeline.Head<>(spliterator, |
209 |
StreamOpFlag.fromCharacteristics(spliterator), |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
210 |
parallel); |
17182 | 211 |
} |
212 |
||
213 |
/** |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
214 |
* Creates a new sequential or parallel {@code LongStream} from a |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
215 |
* {@code Supplier} of {@code Spliterator.OfLong}. |
17182 | 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 |
|
17931
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
223 |
* <a href="../Spliterator.html#binding">late-binding</a>, it is likely |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
224 |
* more efficient to use {@link #longStream(java.util.Spliterator.OfLong, boolean)} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
225 |
* instead. |
17182 | 226 |
* The use of a {@code Supplier} in this form provides a level of |
227 |
* indirection that reduces the scope of potential interference with the |
|
228 |
* source. Since the supplier is only invoked after the terminal operation |
|
229 |
* commences, any modifications to the source up to the start of the |
|
230 |
* terminal operation are reflected in the stream result. See |
|
231 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for |
|
232 |
* more details. |
|
233 |
* |
|
234 |
* @param supplier a {@code Supplier} of a {@code Spliterator.OfLong} |
|
235 |
* @param characteristics Spliterator characteristics of the supplied |
|
236 |
* {@code Spliterator.OfLong}. The characteristics must be equal to |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
237 |
* {@code supplier.get().characteristics()} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
238 |
* @param parallel if {@code true} then the returned stream is a parallel |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
239 |
* stream; if {@code false} the returned stream is a sequential |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
240 |
* stream. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
241 |
* @return a new sequential or parallel {@code LongStream} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
242 |
* @see #longStream(java.util.Spliterator.OfLong, boolean) |
17182 | 243 |
*/ |
244 |
public static LongStream longStream(Supplier<? extends Spliterator.OfLong> supplier, |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
245 |
int characteristics, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
246 |
boolean parallel) { |
17182 | 247 |
return new LongPipeline.Head<>(supplier, |
248 |
StreamOpFlag.fromCharacteristics(characteristics), |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
249 |
parallel); |
17182 | 250 |
} |
251 |
||
252 |
/** |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
253 |
* Creates a new sequential or parallel {@code DoubleStream} from a |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
254 |
* {@code Spliterator.OfDouble}. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
255 |
* |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
256 |
* <p>The spliterator is only traversed, split, or queried for estimated size |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
257 |
* after the terminal operation of the stream pipeline commences. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
258 |
* |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
259 |
* <p>It is strongly recommended the spliterator report a characteristic of |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
260 |
* {@code IMMUTABLE} or {@code CONCURRENT}, or be |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
261 |
* <a href="../Spliterator.html#binding">late-binding</a>. Otherwise, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
262 |
* {@link #doubleStream(java.util.function.Supplier, int, boolean)} should |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
263 |
* be used to reduce the scope of potential interference with the source. See |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
264 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
265 |
* more details. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
266 |
* |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
267 |
* @param spliterator A {@code Spliterator.OfDouble} describing the stream elements |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
268 |
* @param parallel if {@code true} then the returned stream is a parallel |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
269 |
* stream; if {@code false} the returned stream is a sequential |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
270 |
* stream. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
271 |
* @return a new sequential or parallel {@code DoubleStream} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
272 |
*/ |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
273 |
public static DoubleStream doubleStream(Spliterator.OfDouble spliterator, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
274 |
boolean parallel) { |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
275 |
return new DoublePipeline.Head<>(spliterator, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
276 |
StreamOpFlag.fromCharacteristics(spliterator), |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
277 |
parallel); |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
278 |
} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
279 |
|
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
280 |
/** |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
281 |
* Creates a new sequential or parallel {@code DoubleStream} from a |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
282 |
* {@code Supplier} of {@code Spliterator.OfDouble}. |
17182 | 283 |
* |
284 |
* <p>The {@link Supplier#get()} method will be invoked on the supplier no |
|
285 |
* more than once, and after the terminal operation of the stream pipeline |
|
286 |
* commences. |
|
287 |
* |
|
288 |
* <p>For spliterators that report a characteristic of {@code IMMUTABLE} |
|
289 |
* or {@code CONCURRENT}, or that are |
|
17931
765c1e9a498a
8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents:
17182
diff
changeset
|
290 |
* <a href="../Spliterator.html#binding">late-binding</a>, it is likely |
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
291 |
* more efficient to use {@link #doubleStream(java.util.Spliterator.OfDouble, boolean)} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
292 |
* instead. |
17182 | 293 |
* The use of a {@code Supplier} in this form provides a level of |
294 |
* indirection that reduces the scope of potential interference with the |
|
295 |
* source. Since the supplier is only invoked after the terminal operation |
|
296 |
* commences, any modifications to the source up to the start of the |
|
297 |
* terminal operation are reflected in the stream result. See |
|
298 |
* <a href="package-summary.html#Non-Interference">Non-Interference</a> for |
|
299 |
* more details. |
|
300 |
* |
|
301 |
* @param supplier A {@code Supplier} of a {@code Spliterator.OfDouble} |
|
302 |
* @param characteristics Spliterator characteristics of the supplied |
|
303 |
* {@code Spliterator.OfDouble}. The characteristics must be equal to |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
304 |
* {@code supplier.get().characteristics()} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
305 |
* @param parallel if {@code true} then the returned stream is a parallel |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
306 |
* stream; if {@code false} the returned stream is a sequential |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
307 |
* stream. |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
308 |
* @return a new sequential or parallel {@code DoubleStream} |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
309 |
* @see #doubleStream(java.util.Spliterator.OfDouble, boolean) |
17182 | 310 |
*/ |
311 |
public static DoubleStream doubleStream(Supplier<? extends Spliterator.OfDouble> supplier, |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
312 |
int characteristics, |
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
313 |
boolean parallel) { |
17182 | 314 |
return new DoublePipeline.Head<>(supplier, |
315 |
StreamOpFlag.fromCharacteristics(characteristics), |
|
18822
4b6be7c19547
8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents:
17931
diff
changeset
|
316 |
parallel); |
17182 | 317 |
} |
318 |
} |