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

Mutations

42

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:#5]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

68

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:#3]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

95

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

121

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

147

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

174

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

202

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:#2]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallel → KILLED

229

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

255

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

282

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:#17]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED

309

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

337

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:#29]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToStream → KILLED

363

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

390

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:#16]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED

417

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

445

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:#32]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors::parallelToOrderedStream → KILLED

462

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

476

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

511

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

540

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

568

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:#8]
replaced return value with null for com/pivovarit/collectors/ParallelCollectors$Batching::parallelToStream → KILLED

596

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.17.4