| 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, Options.CollectingOption... options) { | |
| 19 | requireNonNull(mapper, "mapper can't be null"); | |
| 20 | ||
| 21 | var config = ConfigProcessor.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, Options.CollectingOption... 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, Options.StreamingOption... options) { | |
| 46 | requireNonNull(mapper, "mapper can't be null"); | |
| 47 | ||
| 48 | var config = ConfigProcessor.process(options); | |
| 49 | boolean batching = config.batching().orElse(false); | |
| 50 | boolean ordered = config.ordered().orElse(false); | |
| 51 | var executor = config.executor().orElseGet(defaultExecutor()); | |
| 52 | ||
| 53 |
1
1. streaming : negated conditional → KILLED |
if (config.parallelism().orElse(-1) == 1) { |
| 54 |
1
1. streaming : replaced return value with null for com/pivovarit/collectors/Factory::streaming → KILLED |
return new SyncCollector<>(mapper); |
| 55 | } | |
| 56 | ||
| 57 |
1
1. streaming : negated conditional → KILLED |
if (batching) { |
| 58 |
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")); |
| 59 |
1
1. streaming : replaced return value with null for com/pivovarit/collectors/Factory::streaming → KILLED |
return new AsyncParallelStreamingCollector.BatchingCollector<>(mapper, executor, parallelism, ordered); |
| 60 | } | |
| 61 | ||
| 62 |
2
1. streaming : replaced return value with null for com/pivovarit/collectors/Factory::streaming → KILLED 2. streaming : negated conditional → KILLED |
return config.parallelism().isPresent() |
| 63 | ? AsyncParallelStreamingCollector.from(mapper, executor, config.parallelism().getAsInt(), ordered) | |
| 64 | : AsyncParallelStreamingCollector.from(mapper, executor, ordered); | |
| 65 | } | |
| 66 | ||
| 67 | private static Supplier<Executor> defaultExecutor() { | |
| 68 |
1
1. defaultExecutor : replaced return value with null for com/pivovarit/collectors/Factory::defaultExecutor → KILLED |
return Executors::newVirtualThreadPerTaskExecutor; |
| 69 | } | |
| 70 | } | |
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 |
|
| 53 |
1.1 |
|
| 54 |
1.1 |
|
| 57 |
1.1 |
|
| 58 |
1.1 |
|
| 59 |
1.1 |
|
| 62 |
1.1 2.2 |
|
| 68 |
1.1 |