1 | package com.pivovarit.collectors; | |
2 | ||
3 | import java.util.concurrent.CompletableFuture; | |
4 | import java.util.concurrent.Executor; | |
5 | import java.util.concurrent.Executors; | |
6 | import java.util.function.Function; | |
7 | import java.util.function.Supplier; | |
8 | import java.util.stream.Collector; | |
9 | import java.util.stream.Stream; | |
10 | ||
11 | import static java.util.Objects.requireNonNull; | |
12 | ||
13 | final class Factory { | |
14 | ||
15 | private Factory() { | |
16 | } | |
17 | ||
18 | static <T, R, C> Collector<T, ?, CompletableFuture<C>> collecting(Function<Stream<R>, C> finalizer, Function<? super T, ? extends R> mapper, Option... options) { | |
19 | requireNonNull(mapper, "mapper can't be null"); | |
20 | ||
21 | var config = Option.process(options); | |
22 | ||
23 | var batching = config.batching().orElse(false); | |
24 | var executor = config.executor().orElseGet(defaultExecutor()); | |
25 | ||
26 |
1
1. collecting : negated conditional → KILLED |
if (config.parallelism().orElse(-1) == 1) { |
27 |
1
1. collecting : replaced return value with null for com/pivovarit/collectors/Factory::collecting → KILLED |
return new AsyncCollector<>(mapper, finalizer, executor); |
28 | } | |
29 | ||
30 |
1
1. collecting : negated conditional → KILLED |
if (batching) { |
31 |
1
1. lambda$collecting$0 : replaced return value with null for com/pivovarit/collectors/Factory::lambda$collecting$0 → NO_COVERAGE |
var parallelism = config.parallelism().orElseThrow(() -> new IllegalArgumentException("it's obligatory to provide parallelism when using batching")); |
32 |
1
1. collecting : replaced return value with null for com/pivovarit/collectors/Factory::collecting → KILLED |
return new AsyncParallelCollector.BatchingCollector<>(mapper, finalizer, executor, parallelism); |
33 | } | |
34 | ||
35 |
2
1. collecting : replaced return value with null for com/pivovarit/collectors/Factory::collecting → KILLED 2. collecting : negated conditional → KILLED |
return config.parallelism().isPresent() |
36 | ? AsyncParallelCollector.from(mapper, finalizer, executor, config.parallelism().getAsInt()) | |
37 | : AsyncParallelCollector.from(mapper, finalizer, executor); | |
38 | } | |
39 | ||
40 | static <T, R> Collector<T, ?, CompletableFuture<Stream<R>>> collecting(Function<? super T, ? extends R> mapper, Option... options) { | |
41 |
1
1. lambda$collecting$1 : replaced return value with Stream.empty for com/pivovarit/collectors/Factory::lambda$collecting$1 → KILLED |
Function<Stream<R>, Stream<R>> finalizer = i -> i; |
42 |
1
1. collecting : replaced return value with null for com/pivovarit/collectors/Factory::collecting → KILLED |
return collecting(finalizer, mapper, options); |
43 | } | |
44 | ||
45 | static <T, R> Collector<T, ?, Stream<R>> streaming(Function<? super T, ? extends R> mapper, boolean ordered, Option... options) { | |
46 | requireNonNull(mapper, "mapper can't be null"); | |
47 | ||
48 | var config = Option.process(options); | |
49 | var batching = config.batching().orElse(false); | |
50 | var executor = config.executor().orElseGet(defaultExecutor()); | |
51 | ||
52 |
1
1. streaming : negated conditional → KILLED |
if (config.parallelism().orElse(-1) == 1) { |
53 |
1
1. streaming : replaced return value with null for com/pivovarit/collectors/Factory::streaming → KILLED |
return new SyncCollector<>(mapper); |
54 | } | |
55 | ||
56 |
1
1. streaming : negated conditional → KILLED |
if (batching) { |
57 |
1
1. lambda$streaming$0 : replaced return value with null for com/pivovarit/collectors/Factory::lambda$streaming$0 → NO_COVERAGE |
var parallelism = config.parallelism().orElseThrow(() -> new IllegalArgumentException("it's obligatory to provide parallelism when using batching")); |
58 |
1
1. streaming : replaced return value with null for com/pivovarit/collectors/Factory::streaming → KILLED |
return new AsyncParallelStreamingCollector.BatchingCollector<>(mapper, executor, parallelism, ordered); |
59 | } | |
60 | ||
61 |
2
1. streaming : replaced return value with null for com/pivovarit/collectors/Factory::streaming → KILLED 2. streaming : negated conditional → KILLED |
return config.parallelism().isPresent() |
62 | ? AsyncParallelStreamingCollector.from(mapper, executor, config.parallelism().getAsInt(), ordered) | |
63 | : AsyncParallelStreamingCollector.from(mapper, executor, ordered); | |
64 | } | |
65 | ||
66 | private static Supplier<Executor> defaultExecutor() { | |
67 |
1
1. defaultExecutor : replaced return value with null for com/pivovarit/collectors/Factory::defaultExecutor → KILLED |
return Executors::newVirtualThreadPerTaskExecutor; |
68 | } | |
69 | } | |
Mutations | ||
26 |
1.1 |
|
27 |
1.1 |
|
30 |
1.1 |
|
31 |
1.1 |
|
32 |
1.1 |
|
35 |
1.1 2.2 |
|
41 |
1.1 |
|
42 |
1.1 |
|
52 |
1.1 |
|
53 |
1.1 |
|
56 |
1.1 |
|
57 |
1.1 |
|
58 |
1.1 |
|
61 |
1.1 2.2 |
|
67 |
1.1 |