| 1 | /* | |
| 2 | * Copyright 2014-2026 Grzegorz Piwowarek, https://4comprehension.com/ | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package com.pivovarit.collectors; | |
| 17 | ||
| 18 | import java.util.LinkedHashMap; | |
| 19 | import java.util.Objects; | |
| 20 | import java.util.concurrent.CompletableFuture; | |
| 21 | import java.util.concurrent.Executor; | |
| 22 | import java.util.function.Consumer; | |
| 23 | import java.util.function.Function; | |
| 24 | import java.util.stream.Collector; | |
| 25 | import java.util.stream.Collectors; | |
| 26 | import java.util.stream.Stream; | |
| 27 | ||
| 28 | import static java.util.Objects.requireNonNull; | |
| 29 | ||
| 30 | final class Factory { | |
| 31 | ||
| 32 | private Factory() { | |
| 33 | } | |
| 34 | ||
| 35 | static <T, K, R> Collector<T, ?, CompletableFuture<Stream<Group<K, R>>>> collectingBy( | |
| 36 | Function<? super T, ? extends K> classifier, | |
| 37 | Function<? super T, ? extends R> mapper, | |
| 38 | Consumer<CollectingConfigurer> configurer) { | |
| 39 |
2
1. collectingBy : replaced return value with null for com/pivovarit/collectors/Factory::collectingBy → KILLED 2. lambda$collectingBy$0 : replaced return value with Stream.empty for com/pivovarit/collectors/Factory::lambda$collectingBy$0 → KILLED |
return Factory.collectingBy(classifier, (Function<Stream<Group<K, R>>, Stream<Group<K, R>>>) i -> i, mapper, configurer); |
| 40 | } | |
| 41 | ||
| 42 | static <T, K, R, C> Collector<T, ?, CompletableFuture<C>> collectingBy( | |
| 43 | Function<? super T, ? extends K> classifier, | |
| 44 | Function<Stream<Group<K, R>>, C> finalizer, | |
| 45 | Function<? super T, ? extends R> mapper, | |
| 46 | Consumer<CollectingConfigurer> configurer) { | |
| 47 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 48 | Objects.requireNonNull(finalizer, "finalizer cannot be null"); | |
| 49 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 50 | Objects.requireNonNull(configurer, "configurer cannot be null"); | |
| 51 | ||
| 52 | var config = ConfigProcessor.process(collecting(configurer).getConfig()); | |
| 53 | ||
| 54 |
1
1. collectingBy : replaced return value with null for com/pivovarit/collectors/Factory::collectingBy → KILLED |
return Collectors.collectingAndThen( |
| 55 | Collectors.groupingBy(classifier, LinkedHashMap::new, Collectors.toList()), | |
| 56 | groups -> groups.entrySet() | |
| 57 | .stream() | |
| 58 |
1
1. lambda$collectingBy$1 : replaced return value with null for com/pivovarit/collectors/Factory::lambda$collectingBy$1 → KILLED |
.collect(collecting(finalizer, |
| 59 |
1
1. lambda$collectingBy$2 : replaced return value with null for com/pivovarit/collectors/Factory::lambda$collectingBy$2 → KILLED |
e -> new Group<>(e.getKey(), e.getValue().stream() |
| 60 |
1
1. lambda$collectingBy$3 : replaced return value with null for com/pivovarit/collectors/Factory::lambda$collectingBy$3 → KILLED |
.map(mapper.andThen(a -> (R) a)) |
| 61 | .toList()), config)) | |
| 62 | ); | |
| 63 | } | |
| 64 | ||
| 65 | static <T, R, C> Collector<T, ?, CompletableFuture<C>> collecting( | |
| 66 | Function<Stream<R>, C> finalizer, | |
| 67 | Function<? super T, ? extends R> mapper, | |
| 68 | Consumer<CollectingConfigurer> configurer | |
| 69 | ) { | |
| 70 | requireNonNull(mapper, "mapper cannot be null"); | |
| 71 | requireNonNull(configurer, "configurer cannot be null"); | |
| 72 | ||
| 73 |
1
1. collecting : replaced return value with null for com/pivovarit/collectors/Factory::collecting → KILLED |
return collecting(finalizer, mapper, ConfigProcessor.process(collecting(configurer).getConfig())); |
| 74 | } | |
| 75 | ||
| 76 | private static <T, R, C> Collector<T, ?, CompletableFuture<C>> collecting( | |
| 77 | Function<Stream<R>, C> finalizer, | |
| 78 | Function<? super T, ? extends R> mapper, | |
| 79 | ConfigProcessor.Config config | |
| 80 | ) { | |
| 81 |
1
1. collecting : replaced return value with null for com/pivovarit/collectors/Factory::collecting → KILLED |
return select(mapper, config, new ModeFactory<T, R, CompletableFuture<C>>() { |
| 82 | @Override | |
| 83 | public Collector<T, ?, CompletableFuture<C>> async(Function<? super T, ? extends R> mapper, Executor executor) { | |
| 84 |
1
1. async : replaced return value with null for com/pivovarit/collectors/Factory$1::async → KILLED |
return new AsyncCollector<>(mapper, finalizer, executor); |
| 85 | } | |
| 86 | ||
| 87 | @Override | |
| 88 | public Collector<T, ?, CompletableFuture<C>> batching(Function<? super T, ? extends R> mapper, Executor executor, int parallelism) { | |
| 89 |
1
1. batching : replaced return value with null for com/pivovarit/collectors/Factory$1::batching → KILLED |
return new AsyncParallelCollector.BatchingCollector<>(mapper, finalizer, executor, parallelism); |
| 90 | } | |
| 91 | ||
| 92 | @Override | |
| 93 | public Collector<T, ?, CompletableFuture<C>> parallel(Function<? super T, ? extends R> mapper, Dispatcher<R> dispatcher) { | |
| 94 |
1
1. parallel : replaced return value with null for com/pivovarit/collectors/Factory$1::parallel → KILLED |
return new AsyncParallelCollector<>(mapper, dispatcher, finalizer); |
| 95 | } | |
| 96 | }); | |
| 97 | } | |
| 98 | ||
| 99 | static <T, K, R> Collector<T, ?, Stream<Group<K, R>>> streamingBy( | |
| 100 | Function<? super T, ? extends K> classifier, | |
| 101 | Function<? super T, ? extends R> mapper, | |
| 102 | Consumer<StreamingConfigurer> configurer) { | |
| 103 | Objects.requireNonNull(classifier, "classifier cannot be null"); | |
| 104 | Objects.requireNonNull(mapper, "mapper cannot be null"); | |
| 105 | Objects.requireNonNull(configurer, "configurer cannot be null"); | |
| 106 | ||
| 107 | var config = ConfigProcessor.process(streaming(configurer).getConfig()); | |
| 108 | ||
| 109 |
1
1. streamingBy : replaced return value with null for com/pivovarit/collectors/Factory::streamingBy → KILLED |
return Collectors.collectingAndThen( |
| 110 | Collectors.groupingBy(classifier, LinkedHashMap::new, Collectors.toList()), | |
| 111 | groups -> groups.entrySet() | |
| 112 | .stream() | |
| 113 |
2
1. lambda$streamingBy$1 : replaced return value with null for com/pivovarit/collectors/Factory::lambda$streamingBy$1 → KILLED 2. lambda$streamingBy$0 : replaced return value with Stream.empty for com/pivovarit/collectors/Factory::lambda$streamingBy$0 → KILLED |
.collect(streaming(e -> new Group<>(e.getKey(), e.getValue().stream() |
| 114 |
1
1. lambda$streamingBy$2 : replaced return value with null for com/pivovarit/collectors/Factory::lambda$streamingBy$2 → KILLED |
.map(mapper.andThen(a -> (R) a)) |
| 115 | .toList()), config)) | |
| 116 | ); | |
| 117 | } | |
| 118 | ||
| 119 | static <T, R> Collector<T, ?, Stream<R>> streaming( | |
| 120 | Function<? super T, ? extends R> mapper, | |
| 121 | Consumer<StreamingConfigurer> configurer) { | |
| 122 | requireNonNull(mapper, "mapper cannot be null"); | |
| 123 | requireNonNull(configurer, "configurer cannot be null"); | |
| 124 | ||
| 125 |
1
1. streaming : replaced return value with null for com/pivovarit/collectors/Factory::streaming → KILLED |
return streaming(mapper, ConfigProcessor.process(streaming(configurer).getConfig())); |
| 126 | } | |
| 127 | ||
| 128 | private static <T, R> Collector<T, ?, Stream<R>> streaming( | |
| 129 | Function<? super T, ? extends R> mapper, | |
| 130 | ConfigProcessor.Config config) { | |
| 131 |
1
1. streaming : replaced return value with null for com/pivovarit/collectors/Factory::streaming → KILLED |
return select(mapper, config, new ModeFactory<T, R, Stream<R>>() { |
| 132 | @Override | |
| 133 | public Collector<T, ?, Stream<R>> async(Function<? super T, ? extends R> m, Executor ex) { | |
| 134 |
1
1. async : replaced return value with null for com/pivovarit/collectors/Factory$2::async → KILLED |
return new SyncCollector<>(m); |
| 135 | } | |
| 136 | ||
| 137 | @Override | |
| 138 | public Collector<T, ?, Stream<R>> batching(Function<? super T, ? extends R> m, Executor ex, int p) { | |
| 139 |
1
1. batching : replaced return value with null for com/pivovarit/collectors/Factory$2::batching → KILLED |
return new AsyncParallelStreamingCollector.BatchingCollector<>(m, ex, p, config.ordered(), config.timeout()); |
| 140 | } | |
| 141 | ||
| 142 | @Override | |
| 143 | public Collector<T, ?, Stream<R>> parallel(Function<? super T, ? extends R> m, Dispatcher<R> d) { | |
| 144 |
1
1. parallel : replaced return value with null for com/pivovarit/collectors/Factory$2::parallel → KILLED |
return new AsyncParallelStreamingCollector<>(m, d, config.ordered(), config.timeout()); |
| 145 | } | |
| 146 | }); | |
| 147 | } | |
| 148 | ||
| 149 | private static <T, R, C> Collector<T, ?, C> select( | |
| 150 | Function<? super T, ? extends R> mapper, | |
| 151 | ConfigProcessor.Config config, | |
| 152 | ModeFactory<T, R, C> factory | |
| 153 | ) { | |
| 154 |
1
1. select : negated conditional → KILLED |
if (config.parallelism() == 1) { |
| 155 |
1
1. select : replaced return value with null for com/pivovarit/collectors/Factory::select → KILLED |
return factory.async(mapper, config.executor()); |
| 156 | } | |
| 157 | ||
| 158 |
1
1. select : negated conditional → KILLED |
if (config.batching()) { |
| 159 |
1
1. select : replaced return value with null for com/pivovarit/collectors/Factory::select → KILLED |
return factory.batching(mapper, config.executor(), config.parallelism()); |
| 160 | } | |
| 161 | ||
| 162 |
2
1. select : negated conditional → TIMED_OUT 2. select : changed conditional boundary → TIMED_OUT |
var dispatcher = (config.parallelism() > 0) |
| 163 | ? new Dispatcher<R>(config.executor(), config.parallelism()) | |
| 164 | : new Dispatcher<R>(config.executor()); | |
| 165 | ||
| 166 |
1
1. select : replaced return value with null for com/pivovarit/collectors/Factory::select → KILLED |
return factory.parallel(mapper, dispatcher); |
| 167 | } | |
| 168 | ||
| 169 | interface ModeFactory<T, R, C> { | |
| 170 | Collector<T, ?, C> async(Function<? super T, ? extends R> mapper, Executor executor); | |
| 171 | ||
| 172 | Collector<T, ?, C> batching(Function<? super T, ? extends R> mapper, Executor executor, int parallelism); | |
| 173 | ||
| 174 | Collector<T, ?, C> parallel(Function<? super T, ? extends R> mapper, Dispatcher<R> dispatcher); | |
| 175 | } | |
| 176 | ||
| 177 | static StreamingConfigurer streaming(Consumer<StreamingConfigurer> consumer) { | |
| 178 | var c = new StreamingConfigurer(); | |
| 179 |
1
1. streaming : removed call to java/util/function/Consumer::accept → KILLED |
consumer.accept(c); |
| 180 |
1
1. streaming : removed call to com/pivovarit/collectors/StreamingConfigurer::validate → KILLED |
c.validate(); |
| 181 |
1
1. streaming : replaced return value with null for com/pivovarit/collectors/Factory::streaming → KILLED |
return c; |
| 182 | } | |
| 183 | ||
| 184 | static CollectingConfigurer collecting(Consumer<CollectingConfigurer> consumer) { | |
| 185 | var c = new CollectingConfigurer(); | |
| 186 |
1
1. collecting : removed call to java/util/function/Consumer::accept → KILLED |
consumer.accept(c); |
| 187 |
1
1. collecting : removed call to com/pivovarit/collectors/CollectingConfigurer::validate → KILLED |
c.validate(); |
| 188 |
1
1. collecting : replaced return value with null for com/pivovarit/collectors/Factory::collecting → KILLED |
return c; |
| 189 | } | |
| 190 | } | |
Mutations | ||
| 39 |
1.1 2.2 |
|
| 54 |
1.1 |
|
| 58 |
1.1 |
|
| 59 |
1.1 |
|
| 60 |
1.1 |
|
| 73 |
1.1 |
|
| 81 |
1.1 |
|
| 84 |
1.1 |
|
| 89 |
1.1 |
|
| 94 |
1.1 |
|
| 109 |
1.1 |
|
| 113 |
1.1 2.2 |
|
| 114 |
1.1 |
|
| 125 |
1.1 |
|
| 131 |
1.1 |
|
| 134 |
1.1 |
|
| 139 |
1.1 |
|
| 144 |
1.1 |
|
| 154 |
1.1 |
|
| 155 |
1.1 |
|
| 158 |
1.1 |
|
| 159 |
1.1 |
|
| 162 |
1.1 2.2 |
|
| 166 |
1.1 |
|
| 179 |
1.1 |
|
| 180 |
1.1 |
|
| 181 |
1.1 |
|
| 186 |
1.1 |
|
| 187 |
1.1 |
|
| 188 |
1.1 |