ParallelCollectors.java

1
package com.pivovarit.collectors;
2
3
import java.util.List;
4
import java.util.concurrent.CompletableFuture;
5
import java.util.concurrent.Executor;
6
import java.util.function.Function;
7
import java.util.stream.Collector;
8
import java.util.stream.Stream;
9
10
import static com.pivovarit.collectors.Option.batched;
11
import static com.pivovarit.collectors.Option.executor;
12
import static com.pivovarit.collectors.Option.parallelism;
13
14
/**
15
 * An umbrella class exposing static factory methods for instantiating parallel {@link Collector}s
16
 *
17
 * @author Grzegorz Piwowarek
18
 */
19
public final class ParallelCollectors {
20
21
    private ParallelCollectors() {
22
    }
23
24
    /**
25
     * A convenience {@link Collector} used for executing parallel computations using Virtual Threads
26
     * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}.
27
     *
28
     * <br>
29
     * Example:
30
     * <pre>{@code
31
     * CompletableFuture<List<String>> result = Stream.of(1, 2, 3)
32
     *   .collect(parallel(i -> foo(i), toList()));
33
     * }</pre>
34
     *
35
     * @param mapper    a transformation to be performed in parallel
36
     * @param collector the {@code Collector} describing the reduction
37
     * @param <T>       the type of the collected elements
38
     * @param <R>       the result returned by {@code mapper}
39
     * @param <RR>      the reduction result {@code collector}
40
     *
41
     * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel
42
     *
43
     * @since 3.0.0
44
     */
45
    public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector) {
46 2 1. lambda$parallel$0 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$0 → KILLED
2. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED
        return Factory.collecting(s -> s.collect(collector), mapper);
47
    }
48
49
    /**
50
     * A convenience {@link Collector} used for executing parallel computations using Virtual Threads
51
     * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}.
52
     *
53
     * <br>
54
     * Example:
55
     * <pre>{@code
56
     * CompletableFuture<List<String>> result = Stream.of(1, 2, 3)
57
     *   .collect(parallel(i -> foo(i), toList(), executor, 2));
58
     * }</pre>
59
     *
60
     * @param mapper      a transformation to be performed in parallel
61
     * @param collector   the {@code Collector} describing the reduction
62
     * @param <T>         the type of the collected elements
63
     * @param <R>         the result returned by {@code mapper}
64
     * @param <RR>        the reduction result {@code collector}
65
     * @param parallelism the max parallelism level
66
     *
67
     * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel
68
     *
69
     * @since 3.2.0
70
     */
71
    public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector, int parallelism) {
72 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, parallelism(parallelism));
73
    }
74
75
    /**
76
     * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor}
77
     * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}.
78
     *
79
     * <br>
80
     * Example:
81
     * <pre>{@code
82
     * CompletableFuture<List<String>> result = Stream.of(1, 2, 3)
83
     *   .collect(parallel(i -> foo(i), toList(), executor, 2));
84
     * }</pre>
85
     *
86
     * @param mapper      a transformation to be performed in parallel
87
     * @param collector   the {@code Collector} describing the reduction
88
     * @param executor    the {@code Executor} to use for asynchronous execution
89
     * @param <T>         the type of the collected elements
90
     * @param <R>         the result returned by {@code mapper}
91
     * @param <RR>        the reduction result {@code collector}
92
     * @param parallelism the max parallelism level
93
     *
94
     * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel
95
     *
96
     * @since 2.0.0
97
     */
98
    public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector, Executor executor, int parallelism) {
99 2 1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED
2. lambda$parallel$2 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$2 → KILLED
        return Factory.collecting(s -> s.collect(collector), mapper, executor(executor), parallelism(parallelism));
100
    }
101
102
    /**
103
     * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} with unlimited parallelism
104
     * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}.
105
     *
106
     * <br>
107
     * Example:
108
     * <pre>{@code
109
     * CompletableFuture<List<String>> result = Stream.of(1, 2, 3)
110
     *   .collect(parallel(i -> foo(i), toList(), executor));
111
     * }</pre>
112
     *
113
     * @param mapper    a transformation to be performed in parallel
114
     * @param collector the {@code Collector} describing the reduction
115
     * @param executor  the {@code Executor} to use for asynchronous execution
116
     * @param <T>       the type of the collected elements
117
     * @param <R>       the result returned by {@code mapper}
118
     * @param <RR>      the reduction result {@code collector}
119
     *
120
     * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel
121
     *
122
     * @since 3.3.0
123
     */
124
    public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector, Executor executor) {
125 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, executor(executor));
126
    }
127
128
    /**
129
     * A convenience {@link Collector} used for executing parallel computations using Virtual Threads
130
     * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements.
131
     *
132
     * <br><br>
133
     * The collector maintains the order of processed {@link Stream}. Instances should not be reused.
134
     *
135
     * <br>
136
     * Example:
137
     * <pre>{@code
138
     * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3)
139
     *   .collect(parallel(i -> foo()));
140
     * }</pre>
141
     *
142
     * @param mapper a transformation to be performed in parallel
143
     * @param <T>    the type of the collected elements
144
     * @param <R>    the result returned by {@code mapper}
145
     *
146
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
147
     *
148
     * @since 3.0.0
149
     */
150
    public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper) {
151 1 1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED
        return Factory.collecting(mapper);
152
    }
153
154
    /**
155
     * A convenience {@link Collector} used for executing parallel computations using Virtual Threads
156
     * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements.
157
     *
158
     * <br><br>
159
     * The collector maintains the order of processed {@link Stream}. Instances should not be reused.
160
     *
161
     * <br>
162
     * Example:
163
     * <pre>{@code
164
     * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3)
165
     *   .collect(parallel(i -> foo()));
166
     * }</pre>
167
     *
168
     * @param mapper      a transformation to be performed in parallel
169
     * @param parallelism the max parallelism level
170
     * @param <T>         the type of the collected elements
171
     * @param <R>         the result returned by {@code mapper}
172
     *
173
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
174
     *
175
     * @since 3.2.0
176
     */
177
    public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper, int parallelism) {
178 1 1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED
        return Factory.collecting(mapper, parallelism(parallelism));
179
    }
180
181
    /**
182
     * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor}
183
     * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements.
184
     *
185
     * <br><br>
186
     * The collector maintains the order of processed {@link Stream}. Instances should not be reused.
187
     *
188
     * <br>
189
     * Example:
190
     * <pre>{@code
191
     * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3)
192
     *   .collect(parallel(i -> foo(), executor, 2));
193
     * }</pre>
194
     *
195
     * @param mapper      a transformation to be performed in parallel
196
     * @param executor    the {@code Executor} to use for asynchronous execution
197
     * @param parallelism the max parallelism level
198
     * @param <T>         the type of the collected elements
199
     * @param <R>         the result returned by {@code mapper}
200
     *
201
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
202
     *
203
     * @since 2.0.0
204
     */
205
    public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) {
206 1 1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED
        return Factory.collecting(mapper, executor(executor), parallelism(parallelism));
207
    }
208
209
    /**
210
     * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} with unlimited parallelism
211
     * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements.
212
     *
213
     * <br><br>
214
     * The collector maintains the order of processed {@link Stream}. Instances should not be reused.
215
     *
216
     * <br>
217
     * Example:
218
     * <pre>{@code
219
     * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3)
220
     *   .collect(parallel(i -> foo(), executor));
221
     * }</pre>
222
     *
223
     * @param mapper   a transformation to be performed in parallel
224
     * @param executor the {@code Executor} to use for asynchronous execution
225
     * @param <T>      the type of the collected elements
226
     * @param <R>      the result returned by {@code mapper}
227
     *
228
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
229
     *
230
     * @since 3.3.0
231
     */
232
    public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper, Executor executor) {
233 1 1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED
        return Factory.collecting(mapper, executor(executor));
234
    }
235
236
    /**
237
     * A convenience {@link Collector} used for executing parallel computations using Virtual Threads
238
     * and returning a {@link Stream} instance returning results as they arrive.
239
     * <p>
240
     * For the parallelism of 1, the stream is executed by the calling thread.
241
     *
242
     * <br>
243
     * Example:
244
     * <pre>{@code
245
     * Stream.of(1, 2, 3)
246
     *   .collect(parallelToStream(i -> foo()))
247
     *   .forEach(System.out::println);
248
     * }</pre>
249
     *
250
     * @param mapper a transformation to be performed in parallel
251
     * @param <T>    the type of the collected elements
252
     * @param <R>    the result returned by {@code mapper}
253
     *
254
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
255
     *
256
     * @since 3.0.0
257
     */
258
    public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper) {
259 1 1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED
        return Factory.streaming(mapper, false);
260
    }
261
262
    /**
263
     * A convenience {@link Collector} used for executing parallel computations using Virtual Threads
264
     * and returning a {@link Stream} instance returning results as they arrive.
265
     * <p>
266
     * For the parallelism of 1, the stream is executed by the calling thread.
267
     *
268
     * <br>
269
     * Example:
270
     * <pre>{@code
271
     * Stream.of(1, 2, 3)
272
     *   .collect(parallelToStream(i -> foo(), executor, 2))
273
     *   .forEach(System.out::println);
274
     * }</pre>
275
     *
276
     * @param mapper      a transformation to be performed in parallel
277
     * @param parallelism the max parallelism level
278
     * @param <T>         the type of the collected elements
279
     * @param <R>         the result returned by {@code mapper}
280
     *
281
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
282
     *
283
     * @since 3.2.0
284
     */
285
    public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, int parallelism) {
286 1 1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED
        return Factory.streaming(mapper, false, parallelism(parallelism));
287
    }
288
289
    /**
290
     * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} with unlimited parallelism
291
     * and returning a {@link Stream} instance returning results as they arrive.
292
     * <p>
293
     * For the parallelism of 1, the stream is executed by the calling thread.
294
     *
295
     * <br>
296
     * Example:
297
     * <pre>{@code
298
     * Stream.of(1, 2, 3)
299
     *   .collect(parallelToStream(i -> foo(), executor, 2))
300
     *   .forEach(System.out::println);
301
     * }</pre>
302
     *
303
     * @param mapper   a transformation to be performed in parallel
304
     * @param executor the {@code Executor} to use for asynchronous execution
305
     * @param <T>      the type of the collected elements
306
     * @param <R>      the result returned by {@code mapper}
307
     *
308
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
309
     *
310
     * @since 3.3.0
311
     */
312
    public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, Executor executor) {
313 1 1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED
        return Factory.streaming(mapper, false, executor(executor));
314
    }
315
316
    /**
317
     * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor}
318
     * and returning a {@link Stream} instance returning results as they arrive.
319
     * <p>
320
     * For the parallelism of 1, the stream is executed by the calling thread.
321
     *
322
     * <br>
323
     * Example:
324
     * <pre>{@code
325
     * Stream.of(1, 2, 3)
326
     *   .collect(parallelToStream(i -> foo(), executor, 2))
327
     *   .forEach(System.out::println);
328
     * }</pre>
329
     *
330
     * @param mapper      a transformation to be performed in parallel
331
     * @param executor    the {@code Executor} to use for asynchronous execution
332
     * @param parallelism the max parallelism level
333
     * @param <T>         the type of the collected elements
334
     * @param <R>         the result returned by {@code mapper}
335
     *
336
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
337
     *
338
     * @since 2.0.0
339
     */
340
    public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) {
341 1 1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED
        return Factory.streaming(mapper, false, executor(executor), parallelism(parallelism));
342
    }
343
344
    /**
345
     * A convenience {@link Collector} used for executing parallel computations using Virtual Threads
346
     * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order.
347
     * <p>
348
     * For the parallelism of 1, the stream is executed by the calling thread.
349
     *
350
     * <br>
351
     * Example:
352
     * <pre>{@code
353
     * Stream.of(1, 2, 3)
354
     *   .collect(parallelToOrderedStream(i -> foo()))
355
     *   .forEach(System.out::println);
356
     * }</pre>
357
     *
358
     * @param mapper a transformation to be performed in parallel
359
     * @param <T>    the type of the collected elements
360
     * @param <R>    the result returned by {@code mapper}
361
     *
362
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
363
     *
364
     * @since 3.0.0
365
     */
366
    public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper) {
367 1 1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED
        return Factory.streaming(mapper, true);
368
    }
369
370
    /**
371
     * A convenience {@link Collector} used for executing parallel computations using Virtual Threads
372
     * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order.
373
     * <p>
374
     * For the parallelism of 1, the stream is executed by the calling thread.
375
     *
376
     * <br>
377
     * Example:
378
     * <pre>{@code
379
     * Stream.of(1, 2, 3)
380
     *   .collect(parallelToOrderedStream(i -> foo(), executor, 2))
381
     *   .forEach(System.out::println);
382
     * }</pre>
383
     *
384
     * @param mapper      a transformation to be performed in parallel
385
     * @param parallelism the max parallelism level
386
     * @param <T>         the type of the collected elements
387
     * @param <R>         the result returned by {@code mapper}
388
     *
389
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
390
     *
391
     * @since 3.2.0
392
     */
393
    public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper, int parallelism) {
394 1 1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED
        return Factory.streaming(mapper, true, parallelism(parallelism));
395
    }
396
397
    /**
398
     * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor} with unlimited parallelism
399
     * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order.
400
     * <p>
401
     * For the parallelism of 1, the stream is executed by the calling thread.
402
     *
403
     * <br>
404
     * Example:
405
     * <pre>{@code
406
     * Stream.of(1, 2, 3)
407
     *   .collect(parallelToOrderedStream(i -> foo(), executor))
408
     *   .forEach(System.out::println);
409
     * }</pre>
410
     *
411
     * @param mapper   a transformation to be performed in parallel
412
     * @param executor the {@code Executor} to use for asynchronous execution
413
     * @param <T>      the type of the collected elements
414
     * @param <R>      the result returned by {@code mapper}
415
     *
416
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
417
     *
418
     * @since 3.3.0
419
     */
420
    public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper, Executor executor) {
421 1 1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED
        return Factory.streaming(mapper, true, executor(executor));
422
    }
423
424
    /**
425
     * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor}
426
     * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order.
427
     * <p>
428
     * For the parallelism of 1, the stream is executed by the calling thread.
429
     *
430
     * <br>
431
     * Example:
432
     * <pre>{@code
433
     * Stream.of(1, 2, 3)
434
     *   .collect(parallelToOrderedStream(i -> foo(), executor, 2))
435
     *   .forEach(System.out::println);
436
     * }</pre>
437
     *
438
     * @param mapper      a transformation to be performed in parallel
439
     * @param executor    the {@code Executor} to use for asynchronous execution
440
     * @param parallelism the max parallelism level
441
     * @param <T>         the type of the collected elements
442
     * @param <R>         the result returned by {@code mapper}
443
     *
444
     * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
445
     *
446
     * @since 2.0.0
447
     */
448
    public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) {
449 1 1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED
        return Factory.streaming(mapper, true, executor(executor), parallelism(parallelism));
450
    }
451
452
    /**
453
     * A convenience {@code Collector} for collecting a {@code Stream<CompletableFuture<T>>}
454
     * into a {@code CompletableFuture<R>} using a provided {@code Collector<T, ?, R>}
455
     *
456
     * @param collector the {@code Collector} describing the reduction
457
     * @param <T>       the type of the collected elements
458
     * @param <R>       the result of the transformation
459
     *
460
     * @return a {@code Collector} which collects all futures and combines them into a single future
461
     * using the provided downstream {@code Collector}
462
     *
463
     * @since 2.3.0
464
     */
465
    public static <T, R> Collector<CompletableFuture<T>, ?, CompletableFuture<R>> toFuture(Collector<T, ?, R> collector) {
466 1 1. toFuture : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED
        return FutureCollectors.toFuture(collector);
467
    }
468
469
    /**
470
     * A convenience {@code Collector} for collecting a {@code Stream<CompletableFuture<T>>} into a {@code CompletableFuture<List<T>>}
471
     *
472
     * @param <T> the type of the collected elements
473
     *
474
     * @return a {@code Collector} which collects all futures and combines them into a single future
475
     * returning a list of results
476
     *
477
     * @since 2.3.0
478
     */
479
    public static <T> Collector<CompletableFuture<T>, ?, CompletableFuture<List<T>>> toFuture() {
480 1 1. toFuture : replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED
        return FutureCollectors.toFuture();
481
    }
482
483
    /**
484
     * 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)
485
     */
486
    public static final class Batching {
487
488
        private Batching() {
489
        }
490
491
        /**
492
         * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor}
493
         * and returning them as a {@link CompletableFuture} containing a result of the application of the user-provided {@link Collector}.
494
         *
495
         * <br>
496
         * Example:
497
         * <pre>{@code
498
         * CompletableFuture<List<String>> result = Stream.of(1, 2, 3)
499
         *   .collect(parallel(i -> foo(i), toList(), executor, 2));
500
         * }</pre>
501
         *
502
         * @param mapper      a transformation to be performed in parallel
503
         * @param collector   the {@code Collector} describing the reduction
504
         * @param executor    the {@code Executor} to use for asynchronous execution
505
         * @param parallelism the max parallelism level
506
         * @param <T>         the type of the collected elements
507
         * @param <R>         the result returned by {@code mapper}
508
         * @param <RR>        the reduction result {@code collector}
509
         *
510
         * @return a {@code Collector} which collects all processed elements into a user-provided mutable {@code Collection} in parallel
511
         *
512
         * @since 2.1.0
513
         */
514
        public static <T, R, RR> Collector<T, ?, CompletableFuture<RR>> parallel(Function<? super T, ? extends R> mapper, Collector<R, ?, RR> collector, Executor executor, int parallelism) {
515 2 1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallel → KILLED
2. lambda$parallel$0 : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::lambda$parallel$0 → KILLED
            return Factory.collecting(s -> s.collect(collector), mapper,
516
              batched(),
517
              executor(executor),
518
              parallelism(parallelism));
519
        }
520
521
        /**
522
         * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor}
523
         * and returning them as {@link CompletableFuture} containing a {@link Stream} of these elements.
524
         *
525
         * <br><br>
526
         * The collector maintains the order of processed {@link Stream}. Instances should not be reused.
527
         *
528
         * <br>
529
         * Example:
530
         * <pre>{@code
531
         * CompletableFuture<Stream<String>> result = Stream.of(1, 2, 3)
532
         *   .collect(parallel(i -> foo(), executor, 2));
533
         * }</pre>
534
         *
535
         * @param mapper      a transformation to be performed in parallel
536
         * @param executor    the {@code Executor} to use for asynchronous execution
537
         * @param parallelism the max parallelism level
538
         * @param <T>         the type of the collected elements
539
         * @param <R>         the result returned by {@code mapper}
540
         *
541
         * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
542
         *
543
         * @since 2.1.0
544
         */
545
        public static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> parallel(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) {
546 1 1. parallel : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallel → KILLED
            return Factory.collecting(mapper,
547
              batched(),
548
              executor(executor),
549
              parallelism(parallelism));
550
        }
551
552
        /**
553
         * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor}
554
         * and returning a {@link Stream} instance returning results as they arrive.
555
         * <p>
556
         * For the parallelism of 1, the stream is executed by the calling thread.
557
         *
558
         * <br>
559
         * Example:
560
         * <pre>{@code
561
         * Stream.of(1, 2, 3)
562
         *   .collect(parallelToStream(i -> foo(), executor, 2))
563
         *   .forEach(System.out::println);
564
         * }</pre>
565
         *
566
         * @param mapper      a transformation to be performed in parallel
567
         * @param executor    the {@code Executor} to use for asynchronous execution
568
         * @param parallelism the max parallelism level
569
         * @param <T>         the type of the collected elements
570
         * @param <R>         the result returned by {@code mapper}
571
         *
572
         * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
573
         *
574
         * @since 2.1.0
575
         */
576
        public static <T, R> Collector<T, ?, Stream<R>> parallelToStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) {
577 1 1. parallelToStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallelToStream → KILLED
            return Factory.streaming(mapper, false,
578
              batched(),
579
              executor(executor),
580
              parallelism(parallelism));
581
        }
582
583
        /**
584
         * A convenience {@link Collector} used for executing parallel computations on a custom {@link Executor}
585
         * and returning a {@link Stream} instance returning results as they arrive while maintaining the initial order.
586
         * <p>
587
         * For the parallelism of 1, the stream is executed by the calling thread.
588
         *
589
         * <br>
590
         * Example:
591
         * <pre>{@code
592
         * Stream.of(1, 2, 3)
593
         *   .collect(parallelToOrderedStream(i -> foo(), executor, 2))
594
         *   .forEach(System.out::println);
595
         * }</pre>
596
         *
597
         * @param mapper      a transformation to be performed in parallel
598
         * @param executor    the {@code Executor} to use for asynchronous execution
599
         * @param parallelism the max parallelism level
600
         * @param <T>         the type of the collected elements
601
         * @param <R>         the result returned by {@code mapper}
602
         *
603
         * @return a {@code Collector} which collects all processed elements into a {@code Stream} in parallel
604
         *
605
         * @since 2.1.0
606
         */
607
        public static <T, R> Collector<T, ?, Stream<R>> parallelToOrderedStream(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) {
608 1 1. parallelToOrderedStream : replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallelToOrderedStream → KILLED
            return Factory.streaming(mapper, true,
609
              batched(),
610
              executor(executor),
611
              parallelism(parallelism));
612
        }
613
    }
614
}

Mutations

46

1.1
Location : lambda$parallel$0
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#5]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$0 → KILLED

2.2
Location : parallel
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#5]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

72

1.1
Location : parallel
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessEmptyWithMaxParallelism()]/[dynamic-test:#3]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

2.2
Location : lambda$parallel$1
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessEmptyWithMaxParallelism()]/[dynamic-test:#3]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$1 → KILLED

99

1.1
Location : parallel
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessEmptyWithMaxParallelism()]/[dynamic-test:#4]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

2.2
Location : lambda$parallel$2
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessEmptyWithMaxParallelism()]/[dynamic-test:#4]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$2 → KILLED

125

1.1
Location : parallel
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#7]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

2.2
Location : lambda$parallel$3
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#7]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::lambda$parallel$3 → KILLED

151

1.1
Location : parallel
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#1]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

178

1.1
Location : parallel
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#2]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

206

1.1
Location : parallel
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessAllElementsWithMaxParallelism()]/[dynamic-test:#2]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

233

1.1
Location : parallel
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#3]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

259

1.1
Location : parallelToStream
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#10]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED

286

1.1
Location : parallelToStream
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessEmptyWithMaxParallelism()]/[dynamic-test:#6]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED

313

1.1
Location : parallelToStream
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#12]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED

341

1.1
Location : parallelToStream
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessAllElementsWithMaxParallelism()]/[dynamic-test:#7]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED

367

1.1
Location : parallelToOrderedStream
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#15]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED

394

1.1
Location : parallelToOrderedStream
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessAllElementsWithMaxParallelism()]/[dynamic-test:#9]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED

421

1.1
Location : parallelToOrderedStream
Killed by : com.pivovarit.collectors.test.BasicProcessingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicProcessingTest]/[test-factory:shouldProcessEmpty()]/[dynamic-test:#17]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED

449

1.1
Location : parallelToOrderedStream
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessEmptyWithMaxParallelism()]/[dynamic-test:#10]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED

466

1.1
Location : toFuture
Killed by : com.pivovarit.collectors.FutureCollectorsTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.FutureCollectorsTest]/[method:shouldCollectToList()]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED

480

1.1
Location : toFuture
Killed by : com.pivovarit.collectors.FutureCollectorsTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.FutureCollectorsTest]/[method:shouldCollect()]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::toFuture → KILLED

515

1.1
Location : parallel
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessEmptyWithMaxParallelism()]/[dynamic-test:#5]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallel → KILLED

2.2
Location : lambda$parallel$0
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessEmptyWithMaxParallelism()]/[dynamic-test:#5]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::lambda$parallel$0 → KILLED

546

1.1
Location : parallel
Killed by : com.pivovarit.collectors.test.RejectedExecutionHandlingTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.RejectedExecutionHandlingTest]/[test-factory:shouldRejectInvalidRejectedExecutionHandlerWhenParallelismOneFactory()]/[dynamic-test:#2]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallel → KILLED

577

1.1
Location : parallelToStream
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessAllElementsWithMaxParallelism()]/[dynamic-test:#8]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallelToStream → KILLED

608

1.1
Location : parallelToOrderedStream
Killed by : com.pivovarit.collectors.test.BasicParallelismTest.[engine:junit-jupiter]/[class:com.pivovarit.collectors.test.BasicParallelismTest]/[test-factory:shouldProcessEmptyWithMaxParallelism()]/[dynamic-test:#11]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallelToOrderedStream → KILLED

Active mutators

Tests examined


Report generated by PIT 1.19.4