| 1 | /* | |
| 2 | * Copyright 2014-2026 Grzegorz Piwowarek, https://4comprehension.com/ | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package com.pivovarit.collectors; | |
| 17 | ||
| 18 | import java.util.List; | |
| 19 | import java.util.Objects; | |
| 20 | import java.util.concurrent.CompletableFuture; | |
| 21 | import java.util.function.Consumer; | |
| 22 | import java.util.function.Function; | |
| 23 | import java.util.stream.Collector; | |
| 24 | import java.util.stream.Stream; | |
| 25 | import org.jspecify.annotations.NullMarked; | |
| 26 | ||
| 27 | /** | |
| 28 | * An umbrella class exposing static factory methods for instantiating parallel {@link Collector}s | |
| 29 | * | |
| 30 | * @author Grzegorz Piwowarek | |
| 31 | */ | |
| 32 | @NullMarked | |
| 33 | public final class ParallelCollectors { | |
| 34 | ||
| 35 | private ParallelCollectors() { | |
| 36 | } | |
| 37 | ||
| 38 | // defaults | |
| 39 | ||
| 40 | /** | |
| 41 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 42 | * and returns a {@link CompletableFuture} containing the result of applying the user-provided | |
| 43 | * {@link Collector} to the mapped elements. | |
| 44 | * <p> | |
| 45 | * Each element is transformed using the provided {@code mapper} in parallel on Virtual Threads, | |
| 46 | * and the results are reduced according to the supplied {@code collector}. | |
| 47 | * | |
| 48 | * <p><b>Note:</b> This collector does not limit parallelism in any way (it may spawn work for every | |
| 49 | * element). As a result, it is not suitable for processing huge streams. | |
| 50 | * | |
| 51 | * <br> | |
| 52 | * Example: | |
| 53 | * <pre>{@code | |
| 54 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 55 | * .collect(parallel(i -> foo(i), toList())); | |
| 56 | * }</pre> | |
| 57 | * | |
| 58 | * @param mapper transformation applied to each element | |
| 59 | * @param collector the {@code Collector} describing the reduction | |
| 60 | * @param <T> the input element type | |
| 61 | * @param <R> the type produced by {@code mapper} | |
| 62 | * @param <RR> the reduction result type produced by {@code collector} | |
| 63 | * | |
| 64 | * @return a {@code Collector} producing a {@link CompletableFuture} of the reduced result | |
| 65 | * | |
| 66 | * @since 4.0.0 | |
| 67 | */ | |
| 68 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel( | |
| 69 | Function<? super T, ? extends R> mapper, | |
| 70 | Collector<R, ?, RR> collector) { | |
| 71 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 72 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 73 | ||
| 74 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$0 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$0 → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, c -> {}); |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 79 | * and returns a {@link CompletableFuture} containing a {@link Stream} of the mapped results. | |
| 80 | * <p> | |
| 81 | * Each element is transformed using the provided {@code mapper} in parallel on Virtual Threads. | |
| 82 | * Unlike {@link #parallel(Function, Collector)}, this overload does not perform a reduction; it | |
| 83 | * simply collects and exposes the mapped elements as a {@code Stream} in the resulting future. | |
| 84 | * | |
| 85 | * <p><b>Note:</b> This collector does not limit parallelism in any way (it may spawn work for every | |
| 86 | * element). As a result, it is not suitable for processing huge streams. | |
| 87 | * | |
| 88 | * <br> | |
| 89 | * Example: | |
| 90 | * <pre>{@code | |
| 91 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 92 | * .collect(parallel(i -> foo(i))); | |
| 93 | * | |
| 94 | * result.thenAccept(s -> s.forEach(System.out::println)); | |
| 95 | * }</pre> | |
| 96 | * | |
| 97 | * @param mapper transformation applied to each element | |
| 98 | * @param <T> the input element type | |
| 99 | * @param <R> the type produced by {@code mapper} | |
| 100 | * | |
| 101 | * @return a {@code Collector} producing a {@code CompletableFuture} of a {@code Stream} of mapped elements | |
| 102 | * | |
| 103 | * @since 3.0.0 | |
| 104 | */ | |
| 105 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel( | |
| 106 | Function<? super T, ? extends R> mapper) { | |
| 107 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 108 | ||
| 109 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$2 : replaced return value with Stream.empty for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$2 → KILLED |
return Factory.collecting((Function<Stream<R>, Stream<R>>) s -> s, mapper, c -> {}); |
| 110 | } | |
| 111 | ||
| 112 | /** | |
| 113 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 114 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 115 | * emitting {@link Group} entries representing each group. | |
| 116 | * <p> | |
| 117 | * Each element is classified using {@code classifier}, then transformed using {@code mapper} in | |
| 118 | * parallel on Virtual Threads. The resulting {@link Group} entries are exposed as a | |
| 119 | * {@link CompletableFuture} of {@code Stream<Group<K, R>>}. | |
| 120 | * | |
| 121 | * <p><b>Note:</b> This collector does not limit parallelism in any way (it may spawn work for every | |
| 122 | * element). As a result, it is not suitable for processing huge streams. | |
| 123 | * | |
| 124 | * <br> | |
| 125 | * Example: | |
| 126 | * <pre>{@code | |
| 127 | * CompletableFuture<Stream<Group<String, String>>> result = Stream.of(t1, t2, t3) | |
| 128 | * .collect(parallelBy(Task::groupId, t -> compute(t))); | |
| 129 | * }</pre> | |
| 130 | * | |
| 131 | * @param classifier function that assigns a grouping key to each element | |
| 132 | * @param mapper transformation applied to each element | |
| 133 | * @param <T> the input element type | |
| 134 | * @param <K> the classification key type | |
| 135 | * @param <R> the type produced by {@code mapper} | |
| 136 | * | |
| 137 | * @return a {@code Collector} producing a {@link CompletableFuture} of a {@code Stream} of grouped results | |
| 138 | * | |
| 139 | * @since 3.4.0 | |
| 140 | */ | |
| 141 | public static <T, K, R> Collector<T, ?, CompletableFuture<Stream<Group<K, R>>>> parallelBy( | |
| 142 | Function<? super T, ? extends K> classifier, | |
| 143 | Function<? super T, ? extends R> mapper) { | |
| 144 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 145 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 146 | ||
| 147 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, mapper, c -> {}); |
| 148 | } | |
| 149 | ||
| 150 | /** | |
| 151 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 152 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 153 | * emitting {@link Group} entries representing each group. | |
| 154 | * <p> | |
| 155 | * The generated {@link Stream} of {@code Group<K, R>} instances is then reduced using the | |
| 156 | * user-provided {@code collector}, executed on Virtual Threads. Each group is processed | |
| 157 | * independently, and every group is guaranteed to be processed on a single thread. | |
| 158 | * The reduction is applied to the grouped results rather than to the raw mapped elements. | |
| 159 | * | |
| 160 | * <p><b>Note:</b> This collector does not limit parallelism in any way (it may spawn work for every | |
| 161 | * element). As a result, it is not suitable for processing huge streams. | |
| 162 | * | |
| 163 | * <br> | |
| 164 | * Example: | |
| 165 | * <pre>{@code | |
| 166 | * CompletableFuture<List<Group<String, String>>> result = Stream.of(t1, t2, t3) | |
| 167 | * .collect(parallelBy(Task::groupId, t -> compute(t), toList())); | |
| 168 | * }</pre> | |
| 169 | * | |
| 170 | * @param classifier function that assigns a grouping key to each element | |
| 171 | * @param mapper transformation applied to each element | |
| 172 | * @param collector the {@code Collector} describing the reduction of the grouped results | |
| 173 | * @param <T> the input element type | |
| 174 | * @param <K> the classification key type | |
| 175 | * @param <R> the type produced by {@code mapper} | |
| 176 | * @param <RR> the reduction result type produced by {@code collector} | |
| 177 | * | |
| 178 | * @return a {@code Collector} producing a {@link CompletableFuture} whose value is obtained | |
| 179 | * by reducing the {@code Stream<Group<K, R>>} produced by the parallel classification | |
| 180 | * | |
| 181 | * @since 3.4.0 | |
| 182 | */ | |
| 183 | public static <T, K, R, RR> Collector<T, ?, CompletableFuture<RR>> parallelBy( | |
| 184 | Function<? super T, ? extends K> classifier, | |
| 185 | Function<? super T, ? extends R> mapper, | |
| 186 | Collector<Group<K, R>, ?, RR> collector) { | |
| 187 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 188 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 189 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 190 | ||
| 191 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy( |
| 192 | classifier, | |
| 193 |
1
1. lambda$parallelBy$1 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallelBy$1 → KILLED |
(Function<Stream<Group<K, R>>, RR>) s -> s.collect(collector), |
| 194 | mapper, | |
| 195 | c -> {}); | |
| 196 | } | |
| 197 | ||
| 198 | /** | |
| 199 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 200 | * and returns a {@link Stream} of the mapped results. | |
| 201 | * <p> | |
| 202 | * Each element is transformed using the provided {@code mapper} in parallel on Virtual Threads, | |
| 203 | * and the mapped elements are exposed as a {@code Stream}. | |
| 204 | * | |
| 205 | * <p><b>Ordering:</b> This collector emits elements in an <em>arbitrary</em> order. To preserve encounter | |
| 206 | * order, use the {@link StreamingConfigurer} overload and configure {@link StreamingConfigurer#ordered()}. | |
| 207 | * | |
| 208 | * <p><b>Note:</b> This collector does not limit parallelism in any way (it may spawn work for every | |
| 209 | * element). As a result, it is not suitable for processing huge streams. | |
| 210 | * | |
| 211 | * <br> | |
| 212 | * Example: | |
| 213 | * <pre>{@code | |
| 214 | * Stream<String> result = Stream.of(1, 2, 3) | |
| 215 | * .collect(parallelToStream(i -> foo(i))); | |
| 216 | * }</pre> | |
| 217 | * | |
| 218 | * @param mapper transformation applied to each element | |
| 219 | * @param <T> the input element type | |
| 220 | * @param <R> the type produced by {@code mapper} | |
| 221 | * | |
| 222 | * @return a {@code Collector} producing a {@code Stream} of mapped elements | |
| 223 | * | |
| 224 | * @since 3.0.0 | |
| 225 | */ | |
| 226 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream( | |
| 227 | Function<? super T, ? extends R> mapper) { | |
| 228 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 229 | ||
| 230 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper, c -> {}); |
| 231 | } | |
| 232 | ||
| 233 | /** | |
| 234 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 235 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 236 | * emitting {@link Group} entries representing each group. | |
| 237 | * <p> | |
| 238 | * Each element is classified using {@code classifier}, then transformed using {@code mapper} in | |
| 239 | * parallel on Virtual Threads. The resulting grouped entries are exposed as a | |
| 240 | * {@code Stream<Group<K, R>>}. | |
| 241 | * | |
| 242 | * <p><b>Ordering:</b> This collector emits {@link Group} elements in an <em>arbitrary</em> order. | |
| 243 | * To preserve encounter order, use the {@link StreamingConfigurer} overload and configure | |
| 244 | * {@link StreamingConfigurer#ordered()}. | |
| 245 | * | |
| 246 | * <p><b>Note:</b> This collector does not limit parallelism in any way (it may spawn work for every | |
| 247 | * element). As a result, it is not suitable for processing huge streams. | |
| 248 | * | |
| 249 | * <br> | |
| 250 | * Example: | |
| 251 | * <pre>{@code | |
| 252 | * Stream<Group<String, String>> result = Stream.of(t1, t2, t3) | |
| 253 | * .collect(parallelToStreamBy(Task::groupId, t -> compute(t))); | |
| 254 | * }</pre> | |
| 255 | * | |
| 256 | * @param classifier function that assigns a grouping key to each element | |
| 257 | * @param mapper transformation applied to each element | |
| 258 | * @param <T> the input element type | |
| 259 | * @param <K> the classification key type | |
| 260 | * @param <R> the type produced by {@code mapper} | |
| 261 | * | |
| 262 | * @return a {@code Collector} producing a {@code Stream} of grouped results | |
| 263 | * | |
| 264 | * @since 3.4.0 | |
| 265 | */ | |
| 266 | public static <T, K, R> Collector<T, ?, Stream<Group<K, R>>> parallelToStreamBy( | |
| 267 | Function<? super T, ? extends K> classifier, | |
| 268 | Function<? super T, ? extends R> mapper) { | |
| 269 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 270 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 271 | ||
| 272 |
1
1. parallelToStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, c -> {}); |
| 273 | } | |
| 274 | ||
| 275 | // configurers | |
| 276 | ||
| 277 | /** | |
| 278 | * A convenience {@link Collector} that performs parallel computations (by default on Virtual Threads) | |
| 279 | * and returns a {@link CompletableFuture} containing a {@link Stream} of the mapped results, | |
| 280 | * with additional configuration applied via the provided {@code configurer}. | |
| 281 | * <p> | |
| 282 | * Each element is transformed using the provided {@code mapper} in parallel. Unless overridden via | |
| 283 | * {@link CollectingConfigurer#executor(java.util.concurrent.Executor)}, tasks are executed on | |
| 284 | * Virtual Threads. The {@code configurer} can also be used to enable batching and/or set a maximum | |
| 285 | * parallelism level. | |
| 286 | * | |
| 287 | * <p><b>Note:</b> Unless the {@code configurer} explicitly limits parallelism (e.g. via | |
| 288 | * {@link CollectingConfigurer#parallelism(int)}), this collector does not limit parallelism in any | |
| 289 | * way (it may spawn work for every element). As a result, it is not suitable for processing huge | |
| 290 | * streams. | |
| 291 | * | |
| 292 | * <p><b>Note:</b> For more information on available configuration options, see | |
| 293 | * {@link CollectingConfigurer}. | |
| 294 | * | |
| 295 | * <br> | |
| 296 | * Example: | |
| 297 | * <pre>{@code | |
| 298 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 299 | * .collect(parallel(i -> foo(i), c -> c | |
| 300 | * .parallelism(64) | |
| 301 | * .batching() | |
| 302 | * )); | |
| 303 | * }</pre> | |
| 304 | * | |
| 305 | * @param mapper transformation applied to each element | |
| 306 | * @param configurer callback used to configure execution (see {@link CollectingConfigurer}) | |
| 307 | * @param <T> the input element type | |
| 308 | * @param <R> the type produced by {@code mapper} | |
| 309 | * | |
| 310 | * @return a {@code Collector} producing a {@code CompletableFuture} of a {@code Stream} of mapped elements | |
| 311 | * | |
| 312 | * @since 4.0.0 | |
| 313 | */ | |
| 314 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel( | |
| 315 | Function<? super T, ? extends R> mapper, | |
| 316 | Consumer<CollectingConfigurer> configurer) { | |
| 317 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 318 | Objects.requireNonNull(configurer, "configurer cannot be null"); | |
| 319 | ||
| 320 |
2
1. lambda$parallel$4 : replaced return value with Stream.empty for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$4 → KILLED 2. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED |
return Factory.collecting((Function<Stream<R>, Stream<R>>) i -> i, mapper, configurer); |
| 321 | } | |
| 322 | ||
| 323 | /** | |
| 324 | * A convenience {@link Collector} that performs parallel computations (by default on Virtual Threads) | |
| 325 | * and returns a {@link CompletableFuture} containing the result of applying the user-provided | |
| 326 | * {@link Collector} to the mapped elements, with additional configuration applied via the provided | |
| 327 | * {@code configurer}. | |
| 328 | * <p> | |
| 329 | * Each element is transformed using the provided {@code mapper} in parallel, and the results are | |
| 330 | * reduced according to the supplied {@code collector}. Unless overridden via | |
| 331 | * {@link CollectingConfigurer#executor(java.util.concurrent.Executor)}, tasks are executed on | |
| 332 | * Virtual Threads. The {@code configurer} can also be used to enable batching and/or limit the | |
| 333 | * maximum parallelism. | |
| 334 | * | |
| 335 | * <p><b>Note:</b> Unless the {@code configurer} explicitly limits parallelism (e.g. via | |
| 336 | * {@link CollectingConfigurer#parallelism(int)}), this collector does not limit parallelism in any | |
| 337 | * way (it may spawn work for every element). As a result, it is not suitable for processing huge | |
| 338 | * streams. | |
| 339 | * | |
| 340 | * <p><b>Note:</b> For more information on available configuration options, see | |
| 341 | * {@link CollectingConfigurer}. | |
| 342 | * | |
| 343 | * <br> | |
| 344 | * Example: | |
| 345 | * <pre>{@code | |
| 346 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 347 | * .collect(parallel(i -> foo(i), c -> c | |
| 348 | * .parallelism(64) | |
| 349 | * .batching(), | |
| 350 | * toList() | |
| 351 | * )); | |
| 352 | * }</pre> | |
| 353 | * | |
| 354 | * @param mapper transformation applied to each element | |
| 355 | * @param collector the {@code Collector} describing the reduction | |
| 356 | * @param configurer callback used to configure execution (see {@link CollectingConfigurer}) | |
| 357 | * @param <T> the input element type | |
| 358 | * @param <R> the type produced by {@code mapper} | |
| 359 | * @param <RR> the reduction result type produced by {@code collector} | |
| 360 | * | |
| 361 | * @return a {@code Collector} producing a {@link CompletableFuture} of the reduced result | |
| 362 | * | |
| 363 | * @since 4.0.0 | |
| 364 | */ | |
| 365 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel( | |
| 366 | Function<? super T, ? extends R> mapper, | |
| 367 | Consumer<CollectingConfigurer> configurer, | |
| 368 | Collector<R, ?, RR> collector) { | |
| 369 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 370 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 371 | Objects.requireNonNull(configurer, "configurer cannot be null"); | |
| 372 | ||
| 373 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$5 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$5 → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, configurer); |
| 374 | } | |
| 375 | ||
| 376 | /** | |
| 377 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 378 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 379 | * emitting {@link Group} entries representing each group, with additional configuration applied | |
| 380 | * via the provided {@code configurer}. | |
| 381 | * <p> | |
| 382 | * Each element is classified using {@code classifier}, then transformed using {@code mapper} in | |
| 383 | * parallel. Unless overridden via {@link CollectingConfigurer#executor(java.util.concurrent.Executor)}, | |
| 384 | * tasks are executed on Virtual Threads. The resulting grouped entries are exposed as a | |
| 385 | * {@link CompletableFuture} of {@code Stream<Group<K, R>>}. The {@code configurer} can also be used | |
| 386 | * to enable batching and/or set a maximum parallelism level. | |
| 387 | * | |
| 388 | * <p><b>Note:</b> Unless the {@code configurer} explicitly limits parallelism (e.g. via | |
| 389 | * {@link CollectingConfigurer#parallelism(int)}), this collector does not limit parallelism in any | |
| 390 | * way (it may spawn work for every element). As a result, it is not suitable for processing huge | |
| 391 | * streams. | |
| 392 | * | |
| 393 | * <p><b>Note:</b> For more information on available configuration options, see | |
| 394 | * {@link CollectingConfigurer}. | |
| 395 | * | |
| 396 | * <br> | |
| 397 | * Example: | |
| 398 | * <pre>{@code | |
| 399 | * CompletableFuture<Stream<Group<String, String>>> result = Stream.of(t1, t2, t3) | |
| 400 | * .collect(parallelBy(Task::groupId, t -> compute(t), c -> c | |
| 401 | * .parallelism(64) | |
| 402 | * .batching() | |
| 403 | * )); | |
| 404 | * }</pre> | |
| 405 | * | |
| 406 | * @param classifier function that assigns a grouping key to each element | |
| 407 | * @param mapper transformation applied to each element | |
| 408 | * @param configurer callback used to configure execution (see {@link CollectingConfigurer}) | |
| 409 | * @param <T> the input element type | |
| 410 | * @param <K> the classification key type | |
| 411 | * @param <R> the type produced by {@code mapper} | |
| 412 | * | |
| 413 | * @return a {@code Collector} producing a {@link CompletableFuture} of a {@code Stream} of grouped results | |
| 414 | * | |
| 415 | * @since 4.0.0 | |
| 416 | */ | |
| 417 | public static <T, K, R> Collector<T, ?, CompletableFuture<Stream<Group<K, R>>>> parallelBy( | |
| 418 | Function<? super T, ? extends K> classifier, | |
| 419 | Function<? super T, ? extends R> mapper, | |
| 420 | Consumer<CollectingConfigurer> configurer) { | |
| 421 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 422 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 423 | Objects.requireNonNull(configurer, "configurer cannot be null"); | |
| 424 | ||
| 425 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, mapper, configurer); |
| 426 | } | |
| 427 | ||
| 428 | /** | |
| 429 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 430 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 431 | * emitting {@link Group} entries representing each group, and then reducing them using the | |
| 432 | * user-provided {@code collector}, with additional configuration applied via the provided | |
| 433 | * {@code configurer}. | |
| 434 | * <p> | |
| 435 | * The generated {@link Stream} of {@code Group<K, R>} instances is reduced using the supplied | |
| 436 | * {@code collector}, executed on Virtual Threads by default (unless overridden via | |
| 437 | * {@link CollectingConfigurer#executor(java.util.concurrent.Executor)}). Each group is processed | |
| 438 | * independently, and every group is guaranteed to be processed on a single thread. | |
| 439 | * The reduction is applied to the grouped results rather than to the raw mapped elements. | |
| 440 | * The {@code configurer} can also be used to enable batching and/or set a maximum parallelism level. | |
| 441 | * | |
| 442 | * <p><b>Note:</b> Unless the {@code configurer} explicitly limits parallelism (e.g. via | |
| 443 | * {@link CollectingConfigurer#parallelism(int)}), this collector does not limit parallelism in any | |
| 444 | * way (it may spawn work for every element). As a result, it is not suitable for processing huge | |
| 445 | * streams. | |
| 446 | * | |
| 447 | * <p><b>Note:</b> For more information on available configuration options, see | |
| 448 | * {@link CollectingConfigurer}. | |
| 449 | * | |
| 450 | * <br> | |
| 451 | * Example: | |
| 452 | * <pre>{@code | |
| 453 | * CompletableFuture<List<Group<String, String>>> result = Stream.of(t1, t2, t3) | |
| 454 | * .collect(parallelBy(Task::groupId, t -> compute(t), c -> c | |
| 455 | * .parallelism(64) | |
| 456 | * .batching(), | |
| 457 | * toList() | |
| 458 | * )); | |
| 459 | * }</pre> | |
| 460 | * | |
| 461 | * @param classifier function that assigns a grouping key to each element | |
| 462 | * @param mapper transformation applied to each element | |
| 463 | * @param configurer callback used to configure execution (see {@link CollectingConfigurer}) | |
| 464 | * @param collector the {@code Collector} describing the reduction for grouped results | |
| 465 | * @param <T> the input element type | |
| 466 | * @param <K> the classification key type | |
| 467 | * @param <R> the type produced by {@code mapper} | |
| 468 | * @param <RR> the reduction result type produced by {@code collector} | |
| 469 | * | |
| 470 | * @return a {@code Collector} producing a {@link CompletableFuture} whose value is obtained by | |
| 471 | * reducing the {@code Stream<Group<K, R>>} produced by the parallel classification | |
| 472 | * | |
| 473 | * @since 4.0.0 | |
| 474 | */ | |
| 475 | public static <T, K, R, RR> Collector<T, ?, CompletableFuture<RR>> parallelBy( | |
| 476 | Function<? super T, ? extends K> classifier, | |
| 477 | Function<? super T, ? extends R> mapper, | |
| 478 | Consumer<CollectingConfigurer> configurer, | |
| 479 | Collector<Group<K, R>, ?, RR> collector) { | |
| 480 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 481 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 482 | Objects.requireNonNull(configurer, "configurer cannot be null"); | |
| 483 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 484 | ||
| 485 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy( |
| 486 | classifier, | |
| 487 |
1
1. lambda$parallelBy$3 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallelBy$3 → KILLED |
(Function<Stream<Group<K, R>>, RR>) s -> s.collect(collector), |
| 488 | mapper, | |
| 489 | configurer); | |
| 490 | } | |
| 491 | ||
| 492 | /** | |
| 493 | * A convenience {@link Collector} that performs parallel computations (by default on Virtual Threads) | |
| 494 | * and returns a {@link Stream} of the mapped results, with additional configuration applied via the | |
| 495 | * provided {@code configurer}. | |
| 496 | * <p> | |
| 497 | * Each element is transformed using the provided {@code mapper} in parallel. Unless overridden via | |
| 498 | * {@link StreamingConfigurer#executor(java.util.concurrent.Executor)}, tasks are executed on Virtual | |
| 499 | * Threads. The {@code configurer} can also be used to enable batching and/or cap parallelism. | |
| 500 | * | |
| 501 | * <p><b>Ordering:</b> By default, this collector emits elements in an <em>arbitrary</em> order. | |
| 502 | * To preserve encounter order, configure ordered emission via {@link StreamingConfigurer#ordered()}. | |
| 503 | * | |
| 504 | * <p><b>Note:</b> Unless the {@code configurer} explicitly limits parallelism (e.g. via | |
| 505 | * {@link StreamingConfigurer#parallelism(int)}), this collector does not limit parallelism in any | |
| 506 | * way (it may spawn work for every element). As a result, it is not suitable for processing huge | |
| 507 | * streams. | |
| 508 | * | |
| 509 | * <p><b>Note:</b> For more information on available configuration options, see | |
| 510 | * {@link StreamingConfigurer}. | |
| 511 | * | |
| 512 | * <br> | |
| 513 | * Example: | |
| 514 | * <pre>{@code | |
| 515 | * Stream<String> result = Stream.of(1, 2, 3) | |
| 516 | * .collect(parallelToStream(i -> foo(i), c -> c | |
| 517 | * .ordered() | |
| 518 | * .parallelism(64) | |
| 519 | * .batching() | |
| 520 | * )); | |
| 521 | * }</pre> | |
| 522 | * | |
| 523 | * @param mapper transformation applied to each element | |
| 524 | * @param configurer callback used to configure execution (see {@link StreamingConfigurer}) | |
| 525 | * @param <T> the input element type | |
| 526 | * @param <R> the type produced by {@code mapper} | |
| 527 | * | |
| 528 | * @return a {@code Collector} producing a {@code Stream} of mapped elements | |
| 529 | * | |
| 530 | * @since 4.0.0 | |
| 531 | */ | |
| 532 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream( | |
| 533 | Function<? super T, ? extends R> mapper, | |
| 534 | Consumer<StreamingConfigurer> configurer) { | |
| 535 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 536 | Objects.requireNonNull(configurer, "configurer cannot be null"); | |
| 537 | ||
| 538 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper, configurer); |
| 539 | } | |
| 540 | ||
| 541 | /** | |
| 542 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 543 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 544 | * emitting {@link Group} entries representing each group, with additional configuration applied | |
| 545 | * via the provided {@code configurer}. | |
| 546 | * <p> | |
| 547 | * Each element is classified using {@code classifier}, then transformed using {@code mapper} in | |
| 548 | * parallel. Unless overridden via {@link StreamingConfigurer#executor(java.util.concurrent.Executor)}, | |
| 549 | * tasks are executed on Virtual Threads. The resulting grouped entries are exposed as a | |
| 550 | * {@code Stream<Group<K, R>>}. | |
| 551 | * | |
| 552 | * <p><b>Ordering:</b> By default, this collector emits {@link Group} elements in an | |
| 553 | * <em>arbitrary</em> order. To preserve encounter order, configure ordered emission via | |
| 554 | * {@link StreamingConfigurer#ordered()}. | |
| 555 | * | |
| 556 | * <p><b>Note:</b> Unless the {@code configurer} explicitly limits parallelism (e.g. via | |
| 557 | * {@link StreamingConfigurer#parallelism(int)}), this collector does not limit parallelism in any | |
| 558 | * way (it may spawn work for every element). As a result, it is not suitable for processing huge | |
| 559 | * streams. | |
| 560 | * | |
| 561 | * <p><b>Note:</b> For more information on available configuration options, see | |
| 562 | * {@link StreamingConfigurer}. | |
| 563 | * | |
| 564 | * <br> | |
| 565 | * Example: | |
| 566 | * <pre>{@code | |
| 567 | * Stream<Group<String, String>> result = Stream.of(t1, t2, t3) | |
| 568 | * .collect(parallelToStreamBy(Task::groupId, t -> compute(t), c -> c | |
| 569 | * .ordered() | |
| 570 | * .parallelism(64) | |
| 571 | * .batching() | |
| 572 | * )); | |
| 573 | * }</pre> | |
| 574 | * | |
| 575 | * @param classifier function that assigns a grouping key to each element | |
| 576 | * @param mapper transformation applied to each element | |
| 577 | * @param configurer callback used to configure execution (see {@link StreamingConfigurer}) | |
| 578 | * @param <T> the input element type | |
| 579 | * @param <K> the classification key type | |
| 580 | * @param <R> the type produced by {@code mapper} | |
| 581 | * | |
| 582 | * @return a {@code Collector} producing a {@code Stream} of grouped results | |
| 583 | * | |
| 584 | * @since 4.0.0 | |
| 585 | */ | |
| 586 | public static <T, K, R> Collector<T, ?, Stream<Group<K, R>>> parallelToStreamBy( | |
| 587 | Function<? super T, ? extends K> classifier, | |
| 588 | Function<? super T, ? extends R> mapper, | |
| 589 | Consumer<StreamingConfigurer> configurer) { | |
| 590 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 591 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 592 | Objects.requireNonNull(configurer, "configurer cannot be null"); | |
| 593 | ||
| 594 |
1
1. parallelToStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, configurer); |
| 595 | } | |
| 596 | ||
| 597 | // convenience (defaults + parallelism) | |
| 598 | ||
| 599 | /** | |
| 600 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 601 | * and returns a {@link CompletableFuture} containing a {@link Stream} of the mapped results. | |
| 602 | * <p> | |
| 603 | * This overload is a convenience for applying an easy parallelism cap. For additional configuration | |
| 604 | * options (e.g. batching or a custom {@link java.util.concurrent.Executor}), use the overload | |
| 605 | * accepting a {@link CollectingConfigurer}. | |
| 606 | * | |
| 607 | * <br> | |
| 608 | * Example: | |
| 609 | * <pre>{@code | |
| 610 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 611 | * .collect(parallel(i -> foo(i), 64)); | |
| 612 | * }</pre> | |
| 613 | * | |
| 614 | * @param mapper transformation applied to each element | |
| 615 | * @param parallelism maximum parallelism (must be positive) | |
| 616 | * @param <T> the input element type | |
| 617 | * @param <R> the type produced by {@code mapper} | |
| 618 | * | |
| 619 | * @return a {@code Collector} producing a {@code CompletableFuture} of a {@code Stream} of mapped elements | |
| 620 | * | |
| 621 | * @since 4.0.0 | |
| 622 | */ | |
| 623 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel( | |
| 624 | Function<? super T, ? extends R> mapper, int parallelism) { | |
| 625 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 626 | ||
| 627 |
1
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED |
return Factory.collecting( |
| 628 |
1
1. lambda$parallel$6 : replaced return value with Stream.empty for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$6 → KILLED |
(Function<Stream<R>, Stream<R>>) i -> i, |
| 629 | mapper, | |
| 630 | c -> c.parallelism(parallelism)); | |
| 631 | } | |
| 632 | ||
| 633 | /** | |
| 634 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 635 | * and returns a {@link CompletableFuture} containing the reduced result produced by the provided | |
| 636 | * {@code collector}. | |
| 637 | * <p> | |
| 638 | * This overload is a convenience for applying an easy parallelism cap. For additional configuration | |
| 639 | * options (e.g. batching or a custom {@link java.util.concurrent.Executor}), use the overload | |
| 640 | * accepting a {@link CollectingConfigurer}. | |
| 641 | * | |
| 642 | * <br> | |
| 643 | * Example: | |
| 644 | * <pre>{@code | |
| 645 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 646 | * .collect(parallel(i -> foo(i), 64, toList())); | |
| 647 | * }</pre> | |
| 648 | * | |
| 649 | * @param mapper transformation applied to each element | |
| 650 | * @param parallelism maximum parallelism (must be positive) | |
| 651 | * @param collector the {@code Collector} describing the reduction | |
| 652 | * @param <T> the input element type | |
| 653 | * @param <R> the type produced by {@code mapper} | |
| 654 | * @param <RR> the reduction result type produced by {@code collector} | |
| 655 | * | |
| 656 | * @return a {@code Collector} producing a {@link CompletableFuture} of the reduced result | |
| 657 | * | |
| 658 | * @since 4.0.0 | |
| 659 | */ | |
| 660 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel( | |
| 661 | Function<? super T, ? extends R> mapper, | |
| 662 | int parallelism, Collector<R, ?, RR> collector) { | |
| 663 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 664 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 665 | ||
| 666 |
1
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED |
return Factory.collecting( |
| 667 |
1
1. lambda$parallel$8 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$8 → KILLED |
(Function<Stream<R>, RR>) s -> s.collect(collector), |
| 668 | mapper, | |
| 669 | c -> c.parallelism(parallelism)); | |
| 670 | } | |
| 671 | ||
| 672 | /** | |
| 673 | * A convenience {@link Collector} that performs parallel computations by classifying input elements | |
| 674 | * using the provided {@code classifier}, applying the given {@code mapper}, and emitting | |
| 675 | * {@link Group} entries representing each group. | |
| 676 | * <p> | |
| 677 | * This overload is a convenience for applying an easy parallelism cap. For additional configuration | |
| 678 | * options (e.g. batching or a custom {@link java.util.concurrent.Executor}), use the overload | |
| 679 | * accepting a {@link CollectingConfigurer}. | |
| 680 | * | |
| 681 | * <br> | |
| 682 | * Example: | |
| 683 | * <pre>{@code | |
| 684 | * CompletableFuture<Stream<Group<String, String>>> result = Stream.of(t1, t2, t3) | |
| 685 | * .collect(parallelBy(Task::groupId, t -> compute(t), 64)); | |
| 686 | * }</pre> | |
| 687 | * | |
| 688 | * @param classifier function that assigns a grouping key to each element | |
| 689 | * @param mapper transformation applied to each element | |
| 690 | * @param parallelism maximum parallelism (must be positive) | |
| 691 | * @param <T> the input element type | |
| 692 | * @param <K> the classification key type | |
| 693 | * @param <R> the type produced by {@code mapper} | |
| 694 | * | |
| 695 | * @return a {@code Collector} producing a {@link CompletableFuture} of a {@code Stream} of grouped results | |
| 696 | * | |
| 697 | * @since 4.0.0 | |
| 698 | */ | |
| 699 | public static <T, K, R> Collector<T, ?, CompletableFuture<Stream<Group<K, R>>>> parallelBy( | |
| 700 | Function<? super T, ? extends K> classifier, | |
| 701 | Function<? super T, ? extends R> mapper, int parallelism) { | |
| 702 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 703 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 704 | ||
| 705 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, mapper, c -> c.parallelism(parallelism)); |
| 706 | } | |
| 707 | ||
| 708 | /** | |
| 709 | * A convenience {@link Collector} that performs parallel computations by classifying input elements | |
| 710 | * using the provided {@code classifier}, applying the given {@code mapper}, emitting {@link Group} | |
| 711 | * entries representing each group, and then reducing them using the user-provided {@code collector}. | |
| 712 | * <p> | |
| 713 | * This overload is a convenience for applying an easy parallelism cap. For additional configuration | |
| 714 | * options (e.g. batching or a custom {@link java.util.concurrent.Executor}), use the overload | |
| 715 | * accepting a {@link CollectingConfigurer}. | |
| 716 | * | |
| 717 | * <br> | |
| 718 | * Example: | |
| 719 | * <pre>{@code | |
| 720 | * CompletableFuture<List<Group<String, String>>> result = Stream.of(t1, t2, t3) | |
| 721 | * .collect(parallelBy(Task::groupId, t -> compute(t), 64, toList())); | |
| 722 | * }</pre> | |
| 723 | * | |
| 724 | * @param classifier function that assigns a grouping key to each element | |
| 725 | * @param mapper transformation applied to each element | |
| 726 | * @param parallelism maximum parallelism (must be positive) | |
| 727 | * @param collector the {@code Collector} describing the reduction for grouped results | |
| 728 | * @param <T> the input element type | |
| 729 | * @param <K> the classification key type | |
| 730 | * @param <R> the type produced by {@code mapper} | |
| 731 | * @param <RR> the reduction result type produced by {@code collector} | |
| 732 | * | |
| 733 | * @return a {@code Collector} producing a {@link CompletableFuture} of the reduced result | |
| 734 | * | |
| 735 | * @since 4.0.0 | |
| 736 | */ | |
| 737 | public static <T, K, R, RR> Collector<T, ?, CompletableFuture<RR>> parallelBy( | |
| 738 | Function<? super T, ? extends K> classifier, | |
| 739 | Function<? super T, ? extends R> mapper, int parallelism, | |
| 740 | Collector<Group<K, R>, ?, RR> collector) { | |
| 741 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 742 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 743 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 744 | ||
| 745 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy( |
| 746 | classifier, | |
| 747 |
1
1. lambda$parallelBy$5 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallelBy$5 → KILLED |
(Function<Stream<Group<K, R>>, RR>) s -> s.collect(collector), |
| 748 | mapper, | |
| 749 | c -> c.parallelism(parallelism)); | |
| 750 | } | |
| 751 | ||
| 752 | /** | |
| 753 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 754 | * and returns a {@link Stream} of the mapped results. | |
| 755 | * <p> | |
| 756 | * This overload is a convenience for applying an easy parallelism cap. This method does not expose | |
| 757 | * additional configuration (such as ordered emission, batching, or a custom executor). For more | |
| 758 | * options, use the overload accepting a {@link StreamingConfigurer}. | |
| 759 | * | |
| 760 | * <p><b>Ordering:</b> This collector emits elements in an <em>arbitrary</em> order. To preserve encounter | |
| 761 | * order, use the {@link StreamingConfigurer} overload and configure {@link StreamingConfigurer#ordered()}. | |
| 762 | * | |
| 763 | * <br> | |
| 764 | * Example: | |
| 765 | * <pre>{@code | |
| 766 | * Stream<String> result = Stream.of(1, 2, 3) | |
| 767 | * .collect(parallelToStream(i -> foo(i), 64)); | |
| 768 | * }</pre> | |
| 769 | * | |
| 770 | * @param mapper transformation applied to each element | |
| 771 | * @param parallelism maximum parallelism (must be positive) | |
| 772 | * @param <T> the input element type | |
| 773 | * @param <R> the type produced by {@code mapper} | |
| 774 | * | |
| 775 | * @return a {@code Collector} producing a {@code Stream} of mapped elements | |
| 776 | * | |
| 777 | * @since 4.0.0 | |
| 778 | */ | |
| 779 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream( | |
| 780 | Function<? super T, ? extends R> mapper, int parallelism) { | |
| 781 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 782 | ||
| 783 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper, c -> c.parallelism(parallelism)); |
| 784 | } | |
| 785 | ||
| 786 | /** | |
| 787 | * A convenience {@link Collector} that performs parallel computations by classifying input elements | |
| 788 | * using the provided {@code classifier}, applying the given {@code mapper}, and emitting | |
| 789 | * {@link Group} entries representing each group. | |
| 790 | * <p> | |
| 791 | * This overload is a convenience for applying an easy parallelism cap. This method does not expose | |
| 792 | * additional configuration (such as ordered emission, batching, or a custom executor). For more | |
| 793 | * options, use the overload accepting a {@link StreamingConfigurer}. | |
| 794 | * | |
| 795 | * <p><b>Ordering:</b> This collector emits {@link Group} elements in an <em>arbitrary</em> order. | |
| 796 | * To preserve encounter order, use the {@link StreamingConfigurer} overload and configure | |
| 797 | * {@link StreamingConfigurer#ordered()}. | |
| 798 | * | |
| 799 | * <br> | |
| 800 | * Example: | |
| 801 | * <pre>{@code | |
| 802 | * Stream<Group<String, String>> result = Stream.of(t1, t2, t3) | |
| 803 | * .collect(parallelToStreamBy(Task::groupId, t -> compute(t), 64)); | |
| 804 | * }</pre> | |
| 805 | * | |
| 806 | * @param classifier function that assigns a grouping key to each element | |
| 807 | * @param mapper transformation applied to each element | |
| 808 | * @param parallelism maximum parallelism (must be positive) | |
| 809 | * @param <T> the input element type | |
| 810 | * @param <K> the classification key type | |
| 811 | * @param <R> the type produced by {@code mapper} | |
| 812 | * | |
| 813 | * @return a {@code Collector} producing a {@code Stream} of grouped results | |
| 814 | * | |
| 815 | * @since 4.0.0 | |
| 816 | */ | |
| 817 | public static <T, K, R> Collector<T, ?, Stream<Group<K, R>>> parallelToStreamBy( | |
| 818 | Function<? super T, ? extends K> classifier, | |
| 819 | Function<? super T, ? extends R> mapper, int parallelism) { | |
| 820 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 821 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 822 | ||
| 823 |
1
1. parallelToStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, c -> c.parallelism(parallelism)); |
| 824 | } | |
| 825 | ||
| 826 | /** | |
| 827 | * A convenience {@code Collector} for collecting a {@code Stream<CompletableFuture<T>>} | |
| 828 | * into a {@code CompletableFuture<R>} using a provided {@code Collector<T, ?, R>} | |
| 829 | * | |
| 830 | * @param collector the {@code Collector} describing the reduction | |
| 831 | * @param <T> the type of the collected elements | |
| 832 | * @param <R> the result type of the downstream {@code Collector} | |
| 833 | * | |
| 834 | * @return a {@code Collector} which collects all futures and combines them into a single future | |
| 835 | * using the provided downstream {@code Collector} | |
| 836 | * | |
| 837 | * @since 2.3.0 | |
| 838 | */ | |
| 839 | public static <T, R> Collector<CompletableFuture<T>, ?, CompletableFuture<R>> toFuture(Collector<T, ?, R> collector) { | |
| 840 |
1
1. toFuture : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED |
return FutureCollectors.toFuture(collector); |
| 841 | } | |
| 842 | ||
| 843 | /** | |
| 844 | * A convenience {@code Collector} for collecting a {@code Stream<CompletableFuture<T>>} into a {@code CompletableFuture<List<T>>} | |
| 845 | * | |
| 846 | * @param <T> the type of the collected elements | |
| 847 | * | |
| 848 | * @return a {@code Collector} which collects all futures and combines them into a single future | |
| 849 | * returning a list of results | |
| 850 | * | |
| 851 | * @since 2.3.0 | |
| 852 | */ | |
| 853 | public static <T> Collector<CompletableFuture<T>, ?, CompletableFuture<List<T>>> toFuture() { | |
| 854 |
1
1. toFuture : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED |
return FutureCollectors.toFuture(); |
| 855 | } | |
| 856 | } | |
Mutations | ||
| 74 |
1.1 2.2 |
|
| 109 |
1.1 2.2 |
|
| 147 |
1.1 |
|
| 191 |
1.1 |
|
| 193 |
1.1 |
|
| 230 |
1.1 |
|
| 272 |
1.1 |
|
| 320 |
1.1 2.2 |
|
| 373 |
1.1 2.2 |
|
| 425 |
1.1 |
|
| 485 |
1.1 |
|
| 487 |
1.1 |
|
| 538 |
1.1 |
|
| 594 |
1.1 |
|
| 627 |
1.1 |
|
| 628 |
1.1 |
|
| 666 |
1.1 |
|
| 667 |
1.1 |
|
| 705 |
1.1 |
|
| 745 |
1.1 |
|
| 747 |
1.1 |
|
| 783 |
1.1 |
|
| 823 |
1.1 |
|
| 840 |
1.1 |
|
| 854 |
1.1 |