| 1 | package com.pivovarit.collectors; | |
| 2 | ||
| 3 | import java.util.List; | |
| 4 | import java.util.Objects; | |
| 5 | import java.util.concurrent.CompletableFuture; | |
| 6 | import java.util.concurrent.Executor; | |
| 7 | import java.util.function.Function; | |
| 8 | import java.util.stream.Collector; | |
| 9 | import java.util.stream.Stream; | |
| 10 | import org.jspecify.annotations.NullMarked; | |
| 11 | ||
| 12 | /** | |
| 13 | * An umbrella class exposing static factory methods for instantiating parallel {@link Collector}s | |
| 14 | * | |
| 15 | * @author Grzegorz Piwowarek | |
| 16 | */ | |
| 17 | @NullMarked | |
| 18 | public final class ParallelCollectors { | |
| 19 | ||
| 20 | private ParallelCollectors() { | |
| 21 | } | |
| 22 | ||
| 23 | /** | |
| 24 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 25 | * and returns a {@link CompletableFuture} containing the result of applying the user-provided | |
| 26 | * {@link Collector} to the mapped elements. | |
| 27 | * <p> | |
| 28 | * Each element is transformed using the provided {@code mapper} in parallel on Virtual Threads, | |
| 29 | * and the results are reduced according to the supplied {@code collector}. | |
| 30 | * | |
| 31 | * <br> | |
| 32 | * Example: | |
| 33 | * <pre>{@code | |
| 34 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 35 | * .collect(parallel(i -> foo(i), toList())); | |
| 36 | * }</pre> | |
| 37 | * | |
| 38 | * @param mapper transformation applied to each element | |
| 39 | * @param collector the {@code Collector} describing the reduction | |
| 40 | * @param <T> the input element type | |
| 41 | * @param <R> the type produced by {@code mapper} | |
| 42 | * @param <RR> the reduction result type produced by {@code collector} | |
| 43 | * | |
| 44 | * @return a {@code Collector} producing a {@link CompletableFuture} of the reduced result | |
| 45 | * | |
| 46 | * @since 3.0.0 | |
| 47 | */ | |
| 48 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel( | |
| 49 | Function<? super T, ? extends R> mapper, | |
| 50 | Collector<R, ?, RR> collector) { | |
| 51 | ||
| 52 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 53 |
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); |
| 54 | } | |
| 55 | ||
| 56 | /** | |
| 57 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 58 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 59 | * emitting {@link Grouped} entries representing each batch. | |
| 60 | * <p> | |
| 61 | * The generated {@link Stream} of {@code Grouped<K, R>} instances is then reduced using the | |
| 62 | * user-provided {@code collector}, executed on Virtual Threads. Each group is processed | |
| 63 | * independently, and every batch is guaranteed to be processed on a single thread. | |
| 64 | * The reduction is applied to the grouped results rather than to the raw mapped elements. | |
| 65 | * <br> | |
| 66 | * <br> | |
| 67 | * Example: | |
| 68 | * <pre>{@code | |
| 69 | * CompletableFuture<List<Grouped<String, String>>> result = Stream.of(t1, t2, t3) | |
| 70 | * .collect(parallelBy(Task::groupId, t -> compute(t), toList())); | |
| 71 | * }</pre> | |
| 72 | * | |
| 73 | * @param classifier function that groups elements into batches | |
| 74 | * @param mapper transformation applied to each element | |
| 75 | * @param collector the {@code Collector} describing the reduction for each batch | |
| 76 | * @param <T> the input element type | |
| 77 | * @param <K> the classification key type | |
| 78 | * @param <R> the type produced by {@code mapper} | |
| 79 | * @param <RR> the reduction result type produced by {@code collector} | |
| 80 | * | |
| 81 | * @return a {@code Collector} producing a {@link CompletableFuture} whose value is obtained | |
| 82 | * by reducing the {@code Stream<Grouped<K, R>>} produced by the parallel classification | |
| 83 | * | |
| 84 | * @since 3.4.0 | |
| 85 | */ | |
| 86 | public static <T, K, R, RR> Collector<T, ?, CompletableFuture<RR>> parallelBy( | |
| 87 | Function<? super T, ? extends K> classifier, | |
| 88 | Function<? super T, ? extends R> mapper, | |
| 89 | Collector<Grouped<K, R>, ?, RR> collector) { | |
| 90 | ||
| 91 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 92 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 93 | ||
| 94 |
2
1. lambda$parallelBy$0 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallelBy$0 → KILLED 2. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, (Function<Stream<Grouped<K, R>>, RR>) s -> s.collect(collector), mapper); |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 99 | * and returns a {@link CompletableFuture} containing the result of applying the user-provided | |
| 100 | * {@link Collector} to the mapped elements, with a configurable parallelism level. | |
| 101 | * <p> | |
| 102 | * Each element is transformed using the provided {@code mapper} in parallel on Virtual Threads, | |
| 103 | * and the results are reduced according to the supplied {@code collector}. | |
| 104 | * | |
| 105 | * <br> | |
| 106 | * Example: | |
| 107 | * <pre>{@code | |
| 108 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 109 | * .collect(parallel(i -> foo(i), toList(), 2)); | |
| 110 | * }</pre> | |
| 111 | * | |
| 112 | * @param mapper transformation applied to each element | |
| 113 | * @param collector the {@code Collector} describing the reduction | |
| 114 | * @param parallelism the maximum degree of parallelism | |
| 115 | * @param <T> the input element type | |
| 116 | * @param <R> the type produced by {@code mapper} | |
| 117 | * @param <RR> the reduction result type produced by {@code collector} | |
| 118 | * | |
| 119 | * @return a {@code Collector} producing a {@link CompletableFuture} of the reduced result | |
| 120 | * | |
| 121 | * @since 3.2.0 | |
| 122 | */ | |
| 123 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel( | |
| 124 | Function<? super T, ? extends R> mapper, | |
| 125 | Collector<R, ?, RR> collector, | |
| 126 | int parallelism) { | |
| 127 | ||
| 128 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 129 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$1 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$1 → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, Options.parallelism(parallelism)); |
| 130 | } | |
| 131 | ||
| 132 | /** | |
| 133 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 134 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 135 | * emitting {@link Grouped} entries representing each batch. | |
| 136 | * <p> | |
| 137 | * The generated {@link Stream} of {@code Grouped<K, R>} instances is then reduced using the | |
| 138 | * user-provided {@code collector}, executed on Virtual Threads. Each group is processed | |
| 139 | * independently, and every batch is guaranteed to be processed on a single thread. | |
| 140 | * The reduction is applied to the grouped results rather than to the raw mapped elements. | |
| 141 | * A configurable {@code parallelism} parameter defines the maximum | |
| 142 | * level of concurrent processing. | |
| 143 | * <br> | |
| 144 | * <br> | |
| 145 | * Example: | |
| 146 | * <pre>{@code | |
| 147 | * CompletableFuture<List<Grouped<String, String>>> result = Stream.of(t1, t2, t3) | |
| 148 | * .collect(parallelBy(Task::groupId, t -> compute(t), toList(), 4)); | |
| 149 | * }</pre> | |
| 150 | * | |
| 151 | * @param classifier function that groups elements into batches | |
| 152 | * @param mapper transformation applied to each element | |
| 153 | * @param collector reduction applied to the resulting {@code Stream<Grouped<K, R>>} | |
| 154 | * @param parallelism maximum allowed parallelism | |
| 155 | * @param <T> the input element type | |
| 156 | * @param <K> the classification key type | |
| 157 | * @param <R> the type produced by {@code mapper} | |
| 158 | * @param <RR> the reduction result type produced by {@code collector} | |
| 159 | * | |
| 160 | * @return a {@code Collector} producing a {@link CompletableFuture} whose value is obtained | |
| 161 | * by reducing the {@code Stream<Grouped<K, R>>} produced by the parallel classification | |
| 162 | * | |
| 163 | * @since 3.4.0 | |
| 164 | */ | |
| 165 | public static <T, K, R, RR> Collector<T, ?, CompletableFuture<RR>> parallelBy( | |
| 166 | Function<? super T, ? extends K> classifier, | |
| 167 | Function<? super T, ? extends R> mapper, | |
| 168 | Collector<Grouped<K, R>, ?, RR> collector, | |
| 169 | int parallelism) { | |
| 170 | ||
| 171 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 172 | ||
| 173 |
2
1. lambda$parallelBy$1 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallelBy$1 → KILLED 2. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, (Function<Stream<Grouped<K, R>>, RR>) s -> s.collect(collector), mapper, Options.parallelism(parallelism)); |
| 174 | } | |
| 175 | ||
| 176 | /** | |
| 177 | * A convenience {@link Collector} that performs parallel computations on a custom {@link Executor} | |
| 178 | * and returns a {@link CompletableFuture} containing the result of applying the user-provided | |
| 179 | * {@link Collector} to the mapped elements, with a configurable parallelism level. | |
| 180 | * <p> | |
| 181 | * Each element is transformed using the provided {@code mapper} in parallel on the specified | |
| 182 | * {@code executor}, and the results are reduced according to the supplied {@code collector}. | |
| 183 | * | |
| 184 | * <br> | |
| 185 | * Example: | |
| 186 | * <pre>{@code | |
| 187 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 188 | * .collect(parallel(i -> foo(i), toList(), executor, 2)); | |
| 189 | * }</pre> | |
| 190 | * | |
| 191 | * @param mapper transformation applied to each element | |
| 192 | * @param collector the {@code Collector} describing the reduction | |
| 193 | * @param executor the {@code Executor} used for asynchronous execution | |
| 194 | * @param parallelism the maximum degree of parallelism | |
| 195 | * @param <T> the input element type | |
| 196 | * @param <R> the type produced by {@code mapper} | |
| 197 | * @param <RR> the reduction result type produced by {@code collector} | |
| 198 | * | |
| 199 | * @return a {@code Collector} producing a {@link CompletableFuture} of the reduced result | |
| 200 | * | |
| 201 | * @since 2.0.0 | |
| 202 | */ | |
| 203 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel( | |
| 204 | Function<? super T, ? extends R> mapper, | |
| 205 | Collector<R, ?, RR> collector, | |
| 206 | Executor executor, | |
| 207 | int parallelism) { | |
| 208 | ||
| 209 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 210 |
2
1. lambda$parallel$2 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$2 → KILLED 2. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, Options.executor(executor), Options.parallelism(parallelism)); |
| 211 | } | |
| 212 | ||
| 213 | /** | |
| 214 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 215 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 216 | * emitting {@link Grouped} entries representing each batch. | |
| 217 | * <p> | |
| 218 | * The generated {@link Stream} of {@code Grouped<K, R>} instances is then reduced using the | |
| 219 | * user-provided {@code collector}, executed on the supplied {@link Executor}. Each group is | |
| 220 | * processed independently, and every batch is guaranteed to be processed on a single thread. | |
| 221 | * The reduction is applied to grouped results rather than to the raw mapped elements. A | |
| 222 | * configurable {@code parallelism} parameter defines the maximum level of concurrent batch | |
| 223 | * execution. | |
| 224 | * <br> | |
| 225 | * <br> | |
| 226 | * Example: | |
| 227 | * <pre>{@code | |
| 228 | * CompletableFuture<List<Grouped<String, String>>> result = Stream.of(t1, t2, t3) | |
| 229 | * .collect(parallelBy(Task::groupId, t -> compute(t), toList(), executor, 4)); | |
| 230 | * }</pre> | |
| 231 | * | |
| 232 | * @param classifier function that groups elements into batches | |
| 233 | * @param mapper transformation applied to each element | |
| 234 | * @param collector reduction applied to the resulting {@code Stream<Grouped<K, R>>} | |
| 235 | * @param executor the {@code Executor} used for asynchronous execution | |
| 236 | * @param parallelism maximum allowed parallelism | |
| 237 | * @param <T> the input element type | |
| 238 | * @param <K> the classification key type | |
| 239 | * @param <R> the type produced by {@code mapper} | |
| 240 | * @param <RR> the reduction result type produced by {@code collector} | |
| 241 | * | |
| 242 | * @return a {@code Collector} producing a {@link CompletableFuture} whose value is obtained | |
| 243 | * by reducing the {@code Stream<Grouped<K, R>>} produced by the parallel classification | |
| 244 | * | |
| 245 | * @since 3.4.0 | |
| 246 | */ | |
| 247 | public static <T, K, R, RR> Collector<T, ?, CompletableFuture<RR>> parallelBy( | |
| 248 | Function<? super T, ? extends K> classifier, | |
| 249 | Function<? super T, ? extends R> mapper, | |
| 250 | Collector<Grouped<K, R>, ?, RR> collector, | |
| 251 | Executor executor, | |
| 252 | int parallelism) { | |
| 253 | ||
| 254 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 255 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 256 |
2
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED 2. lambda$parallelBy$2 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallelBy$2 → KILLED |
return Factory.collectingBy(classifier, (Function<Stream<Grouped<K, R>>, RR>) s -> s.collect(collector), mapper, Options.executor(executor), Options.parallelism(parallelism)); |
| 257 | } | |
| 258 | ||
| 259 | /** | |
| 260 | * A convenience {@link Collector} that performs parallel computations on a custom {@link Executor} | |
| 261 | * with effectively unlimited parallelism and returns a {@link CompletableFuture} containing the | |
| 262 | * result of applying the user-provided {@link Collector} to the mapped elements. | |
| 263 | * <p> | |
| 264 | * Each element is transformed using the provided {@code mapper} in parallel on the specified | |
| 265 | * {@code executor}, and the results are reduced according to the supplied {@code collector}. | |
| 266 | * | |
| 267 | * <br> | |
| 268 | * Example: | |
| 269 | * <pre>{@code | |
| 270 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 271 | * .collect(parallel(i -> foo(i), toList(), executor)); | |
| 272 | * }</pre> | |
| 273 | * | |
| 274 | * @param mapper transformation applied to each element | |
| 275 | * @param collector the {@code Collector} describing the reduction | |
| 276 | * @param executor the {@code Executor} used for asynchronous execution | |
| 277 | * @param <T> the input element type | |
| 278 | * @param <R> the type produced by {@code mapper} | |
| 279 | * @param <RR> the reduction result type produced by {@code collector} | |
| 280 | * | |
| 281 | * @return a {@code Collector} producing a {@link CompletableFuture} of the reduced result | |
| 282 | * | |
| 283 | * @since 3.3.0 | |
| 284 | */ | |
| 285 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel( | |
| 286 | Function<? super T, ? extends R> mapper, | |
| 287 | Collector<R, ?, RR> collector, | |
| 288 | Executor executor) { | |
| 289 | ||
| 290 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 291 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$3 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$3 → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, Options.executor(executor)); |
| 292 | } | |
| 293 | ||
| 294 | /** | |
| 295 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 296 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 297 | * emitting {@link Grouped} entries representing each batch. | |
| 298 | * <p> | |
| 299 | * The generated {@link Stream} of {@code Grouped<K, R>} instances is then reduced using the | |
| 300 | * user-provided {@code collector}, executed on the supplied {@link Executor}. Each group is | |
| 301 | * processed independently, and every batch is guaranteed to be processed on a single thread. | |
| 302 | * The reduction is applied to grouped results rather than to the raw mapped elements. | |
| 303 | * <br> | |
| 304 | * <br> | |
| 305 | * Example: | |
| 306 | * <pre>{@code | |
| 307 | * CompletableFuture<List<Grouped<String, String>>> result = Stream.of(task1, task2, task3) | |
| 308 | * .collect(parallelBy( | |
| 309 | * Task::groupId, | |
| 310 | * t -> compute(t), | |
| 311 | * toList(), | |
| 312 | * executor)); | |
| 313 | * }</pre> | |
| 314 | * | |
| 315 | * @param classifier function that groups elements into batches | |
| 316 | * @param mapper transformation applied to each element | |
| 317 | * @param collector reduction applied to the resulting {@code Stream<Grouped<K, R>>} | |
| 318 | * @param executor the {@code Executor} used for asynchronous execution | |
| 319 | * @param <T> the input element type | |
| 320 | * @param <K> the classification key type | |
| 321 | * @param <R> the type produced by {@code mapper} | |
| 322 | * @param <RR> the reduction result type produced by {@code collector} | |
| 323 | * | |
| 324 | * @return a {@code Collector} producing a {@link CompletableFuture} whose value is obtained | |
| 325 | * by reducing the {@code Stream<Grouped<K, R>>} produced by the parallel classification | |
| 326 | * | |
| 327 | * @since 3.4.0 | |
| 328 | */ | |
| 329 | public static <T, K, R, RR> Collector<T, ?, CompletableFuture<RR>> parallelBy( | |
| 330 | Function<? super T, ? extends K> classifier, | |
| 331 | Function<? super T, ? extends R> mapper, | |
| 332 | Collector<Grouped<K, R>, ?, RR> collector, | |
| 333 | Executor executor) { | |
| 334 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 335 |
2
1. lambda$parallelBy$3 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallelBy$3 → KILLED 2. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, (Function<Stream<Grouped<K, R>>, RR>) s -> s.collect(collector), mapper, Options.executor(executor)); |
| 336 | } | |
| 337 | ||
| 338 | /** | |
| 339 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 340 | * and returns a {@link CompletableFuture} containing a {@link Stream} of the mapped elements. | |
| 341 | * <p> | |
| 342 | * The collector maintains the encounter order of the processed elements. Instances of this | |
| 343 | * collector should not be reused. | |
| 344 | * | |
| 345 | * <br> | |
| 346 | * Example: | |
| 347 | * <pre>{@code | |
| 348 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 349 | * .collect(parallel(i -> foo())); | |
| 350 | * }</pre> | |
| 351 | * | |
| 352 | * @param mapper a transformation applied to each element | |
| 353 | * @param <T> the input element type | |
| 354 | * @param <R> the type produced by {@code mapper} | |
| 355 | * | |
| 356 | * @return a {@code Collector} producing a {@link CompletableFuture} of a {@link Stream} of mapped elements | |
| 357 | * | |
| 358 | * @since 3.0.0 | |
| 359 | */ | |
| 360 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel( | |
| 361 | Function<? super T, ? extends R> mapper) { | |
| 362 | ||
| 363 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$4 : replaced return value with Stream.empty for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$4 → KILLED |
return Factory.collecting((Function<Stream<R>, Stream<R>>) i -> i, mapper); |
| 364 | } | |
| 365 | ||
| 366 | /** | |
| 367 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 368 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 369 | * emitting {@link Grouped} entries representing each batch. | |
| 370 | * <p> | |
| 371 | * The resulting {@link CompletableFuture} completes with a {@link Stream} of | |
| 372 | * {@code Grouped<K, R>} instances. Each group is processed independently on Virtual Threads, | |
| 373 | * and every batch is guaranteed to be processed on a single thread. The encounter order of | |
| 374 | * elements within each batch is preserved. | |
| 375 | * <br> | |
| 376 | * <br> | |
| 377 | * Example: | |
| 378 | * <pre>{@code | |
| 379 | * CompletableFuture<Stream<Grouped<String, String>>> result = Stream.of(t1, t2, t3) | |
| 380 | * .collect(parallelBy(Task::groupId, t -> compute(t))); | |
| 381 | * }</pre> | |
| 382 | * | |
| 383 | * @param classifier function that groups elements into batches | |
| 384 | * @param mapper transformation applied to each element | |
| 385 | * @param <T> the input element type | |
| 386 | * @param <K> the classification key type | |
| 387 | * @param <R> the type produced by {@code mapper} | |
| 388 | * | |
| 389 | * @return a {@code Collector} producing a {@link CompletableFuture} whose value is a | |
| 390 | * {@link Stream} of {@code Grouped<K, R>} produced by the parallel classification | |
| 391 | * | |
| 392 | * @since 3.4.0 | |
| 393 | */ | |
| 394 | public static <T, K, R> Collector<T, ?, CompletableFuture<Stream<Grouped<K, R>>>> parallelBy( | |
| 395 | Function<? super T, ? extends K> classifier, | |
| 396 | Function<? super T, ? extends R> mapper) { | |
| 397 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, mapper); |
| 398 | } | |
| 399 | ||
| 400 | /** | |
| 401 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 402 | * and returns a {@link CompletableFuture} containing a {@link Stream} of the mapped elements. | |
| 403 | * <p> | |
| 404 | * The collector maintains the encounter order of the processed elements. Instances of this | |
| 405 | * collector should not be reused. | |
| 406 | * | |
| 407 | * <br> | |
| 408 | * Example: | |
| 409 | * <pre>{@code | |
| 410 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 411 | * .collect(parallel(i -> foo(), 4)); | |
| 412 | * }</pre> | |
| 413 | * | |
| 414 | * @param mapper a transformation applied to each element | |
| 415 | * @param parallelism the maximum degree of parallelism | |
| 416 | * @param <T> the input element type | |
| 417 | * @param <R> the type produced by {@code mapper} | |
| 418 | * | |
| 419 | * @return a {@code Collector} producing a {@link CompletableFuture} of a {@link Stream} of mapped elements | |
| 420 | * | |
| 421 | * @since 3.2.0 | |
| 422 | */ | |
| 423 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel( | |
| 424 | Function<? super T, ? extends R> mapper, | |
| 425 | int parallelism) { | |
| 426 |
2
1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED 2. lambda$parallel$5 : replaced return value with Stream.empty for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$5 → KILLED |
return Factory.collecting((Function<Stream<R>, Stream<R>>) i -> i, mapper, Options.parallelism(parallelism)); |
| 427 | } | |
| 428 | ||
| 429 | /** | |
| 430 | * A convenience {@link Collector} that performs parallel computations by classifying input | |
| 431 | * elements using the provided {@code classifier}, applying the given {@code mapper}, and | |
| 432 | * emitting {@link Grouped} entries representing each batch. | |
| 433 | * <p> | |
| 434 | * The resulting {@link CompletableFuture} completes with a {@link Stream} of | |
| 435 | * {@code Grouped<K, R>} instances. Each group is processed independently on Virtual Threads, | |
| 436 | * and every batch is guaranteed to be processed on a single thread. The encounter order of | |
| 437 | * elements within each batch is preserved. | |
| 438 | * <br> | |
| 439 | * <br> | |
| 440 | * Example: | |
| 441 | * <pre>{@code | |
| 442 | * CompletableFuture<Stream<Grouped<String, String>>> result = Stream.of(t1, t2, t3) | |
| 443 | * .collect(parallelBy(Task::groupId, t -> compute(t), 4)); | |
| 444 | * }</pre> | |
| 445 | * | |
| 446 | * @param classifier function that groups elements into batches | |
| 447 | * @param mapper transformation applied to each element | |
| 448 | * @param parallelism the maximum degree of parallelism | |
| 449 | * @param <T> the input element type | |
| 450 | * @param <K> the classification key type | |
| 451 | * @param <R> the type produced by {@code mapper} | |
| 452 | * | |
| 453 | * @return a {@code Collector} producing a {@link CompletableFuture} whose value is a | |
| 454 | * {@link Stream} of {@code Grouped<K, R>} produced by the parallel classification | |
| 455 | * | |
| 456 | * @since 3.4.0 | |
| 457 | */ | |
| 458 | public static <T, K, R> Collector<T, ?, CompletableFuture<Stream<Grouped<K, R>>>> parallelBy( | |
| 459 | Function<? super T, ? extends K> classifier, | |
| 460 | Function<? super T, ? extends R> mapper, | |
| 461 | int parallelism) { | |
| 462 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, mapper, Options.parallelism(parallelism)); |
| 463 | } | |
| 464 | ||
| 465 | /** | |
| 466 | * A convenience {@link Collector} that performs parallel computations on a custom {@link Executor} | |
| 467 | * and returns a {@link CompletableFuture} containing a {@link Stream} of the mapped elements. | |
| 468 | * <p> | |
| 469 | * The collector maintains the encounter order of the processed elements. Instances of this | |
| 470 | * collector should not be reused. | |
| 471 | * | |
| 472 | * <br> | |
| 473 | * Example: | |
| 474 | * <pre>{@code | |
| 475 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 476 | * .collect(parallel(i -> foo(), executor, 2)); | |
| 477 | * }</pre> | |
| 478 | * | |
| 479 | * @param mapper a transformation applied to each element | |
| 480 | * @param executor the {@code Executor} used for asynchronous execution | |
| 481 | * @param parallelism the maximum degree of parallelism | |
| 482 | * @param <T> the input element type | |
| 483 | * @param <R> the type produced by {@code mapper} | |
| 484 | * | |
| 485 | * @return a {@code Collector} producing a {@link CompletableFuture} of a {@link Stream} of mapped elements | |
| 486 | * | |
| 487 | * @since 2.0.0 | |
| 488 | */ | |
| 489 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel( | |
| 490 | Function<? super T, ? extends R> mapper, | |
| 491 | Executor executor, | |
| 492 | int parallelism) { | |
| 493 | ||
| 494 |
2
1. lambda$parallel$6 : replaced return value with Stream.empty for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$6 → 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, Options.executor(executor), Options.parallelism(parallelism)); |
| 495 | } | |
| 496 | ||
| 497 | /** | |
| 498 | * A convenience {@link Collector} that performs parallel computations by classifying elements | |
| 499 | * into groups using the provided {@code classifier}, executing each group asynchronously on the | |
| 500 | * supplied {@link Executor}, and returning a {@link CompletableFuture} that yields a | |
| 501 | * {@link Stream} of {@link Grouped} results. | |
| 502 | * <p> | |
| 503 | * Elements within each group preserve encounter order. Instances of this collector are not | |
| 504 | * intended to be reused. | |
| 505 | * | |
| 506 | * <br> | |
| 507 | * Example: | |
| 508 | * <pre>{@code | |
| 509 | * CompletableFuture<Stream<Grouped<String, String>>> result = Stream.of(t1, t2, t3) | |
| 510 | * .collect(parallelBy(Task::groupId, t -> compute(t), executor, 4)); | |
| 511 | * }</pre> | |
| 512 | * | |
| 513 | * @param classifier function that assigns each input element to a group | |
| 514 | * @param mapper transformation applied to each element | |
| 515 | * @param executor the {@code Executor} used for asynchronous execution | |
| 516 | * @param parallelism the maximum degree of parallelism | |
| 517 | * @param <T> the input element type | |
| 518 | * @param <K> the classification key type | |
| 519 | * @param <R> the mapped element type | |
| 520 | * | |
| 521 | * @return a {@code Collector} producing a {@link CompletableFuture} of a | |
| 522 | * {@link Stream} of {@link Grouped} results | |
| 523 | * | |
| 524 | * @since 3.4.0 | |
| 525 | */ | |
| 526 | public static <T, K, R> Collector<T, ?, CompletableFuture<Stream<Grouped<K, R>>>> parallelBy( | |
| 527 | Function<? super T, ? extends K> classifier, | |
| 528 | Function<? super T, ? extends R> mapper, | |
| 529 | Executor executor, | |
| 530 | int parallelism) { | |
| 531 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, mapper, Options.executor(executor), Options.parallelism(parallelism)); |
| 532 | } | |
| 533 | ||
| 534 | /** | |
| 535 | * A convenience {@link Collector} that performs parallel computations on a custom {@link Executor} | |
| 536 | * with effectively unlimited parallelism and returns a {@link CompletableFuture} containing a | |
| 537 | * {@link Stream} of the mapped elements. | |
| 538 | * <p> | |
| 539 | * The collector maintains the encounter order of the processed elements. Instances of this | |
| 540 | * collector should not be reused. | |
| 541 | * | |
| 542 | * <br> | |
| 543 | * Example: | |
| 544 | * <pre>{@code | |
| 545 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 546 | * .collect(parallel(i -> foo(), executor)); | |
| 547 | * }</pre> | |
| 548 | * | |
| 549 | * @param mapper a transformation applied to each element | |
| 550 | * @param executor the {@code Executor} used for asynchronous execution | |
| 551 | * @param <T> the input element type | |
| 552 | * @param <R> the type produced by {@code mapper} | |
| 553 | * | |
| 554 | * @return a {@code Collector} producing a {@link CompletableFuture} of a {@link Stream} of mapped elements | |
| 555 | * | |
| 556 | * @since 3.3.0 | |
| 557 | */ | |
| 558 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel( | |
| 559 | Function<? super T, ? extends R> mapper, | |
| 560 | Executor executor) { | |
| 561 | ||
| 562 |
2
1. lambda$parallel$7 : replaced return value with Stream.empty for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$7 → 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, Options.executor(executor)); |
| 563 | } | |
| 564 | ||
| 565 | /** | |
| 566 | * A convenience {@link Collector} that performs parallel computations by classifying elements | |
| 567 | * using the provided {@code classifier}, executing each group asynchronously on the supplied | |
| 568 | * {@link Executor}, and returning a {@link CompletableFuture} that yields a | |
| 569 | * {@link Stream} of {@link Grouped} results. | |
| 570 | * <p> | |
| 571 | * Elements within a group preserve their encounter order. Instances of this collector are | |
| 572 | * not intended to be reused. | |
| 573 | * | |
| 574 | * <br> | |
| 575 | * Example: | |
| 576 | * <pre>{@code | |
| 577 | * CompletableFuture<Stream<Grouped<String, String>>> future = Stream.of(t1, t2, t3) | |
| 578 | * .collect(parallelBy(Task::groupId, t -> compute(t), executor)); | |
| 579 | * }</pre> | |
| 580 | * | |
| 581 | * @param classifier function that assigns each element to a group | |
| 582 | * @param mapper transformation applied to each element | |
| 583 | * @param executor the {@code Executor} used for asynchronous execution | |
| 584 | * @param <T> the input element type | |
| 585 | * @param <K> the classification key type | |
| 586 | * @param <R> the mapped element type | |
| 587 | * | |
| 588 | * @return a {@code Collector} producing a {@link CompletableFuture} | |
| 589 | * of a {@link Stream} of {@link Grouped} results | |
| 590 | * | |
| 591 | * @since 3.4.0 | |
| 592 | */ | |
| 593 | public static <T, K, R> Collector<T, ?, CompletableFuture<Stream<Grouped<K, R>>>> parallelBy( | |
| 594 | Function<? super T, ? extends K> classifier, | |
| 595 | Function<? super T, ? extends R> mapper, | |
| 596 | Executor executor) { | |
| 597 | ||
| 598 |
1
1. parallelBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelBy → KILLED |
return Factory.collectingBy(classifier, mapper, Options.executor(executor)); |
| 599 | } | |
| 600 | ||
| 601 | /** | |
| 602 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 603 | * and returns a {@link Stream} of the mapped elements as they arrive. | |
| 604 | * <p> | |
| 605 | * For a parallelism of 1, the stream is executed by the calling thread. | |
| 606 | * | |
| 607 | * <br> | |
| 608 | * Example: | |
| 609 | * <pre>{@code | |
| 610 | * Stream.of(1, 2, 3) | |
| 611 | * .collect(parallelToStream(i -> foo())) | |
| 612 | * .forEach(System.out::println); | |
| 613 | * }</pre> | |
| 614 | * | |
| 615 | * @param mapper a transformation applied to each element | |
| 616 | * @param <T> the input element type | |
| 617 | * @param <R> the type produced by {@code mapper} | |
| 618 | * | |
| 619 | * @return a {@code Collector} producing a {@link Stream} of mapped elements in parallel | |
| 620 | * | |
| 621 | * @since 3.0.0 | |
| 622 | */ | |
| 623 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream( | |
| 624 | Function<? super T, ? extends R> mapper) { | |
| 625 | ||
| 626 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper); |
| 627 | } | |
| 628 | ||
| 629 | /** | |
| 630 | * A convenience {@link Collector} that performs parallel computations by classifying elements | |
| 631 | * using the provided {@code classifier}, applying the given {@code mapper}, and producing a | |
| 632 | * {@link Stream} of {@link Grouped} elements as they become available. | |
| 633 | * <p> | |
| 634 | * Each group is processed independently on Virtual Threads, and every batch is guaranteed to | |
| 635 | * be executed on a single thread. The encounter order within each group is preserved. | |
| 636 | * | |
| 637 | * <br> | |
| 638 | * Example: | |
| 639 | * <pre>{@code | |
| 640 | * Stream.of(task1, task2, task3) | |
| 641 | * .collect(parallelToStreamBy(Task::groupId, t -> compute(t))) | |
| 642 | * .forEach(System.out::println); | |
| 643 | * }</pre> | |
| 644 | * | |
| 645 | * @param classifier function that assigns each input element to a group | |
| 646 | * @param mapper transformation applied to each element | |
| 647 | * @param <T> the input element type | |
| 648 | * @param <K> the classification key type | |
| 649 | * @param <R> the mapped element type | |
| 650 | * | |
| 651 | * @return a {@code Collector} producing a {@link Stream} of {@link Grouped} elements | |
| 652 | * computed in parallel | |
| 653 | * | |
| 654 | * @since 3.4.0 | |
| 655 | */ | |
| 656 | public static <T, K, R> Collector<T, ?, Stream<Grouped<K, R>>> parallelToStreamBy( | |
| 657 | Function<? super T, ? extends K> classifier, | |
| 658 | Function<? super T, ? extends R> mapper) { | |
| 659 | ||
| 660 |
1
1. parallelToStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper); |
| 661 | } | |
| 662 | ||
| 663 | /** | |
| 664 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 665 | * and returns a {@link Stream} of the mapped elements as they arrive. | |
| 666 | * <p> | |
| 667 | * For a parallelism of 1, the stream is executed by the calling thread. | |
| 668 | * | |
| 669 | * <br> | |
| 670 | * Example: | |
| 671 | * <pre>{@code | |
| 672 | * Stream.of(1, 2, 3) | |
| 673 | * .collect(parallelToStream(i -> foo(), 2)) | |
| 674 | * .forEach(System.out::println); | |
| 675 | * }</pre> | |
| 676 | * | |
| 677 | * @param mapper a transformation applied to each element | |
| 678 | * @param parallelism the maximum degree of parallelism | |
| 679 | * @param <T> the input element type | |
| 680 | * @param <R> the type produced by {@code mapper} | |
| 681 | * | |
| 682 | * @return a {@code Collector} producing a {@link Stream} of mapped elements in parallel | |
| 683 | * | |
| 684 | * @since 3.2.0 | |
| 685 | */ | |
| 686 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream( | |
| 687 | Function<? super T, ? extends R> mapper, | |
| 688 | int parallelism) { | |
| 689 | ||
| 690 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper, Options.parallelism(parallelism)); |
| 691 | } | |
| 692 | ||
| 693 | /** | |
| 694 | * A convenience {@link Collector} that performs parallel computations by classifying elements | |
| 695 | * using the provided {@code classifier}, applying the given {@code mapper}, and producing a | |
| 696 | * {@link Stream} of {@link Grouped} elements as they become available. | |
| 697 | * <p> | |
| 698 | * Each group is processed independently on Virtual Threads, and every batch is guaranteed to | |
| 699 | * be executed on a single thread. The encounter order within each group is preserved. | |
| 700 | * A {@code parallelism} parameter limits the maximum number of concurrently processed groups. | |
| 701 | * | |
| 702 | * <br> | |
| 703 | * Example: | |
| 704 | * <pre>{@code | |
| 705 | * Stream.of(t1, t2, t3) | |
| 706 | * .collect(parallelToStreamBy(Task::groupId, t -> compute(t), 2)) | |
| 707 | * .forEach(System.out::println); | |
| 708 | * }</pre> | |
| 709 | * | |
| 710 | * @param classifier function that assigns each input element to a group | |
| 711 | * @param mapper transformation applied to each element | |
| 712 | * @param parallelism the maximum degree of parallelism | |
| 713 | * @param <T> the input element type | |
| 714 | * @param <K> the classification key type | |
| 715 | * @param <R> the mapped element type | |
| 716 | * | |
| 717 | * @return a {@code Collector} producing a {@link Stream} of {@link Grouped} elements | |
| 718 | * computed in parallel | |
| 719 | * | |
| 720 | * @since 3.4.0 | |
| 721 | */ | |
| 722 | public static <T, K, R> Collector<T, ?, Stream<Grouped<K, R>>> parallelToStreamBy( | |
| 723 | Function<? super T, ? extends K> classifier, | |
| 724 | Function<? super T, ? extends R> mapper, | |
| 725 | int parallelism) { | |
| 726 | ||
| 727 |
1
1. parallelToStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, Options.parallelism(parallelism)); |
| 728 | } | |
| 729 | ||
| 730 | /** | |
| 731 | * A convenience {@link Collector} that performs parallel computations on a custom {@link Executor} | |
| 732 | * with effectively unlimited parallelism and returns a {@link Stream} of the mapped elements as they arrive. | |
| 733 | * <p> | |
| 734 | * For a parallelism of 1, the stream is executed by the calling thread. | |
| 735 | * | |
| 736 | * <br> | |
| 737 | * Example: | |
| 738 | * <pre>{@code | |
| 739 | * Stream.of(1, 2, 3) | |
| 740 | * .collect(parallelToStream(i -> foo(), executor)) | |
| 741 | * .forEach(System.out::println); | |
| 742 | * }</pre> | |
| 743 | * | |
| 744 | * @param mapper a transformation applied to each element | |
| 745 | * @param executor the {@code Executor} used for asynchronous execution | |
| 746 | * @param <T> the input element type | |
| 747 | * @param <R> the type produced by {@code mapper} | |
| 748 | * | |
| 749 | * @return a {@code Collector} producing a {@link Stream} of mapped elements in parallel | |
| 750 | * | |
| 751 | * @since 3.3.0 | |
| 752 | */ | |
| 753 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream( | |
| 754 | Function<? super T, ? extends R> mapper, | |
| 755 | Executor executor) { | |
| 756 | ||
| 757 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper, Options.executor(executor)); |
| 758 | } | |
| 759 | ||
| 760 | /** | |
| 761 | * A convenience {@link Collector} that performs parallel computations by classifying elements | |
| 762 | * using the provided {@code classifier}, applying the given {@code mapper}, and producing a | |
| 763 | * {@link Stream} of {@link Grouped} elements as they become available. | |
| 764 | * <p> | |
| 765 | * Each group is processed independently on the supplied {@link Executor}, and every batch is | |
| 766 | * guaranteed to be executed on a single thread. The encounter order within each group is preserved. | |
| 767 | * | |
| 768 | * <br> | |
| 769 | * Example: | |
| 770 | * <pre>{@code | |
| 771 | * Stream.of(t1, t2, t3) | |
| 772 | * .collect(parallelToStreamBy(Task::groupId, t -> compute(t), executor)) | |
| 773 | * .forEach(System.out::println); | |
| 774 | * }</pre> | |
| 775 | * | |
| 776 | * @param classifier function that assigns each input element to a group | |
| 777 | * @param mapper transformation applied to each element | |
| 778 | * @param executor the {@code Executor} used for asynchronous execution | |
| 779 | * @param <T> the input element type | |
| 780 | * @param <K> the classification key type | |
| 781 | * @param <R> the mapped element type | |
| 782 | * | |
| 783 | * @return a {@code Collector} producing a {@link Stream} of {@link Grouped} elements | |
| 784 | * computed in parallel | |
| 785 | * | |
| 786 | * @since 3.4.0 | |
| 787 | */ | |
| 788 | public static <T, K, R> Collector<T, ?, Stream<Grouped<K, R>>> parallelToStreamBy( | |
| 789 | Function<? super T, ? extends K> classifier, | |
| 790 | Function<? super T, ? extends R> mapper, | |
| 791 | Executor executor) { | |
| 792 | ||
| 793 |
1
1. parallelToStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, Options.executor(executor)); |
| 794 | } | |
| 795 | ||
| 796 | /** | |
| 797 | * A convenience {@link Collector} that performs parallel computations on a custom {@link Executor} | |
| 798 | * and returns a {@link Stream} yielding results as soon as they are produced. | |
| 799 | * <p> | |
| 800 | * Each input element is submitted independently for asynchronous processing using the provided | |
| 801 | * {@code mapper}. Execution may proceed in parallel up to the configured {@code parallelism}. | |
| 802 | * When the parallelism is set to {@code 1}, all work is performed on the calling thread. | |
| 803 | * <p> | |
| 804 | * Ordering characteristics: | |
| 805 | * <ul> | |
| 806 | * <li>The encounter order of input elements is not preserved.</li> | |
| 807 | * <li>Results are emitted in the order in which they complete.</li> | |
| 808 | * </ul> | |
| 809 | * <p> | |
| 810 | * Example: | |
| 811 | * <pre>{@code | |
| 812 | * Stream.of(1, 2, 3) | |
| 813 | * .collect(parallelToStream(i -> foo(i), executor, 2)) | |
| 814 | * .forEach(System.out::println); | |
| 815 | * }</pre> | |
| 816 | * | |
| 817 | * @param mapper transformation applied to each element | |
| 818 | * @param executor the {@code Executor} used for asynchronous execution | |
| 819 | * @param parallelism the maximum degree of parallelism | |
| 820 | * @param <T> the input element type | |
| 821 | * @param <R> the result type produced by {@code mapper} | |
| 822 | * | |
| 823 | * @return a {@code Collector} producing a {@link Stream} of mapped results as they complete | |
| 824 | * | |
| 825 | * @since 2.0.0 | |
| 826 | */ | |
| 827 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 828 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED |
return Factory.streaming(mapper, Options.executor(executor), Options.parallelism(parallelism)); |
| 829 | } | |
| 830 | ||
| 831 | /** | |
| 832 | * A convenience {@link Collector} that performs parallel computations on a custom {@link Executor}, | |
| 833 | * ensuring that all elements classified into the same group are processed on a single thread. | |
| 834 | * <p> | |
| 835 | * Incoming elements are partitioned using the provided {@code classifier}. Each partition | |
| 836 | * (i.e., batch associated with a classification key) is executed as a unit, guaranteeing that all | |
| 837 | * elements within that batch are processed by the same thread. Different batches may run in | |
| 838 | * parallel depending on the configured {@code parallelism}. | |
| 839 | * <p> | |
| 840 | * Ordering guarantees: | |
| 841 | * <ul> | |
| 842 | * <li>Elements within the same batch preserve their encounter order.</li> | |
| 843 | * <li>Batches themselves may execute and complete in any order.</li> | |
| 844 | * </ul> | |
| 845 | * <p> | |
| 846 | * The resulting {@link Stream} emits mapped results as soon as they are produced. If | |
| 847 | * {@code parallelism} is set to {@code 1}, all work is executed on the calling thread. | |
| 848 | * | |
| 849 | * <br> | |
| 850 | * Example: | |
| 851 | * <pre>{@code | |
| 852 | * Stream.of(t1, t2, t3) | |
| 853 | * .collect(parallelToStreamBy(Task::groupId, t -> compute(t), executor, 4)) | |
| 854 | * .forEach(System.out::println); | |
| 855 | * }</pre> | |
| 856 | * | |
| 857 | * @param classifier function that assigns elements to groups; all elements with the same key | |
| 858 | * are guaranteed to run on the same thread | |
| 859 | * @param mapper transformation applied to each element | |
| 860 | * @param executor the {@code Executor} used for asynchronous execution | |
| 861 | * @param parallelism the maximum allowed parallelism | |
| 862 | * @param <T> the input element type | |
| 863 | * @param <K> the classification key type | |
| 864 | * @param <R> the mapped result type | |
| 865 | * | |
| 866 | * @return a {@code Collector} producing a {@link Stream} of mapped results as they become available | |
| 867 | * | |
| 868 | * @since 3.4.0 | |
| 869 | */ | |
| 870 | public static <T, K, R> Collector<T, ?, Stream<Grouped<K, R>>> parallelToStreamBy(Function<? super T, ? extends K> classifier, Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 871 |
1
1. parallelToStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, Options.executor(executor), Options.parallelism(parallelism)); |
| 872 | } | |
| 873 | ||
| 874 | /** | |
| 875 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 876 | * and returns a {@link Stream} of the mapped elements as they arrive while maintaining the initial order. | |
| 877 | * <p> | |
| 878 | * For a parallelism of 1, the stream is executed by the calling thread. | |
| 879 | * | |
| 880 | * <br> | |
| 881 | * Example: | |
| 882 | * <pre>{@code | |
| 883 | * Stream.of(1, 2, 3) | |
| 884 | * .collect(parallelToOrderedStream(i -> foo())) | |
| 885 | * .forEach(System.out::println); | |
| 886 | * }</pre> | |
| 887 | * | |
| 888 | * @param mapper a transformation applied to each element | |
| 889 | * @param <T> the input element type | |
| 890 | * @param <R> the type produced by {@code mapper} | |
| 891 | * | |
| 892 | * @return a {@code Collector} producing a {@link Stream} of mapped elements in parallel, preserving order | |
| 893 | * | |
| 894 | * @since 3.0.0 | |
| 895 | */ | |
| 896 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream( | |
| 897 | Function<? super T, ? extends R> mapper) { | |
| 898 | ||
| 899 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED |
return Factory.streaming(mapper, Options.ordered()); |
| 900 | } | |
| 901 | ||
| 902 | /** | |
| 903 | * A convenience {@link Collector} that performs parallel computations by classifying elements | |
| 904 | * using the provided {@code classifier}, applying the given {@code mapper}, and producing a | |
| 905 | * {@link Stream} of {@link Grouped} elements as they become available while preserving the | |
| 906 | * original encounter order of input elements. | |
| 907 | * <p> | |
| 908 | * Ordering guarantees: | |
| 909 | * <ul> | |
| 910 | * <li>The encounter order of input elements is preserved within the resulting {@link Stream}.</li> | |
| 911 | * <li>Parallel execution does not affect the final ordering of elements in the resulting stream.</li> | |
| 912 | * </ul> | |
| 913 | * <p> | |
| 914 | * Each group is processed independently on Virtual Threads, and every batch is guaranteed to | |
| 915 | * be executed on a single thread. | |
| 916 | * | |
| 917 | * <br> | |
| 918 | * Example: | |
| 919 | * <pre>{@code | |
| 920 | * Stream.of(t1, t2, t3) | |
| 921 | * .collect(parallelToOrderedStreamBy(Task::groupId, t -> compute(t))) | |
| 922 | * .forEach(System.out::println); | |
| 923 | * }</pre> | |
| 924 | * | |
| 925 | * @param classifier function that assigns elements to groups | |
| 926 | * @param mapper transformation applied to each element | |
| 927 | * @param <T> the input element type | |
| 928 | * @param <K> the classification key type | |
| 929 | * @param <R> the mapped element type | |
| 930 | * | |
| 931 | * @return a {@code Collector} producing a {@link Stream} of {@link Grouped} elements | |
| 932 | * computed in parallel while preserving input order | |
| 933 | * | |
| 934 | * @since 3.4.0 | |
| 935 | */ | |
| 936 | public static <T, K, R> Collector<T, ?, Stream<Grouped<K, R>>> parallelToOrderedStreamBy( | |
| 937 | Function<? super T, ? extends K> classifier, | |
| 938 | Function<? super T, ? extends R> mapper) { | |
| 939 | ||
| 940 |
1
1. parallelToOrderedStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, Options.ordered()); |
| 941 | } | |
| 942 | ||
| 943 | /** | |
| 944 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 945 | * while preserving the encounter order of the input elements. Results are emitted in the same | |
| 946 | * order as the corresponding elements were encountered, regardless of when individual tasks | |
| 947 | * complete. | |
| 948 | * <p> | |
| 949 | * Each element is submitted independently for asynchronous processing on Virtual Threads using | |
| 950 | * the provided {@code mapper}. Execution may proceed in parallel up to the configured | |
| 951 | * {@code parallelism}. When the parallelism is set to {@code 1}, all work is performed on the | |
| 952 | * calling thread. | |
| 953 | * <p> | |
| 954 | * Ordering guarantees: | |
| 955 | * <ul> | |
| 956 | * <li>The encounter order of input elements is preserved.</li> | |
| 957 | * <li>Parallel execution does not affect the final ordering of the resulting stream.</li> | |
| 958 | * </ul> | |
| 959 | * | |
| 960 | * <br> | |
| 961 | * Example: | |
| 962 | * <pre>{@code | |
| 963 | * Stream.of(1, 2, 3) | |
| 964 | * .collect(parallelToOrderedStream(i -> foo(i), 2)) | |
| 965 | * .forEach(System.out::println); | |
| 966 | * }</pre> | |
| 967 | * | |
| 968 | * @param mapper transformation applied to each element | |
| 969 | * @param parallelism the maximum degree of parallelism | |
| 970 | * @param <T> the input element type | |
| 971 | * @param <R> the mapped result type | |
| 972 | * | |
| 973 | * @return a {@code Collector} producing an ordered {@link Stream} of mapped results | |
| 974 | * | |
| 975 | * @since 3.2.0 | |
| 976 | */ | |
| 977 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream( | |
| 978 | Function<? super T, ? extends R> mapper, | |
| 979 | int parallelism) { | |
| 980 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED |
return Factory.streaming(mapper, Options.ordered(), Options.parallelism(parallelism)); |
| 981 | } | |
| 982 | ||
| 983 | /** | |
| 984 | * A convenience {@link Collector} that performs parallel computations using Virtual Threads | |
| 985 | * while preserving the encounter order of both batches and the elements within each batch. | |
| 986 | * <p> | |
| 987 | * Incoming elements are partitioned using the provided {@code classifier}. Each partition | |
| 988 | * (i.e., batch associated with a classification key) is processed as a unit. Although batches | |
| 989 | * may execute in parallel up to the configured {@code parallelism}, their results are emitted | |
| 990 | * strictly in encounter order. | |
| 991 | * <p> | |
| 992 | * Ordering guarantees: | |
| 993 | * <ul> | |
| 994 | * <li>Elements within a batch preserve their encounter order.</li> | |
| 995 | * <li>Batches are emitted in the encounter order of their first element.</li> | |
| 996 | * <li>Parallel execution does not affect the final ordering of the resulting stream.</li> | |
| 997 | * </ul> | |
| 998 | * <p> | |
| 999 | * When {@code parallelism} is {@code 1}, all processing is performed on the calling thread. | |
| 1000 | * | |
| 1001 | * <br> | |
| 1002 | * Example: | |
| 1003 | * <pre>{@code | |
| 1004 | * Stream.of(t1, t2, t3) | |
| 1005 | * .collect(parallelToOrderedStreamBy(Task::groupId, t -> compute(t), 4)) | |
| 1006 | * .forEach(System.out::println); | |
| 1007 | * }</pre> | |
| 1008 | * | |
| 1009 | * @param classifier function that groups elements into batches | |
| 1010 | * @param mapper transformation applied to each element | |
| 1011 | * @param parallelism the maximum allowed parallelism | |
| 1012 | * @param <T> the input element type | |
| 1013 | * @param <K> the classification key type | |
| 1014 | * @param <R> the mapped result type | |
| 1015 | * | |
| 1016 | * @return a {@code Collector} producing an ordered {@link Stream} of {@link Grouped} results | |
| 1017 | * | |
| 1018 | * @since 3.4.0 | |
| 1019 | */ | |
| 1020 | public static <T, K, R> Collector<T, ?, Stream<Grouped<K, R>>> parallelToOrderedStreamBy( | |
| 1021 | Function<? super T, ? extends K> classifier, | |
| 1022 | Function<? super T, ? extends R> mapper, | |
| 1023 | int parallelism) { | |
| 1024 |
1
1. parallelToOrderedStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, Options.ordered(), Options.parallelism(parallelism)); |
| 1025 | } | |
| 1026 | ||
| 1027 | /** | |
| 1028 | * A convenience {@link Collector} that performs parallel computations on a custom {@link Executor} | |
| 1029 | * while preserving the encounter order of the input elements. Results are emitted in the same order | |
| 1030 | * as the corresponding elements were encountered, regardless of when individual tasks complete. | |
| 1031 | * <p> | |
| 1032 | * Each element is submitted independently for asynchronous processing using the provided | |
| 1033 | * {@code mapper} and executed on the specified {@code executor}. Execution may proceed with | |
| 1034 | * effectively unlimited parallelism. When all work is performed on the calling thread | |
| 1035 | * ({@code parallelism} of 1), the stream behaves sequentially. | |
| 1036 | * <p> | |
| 1037 | * Ordering guarantees: | |
| 1038 | * <ul> | |
| 1039 | * <li>The encounter order of input elements is preserved.</li> | |
| 1040 | * <li>Parallel execution does not affect the final ordering of the resulting stream.</li> | |
| 1041 | * </ul> | |
| 1042 | * | |
| 1043 | * <br> | |
| 1044 | * Example: | |
| 1045 | * <pre>{@code | |
| 1046 | * Stream.of(1, 2, 3) | |
| 1047 | * .collect(parallelToOrderedStream(i -> foo(i), executor)) | |
| 1048 | * .forEach(System.out::println); | |
| 1049 | * }</pre> | |
| 1050 | * | |
| 1051 | * @param mapper transformation applied to each element | |
| 1052 | * @param executor the {@code Executor} used for asynchronous execution | |
| 1053 | * @param <T> the input element type | |
| 1054 | * @param <R> the mapped result type | |
| 1055 | * | |
| 1056 | * @return a {@code Collector} producing an ordered {@link Stream} of mapped results | |
| 1057 | * | |
| 1058 | * @since 3.3.0 | |
| 1059 | */ | |
| 1060 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream( | |
| 1061 | Function<? super T, ? extends R> mapper, | |
| 1062 | Executor executor) { | |
| 1063 | ||
| 1064 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED |
return Factory.streaming(mapper, Options.ordered(), Options.executor(executor)); |
| 1065 | } | |
| 1066 | ||
| 1067 | /** | |
| 1068 | * A convenience {@link Collector} that performs parallel computations by classifying elements | |
| 1069 | * into batches using the provided {@code classifier}, executed on a custom {@link Executor}, | |
| 1070 | * while preserving the encounter order of both batches and elements within each batch. | |
| 1071 | * <p> | |
| 1072 | * Each batch is processed as a unit on the specified executor. Results are emitted in the | |
| 1073 | * encounter order of the batches and the elements within them, even though batches may execute | |
| 1074 | * concurrently. | |
| 1075 | * <p> | |
| 1076 | * Ordering guarantees: | |
| 1077 | * <ul> | |
| 1078 | * <li>Elements within a batch preserve their encounter order.</li> | |
| 1079 | * <li>Batches are emitted in the encounter order of their first element.</li> | |
| 1080 | * </ul> | |
| 1081 | * | |
| 1082 | * <br> | |
| 1083 | * Example: | |
| 1084 | * <pre>{@code | |
| 1085 | * Stream.of(t1, t2, t3) | |
| 1086 | * .collect(parallelToOrderedStreamBy(Task::groupId, t -> compute(t), executor)) | |
| 1087 | * .forEach(System.out::println); | |
| 1088 | * }</pre> | |
| 1089 | * | |
| 1090 | * @param classifier function that assigns elements to groups; all elements with the same key | |
| 1091 | * are guaranteed to run on the same thread | |
| 1092 | * @param mapper transformation applied to each element | |
| 1093 | * @param executor the {@code Executor} used for asynchronous execution | |
| 1094 | * @param <T> the input element type | |
| 1095 | * @param <K> the classification key type | |
| 1096 | * @param <R> the mapped result type | |
| 1097 | * | |
| 1098 | * @return a {@code Collector} producing an ordered {@link Stream} of {@link Grouped} results | |
| 1099 | * | |
| 1100 | * @since 3.4.0 | |
| 1101 | */ | |
| 1102 | public static <T, K, R> Collector<T, ?, Stream<Grouped<K, R>>> parallelToOrderedStreamBy( | |
| 1103 | Function<? super T, ? extends K> classifier, | |
| 1104 | Function<? super T, ? extends R> mapper, | |
| 1105 | Executor executor) { | |
| 1106 |
1
1. parallelToOrderedStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, Options.ordered(), Options.executor(executor)); |
| 1107 | } | |
| 1108 | ||
| 1109 | /** | |
| 1110 | * A convenience {@link Collector} that performs parallel computations on a custom {@link Executor} | |
| 1111 | * while preserving the encounter order of input elements. Results are emitted in the same order | |
| 1112 | * as the corresponding elements were encountered, regardless of completion order. | |
| 1113 | * <p> | |
| 1114 | * Each element is submitted independently for asynchronous processing using the provided | |
| 1115 | * {@code mapper} and executed on the specified {@code executor}. Execution may proceed in | |
| 1116 | * parallel up to the configured {@code parallelism}. When {@code parallelism} is {@code 1}, | |
| 1117 | * all work is executed on the calling thread. | |
| 1118 | * <p> | |
| 1119 | * Ordering guarantees: | |
| 1120 | * <ul> | |
| 1121 | * <li>The encounter order of input elements is preserved.</li> | |
| 1122 | * <li>Parallel execution does not affect the final ordering of the resulting stream.</li> | |
| 1123 | * </ul> | |
| 1124 | * | |
| 1125 | * <br> | |
| 1126 | * Example: | |
| 1127 | * <pre>{@code | |
| 1128 | * Stream.of(1, 2, 3) | |
| 1129 | * .collect(parallelToOrderedStream(i -> foo(i), executor, 2)) | |
| 1130 | * .forEach(System.out::println); | |
| 1131 | * }</pre> | |
| 1132 | * | |
| 1133 | * @param mapper transformation applied to each element | |
| 1134 | * @param executor the {@code Executor} used for asynchronous execution | |
| 1135 | * @param parallelism the maximum degree of parallelism | |
| 1136 | * @param <T> the input element type | |
| 1137 | * @param <R> the mapped result type | |
| 1138 | * | |
| 1139 | * @return a {@code Collector} producing an ordered {@link Stream} of mapped results | |
| 1140 | * | |
| 1141 | * @since 2.0.0 | |
| 1142 | */ | |
| 1143 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream( | |
| 1144 | Function<? super T, ? extends R> mapper, | |
| 1145 | Executor executor, | |
| 1146 | int parallelism) { | |
| 1147 | ||
| 1148 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED |
return Factory.streaming( |
| 1149 | mapper, | |
| 1150 | Options.ordered(), | |
| 1151 | Options.executor(executor), | |
| 1152 | Options.parallelism(parallelism) | |
| 1153 | ); | |
| 1154 | } | |
| 1155 | ||
| 1156 | /** | |
| 1157 | * A convenience {@link Collector} that performs parallel computations by classifying elements | |
| 1158 | * into batches using the provided {@code classifier}, executed on a custom {@link Executor}, | |
| 1159 | * while preserving the encounter order of both batches and elements within each batch. | |
| 1160 | * <p> | |
| 1161 | * Each batch is processed as a unit on the specified executor. Results are emitted in the | |
| 1162 | * encounter order of batches and of elements within each batch, even though batches may execute | |
| 1163 | * concurrently up to the configured {@code parallelism}. | |
| 1164 | * <p> | |
| 1165 | * Ordering guarantees: | |
| 1166 | * <ul> | |
| 1167 | * <li>Elements within a batch preserve their encounter order.</li> | |
| 1168 | * <li>Batches are emitted in the encounter order of their first element.</li> | |
| 1169 | * </ul> | |
| 1170 | * | |
| 1171 | * <br> | |
| 1172 | * Example: | |
| 1173 | * <pre>{@code | |
| 1174 | * Stream.of(t1, t2, t3) | |
| 1175 | * .collect(parallelToOrderedStreamBy(Task::groupId, t -> compute(t), executor, 4)) | |
| 1176 | * .forEach(System.out::println); | |
| 1177 | * }</pre> | |
| 1178 | * | |
| 1179 | * @param classifier function that assigns elements to groups; all elements with the same key | |
| 1180 | * are guaranteed to run on the same thread | |
| 1181 | * @param mapper transformation applied to each element | |
| 1182 | * @param executor the {@code Executor} used for asynchronous execution | |
| 1183 | * @param parallelism the maximum allowed parallelism | |
| 1184 | * @param <T> the input element type | |
| 1185 | * @param <K> the classification key type | |
| 1186 | * @param <R> the mapped result type | |
| 1187 | * | |
| 1188 | * @return a {@code Collector} producing an ordered {@link Stream} of {@link Grouped} results | |
| 1189 | * | |
| 1190 | * @since 3.4.0 | |
| 1191 | */ | |
| 1192 | public static <T, K, R> Collector<T, ?, Stream<Grouped<K, R>>> parallelToOrderedStreamBy( | |
| 1193 | Function<? super T, ? extends K> classifier, | |
| 1194 | Function<? super T, ? extends R> mapper, | |
| 1195 | Executor executor, | |
| 1196 | int parallelism) { | |
| 1197 | ||
| 1198 |
1
1. parallelToOrderedStreamBy : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStreamBy → KILLED |
return Factory.streamingBy(classifier, mapper, Options.ordered(), Options.executor(executor), Options.parallelism(parallelism)); |
| 1199 | } | |
| 1200 | ||
| 1201 | /** | |
| 1202 | * A convenience {@code Collector} for collecting a {@code Stream<CompletableFuture<T>>} | |
| 1203 | * into a {@code CompletableFuture<R>} using a provided {@code Collector<T, ?, R>} | |
| 1204 | * | |
| 1205 | * @param collector the {@code Collector} describing the reduction | |
| 1206 | * @param <T> the type of the collected elements | |
| 1207 | * @param <R> the result of the transformation | |
| 1208 | * | |
| 1209 | * @return a {@code Collector} which collects all futures and combines them into a single future | |
| 1210 | * using the provided downstream {@code Collector} | |
| 1211 | * | |
| 1212 | * @since 2.3.0 | |
| 1213 | */ | |
| 1214 | public static <T, R> Collector<CompletableFuture<T>, ?, CompletableFuture<R>> toFuture(Collector<T, ?, R> collector) { | |
| 1215 |
1
1. toFuture : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED |
return FutureCollectors.toFuture(collector); |
| 1216 | } | |
| 1217 | ||
| 1218 | /** | |
| 1219 | * A convenience {@code Collector} for collecting a {@code Stream<CompletableFuture<T>>} into a {@code CompletableFuture<List<T>>} | |
| 1220 | * | |
| 1221 | * @param <T> the type of the collected elements | |
| 1222 | * | |
| 1223 | * @return a {@code Collector} which collects all futures and combines them into a single future | |
| 1224 | * returning a list of results | |
| 1225 | * | |
| 1226 | * @since 2.3.0 | |
| 1227 | */ | |
| 1228 | public static <T> Collector<CompletableFuture<T>, ?, CompletableFuture<List<T>>> toFuture() { | |
| 1229 |
1
1. toFuture : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED |
return FutureCollectors.toFuture(); |
| 1230 | } | |
| 1231 | ||
| 1232 | /** | |
| 1233 | * A subset of collectors which perform operations in batches and not separately (one object in a thread pool's worker queue represents a batch of operations to be performed by a single thread) | |
| 1234 | */ | |
| 1235 | public static final class Batching { | |
| 1236 | ||
| 1237 | private Batching() { | |
| 1238 | } | |
| 1239 | ||
| 1240 | /** | |
| 1241 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 1242 | * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}. | |
| 1243 | * | |
| 1244 | * <br> | |
| 1245 | * Example: | |
| 1246 | * <pre>{@code | |
| 1247 | * CompletableFuture<List<String>> result = Stream.of(1, 2, 3) | |
| 1248 | * .collect(parallel(i -> foo(i), toList(), executor, 2)); | |
| 1249 | * }</pre> | |
| 1250 | * | |
| 1251 | * @param mapper a transformation to be performed in parallel | |
| 1252 | * @param collector the {@code Collector} describing the reduction | |
| 1253 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 1254 | * @param parallelism the max parallelism level | |
| 1255 | * @param <T> the type of the collected elements | |
| 1256 | * @param <R> the result returned by {@code mapper} | |
| 1257 | * @param <RR> the reduction result {@code collector} | |
| 1258 | * | |
| 1259 | * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel | |
| 1260 | * | |
| 1261 | * @since 2.1.0 | |
| 1262 | */ | |
| 1263 | public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector, Executor executor, int parallelism) { | |
| 1264 | Objects.requireNonNull(collector, "collector cannot be null"); | |
| 1265 |
2
1. lambda$parallel$0 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::lambda$parallel$0 → KILLED 2. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallel → KILLED |
return Factory.collecting(s -> s.collect(collector), mapper, |
| 1266 | Options.batched(), | |
| 1267 | Options.executor(executor), | |
| 1268 | Options.parallelism(parallelism)); | |
| 1269 | } | |
| 1270 | ||
| 1271 | /** | |
| 1272 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 1273 | * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements. | |
| 1274 | * | |
| 1275 | * <br><br> | |
| 1276 | * The collector maintains the order of processed {@link Stream}. Instances should not be reused. | |
| 1277 | * | |
| 1278 | * <br> | |
| 1279 | * Example: | |
| 1280 | * <pre>{@code | |
| 1281 | * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3) | |
| 1282 | * .collect(parallel(i -> foo(), executor, 2)); | |
| 1283 | * }</pre> | |
| 1284 | * | |
| 1285 | * @param mapper a transformation to be performed in parallel | |
| 1286 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 1287 | * @param parallelism the max parallelism level | |
| 1288 | * @param <T> the type of the collected elements | |
| 1289 | * @param <R> the result returned by {@code mapper} | |
| 1290 | * | |
| 1291 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 1292 | * | |
| 1293 | * @since 2.1.0 | |
| 1294 | */ | |
| 1295 | public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 1296 |
2
1. lambda$parallel$1 : replaced return value with Stream.empty for com/pivovarit/collectors/ParallelCollectors$Batching::lambda$parallel$1 → SURVIVED 2. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallel → KILLED |
return Factory.collecting((Function<Stream<R>, Stream<R>>) i -> i, mapper, |
| 1297 | Options.batched(), | |
| 1298 | Options.executor(executor), | |
| 1299 | Options.parallelism(parallelism)); | |
| 1300 | } | |
| 1301 | ||
| 1302 | /** | |
| 1303 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 1304 | * and returning a {@link Stream} instance returning results as they arrive. | |
| 1305 | * <p> | |
| 1306 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 1307 | * | |
| 1308 | * <br> | |
| 1309 | * Example: | |
| 1310 | * <pre>{@code | |
| 1311 | * Stream.of(1, 2, 3) | |
| 1312 | * .collect(parallelToStream(i -> foo(), executor, 2)) | |
| 1313 | * .forEach(System.out::println); | |
| 1314 | * }</pre> | |
| 1315 | * | |
| 1316 | * @param mapper a transformation to be performed in parallel | |
| 1317 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 1318 | * @param parallelism the max parallelism level | |
| 1319 | * @param <T> the type of the collected elements | |
| 1320 | * @param <R> the result returned by {@code mapper} | |
| 1321 | * | |
| 1322 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 1323 | * | |
| 1324 | * @since 2.1.0 | |
| 1325 | */ | |
| 1326 | public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 1327 |
1
1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallelToStream → KILLED |
return Factory.streaming(mapper, |
| 1328 | Options.batched(), | |
| 1329 | Options.executor(executor), | |
| 1330 | Options.parallelism(parallelism)); | |
| 1331 | } | |
| 1332 | ||
| 1333 | /** | |
| 1334 | * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} | |
| 1335 | * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order. | |
| 1336 | * <p> | |
| 1337 | * For the parallelism of 1, the stream is executed by the calling thread. | |
| 1338 | * | |
| 1339 | * <br> | |
| 1340 | * Example: | |
| 1341 | * <pre>{@code | |
| 1342 | * Stream.of(1, 2, 3) | |
| 1343 | * .collect(parallelToOrderedStream(i -> foo(), executor, 2)) | |
| 1344 | * .forEach(System.out::println); | |
| 1345 | * }</pre> | |
| 1346 | * | |
| 1347 | * @param mapper a transformation to be performed in parallel | |
| 1348 | * @param executor the {@code Executor} to use for asynchronous execution | |
| 1349 | * @param parallelism the max parallelism level | |
| 1350 | * @param <T> the type of the collected elements | |
| 1351 | * @param <R> the result returned by {@code mapper} | |
| 1352 | * | |
| 1353 | * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel | |
| 1354 | * | |
| 1355 | * @since 2.1.0 | |
| 1356 | */ | |
| 1357 | public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 1358 |
1
1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallelToOrderedStream → KILLED |
return Factory.streaming(mapper, |
| 1359 | Options.ordered(), | |
| 1360 | Options.batched(), | |
| 1361 | Options.executor(executor), | |
| 1362 | Options.parallelism(parallelism)); | |
| 1363 | } | |
| 1364 | } | |
| 1365 | } | |
Mutations | ||
| 53 |
1.1 2.2 |
|
| 94 |
1.1 2.2 |
|
| 129 |
1.1 2.2 |
|
| 173 |
1.1 2.2 |
|
| 210 |
1.1 2.2 |
|
| 256 |
1.1 2.2 |
|
| 291 |
1.1 2.2 |
|
| 335 |
1.1 2.2 |
|
| 363 |
1.1 2.2 |
|
| 397 |
1.1 |
|
| 426 |
1.1 2.2 |
|
| 462 |
1.1 |
|
| 494 |
1.1 2.2 |
|
| 531 |
1.1 |
|
| 562 |
1.1 2.2 |
|
| 598 |
1.1 |
|
| 626 |
1.1 |
|
| 660 |
1.1 |
|
| 690 |
1.1 |
|
| 727 |
1.1 |
|
| 757 |
1.1 |
|
| 793 |
1.1 |
|
| 828 |
1.1 |
|
| 871 |
1.1 |
|
| 899 |
1.1 |
|
| 940 |
1.1 |
|
| 980 |
1.1 |
|
| 1024 |
1.1 |
|
| 1064 |
1.1 |
|
| 1106 |
1.1 |
|
| 1148 |
1.1 |
|
| 1198 |
1.1 |
|
| 1215 |
1.1 |
|
| 1229 |
1.1 |
|
| 1265 |
1.1 2.2 |
|
| 1296 |
1.1 2.2 |
|
| 1327 |
1.1 |
|
| 1358 |
1.1 |