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