GroupingByGatherer.java

1
package com.pivovarit.gatherers;
2
3
import java.util.HashMap;
4
import java.util.Map;
5
import java.util.Objects;
6
import java.util.function.BiConsumer;
7
import java.util.function.Function;
8
import java.util.function.Supplier;
9
import java.util.stream.Collector;
10
import java.util.stream.Gatherer;
11
import java.util.stream.Stream;
12
13
record GroupingByGatherer<T, K, R>(Function<? super T, ? extends K> classifier,
14
                                   Collector<? super T, ?, ? extends R> collector)
15
  implements Gatherer<T, HashMap<K, Stream.Builder<T>>, Map.Entry<K, R>> {
16
17
    GroupingByGatherer {
18
        Objects.requireNonNull(classifier, "classifier can't be null");
19
        Objects.requireNonNull(collector, "collector can't be null");
20
    }
21
22
    @Override
23
    public Supplier<HashMap<K, Stream.Builder<T>>> initializer() {
24 1 1. initializer : replaced return value with null for com/pivovarit/gatherers/GroupingByGatherer::initializer → KILLED
        return HashMap::new;
25
    }
26
27
    @Override
28
    public Integrator<HashMap<K, Stream.Builder<T>>, T, Map.Entry<K, R>> integrator() {
29 1 1. integrator : replaced return value with null for com/pivovarit/gatherers/GroupingByGatherer::integrator → KILLED
        return Integrator.ofGreedy((state, element, _) -> {
30 2 1. lambda$integrator$1 : removed call to java/util/stream/Stream$Builder::accept → KILLED
2. lambda$integrator$0 : replaced return value with null for com/pivovarit/gatherers/GroupingByGatherer::lambda$integrator$0 → KILLED
            state.computeIfAbsent(classifier.apply(element), _ -> Stream.builder()).accept(element);
31 1 1. lambda$integrator$1 : replaced boolean return with false for com/pivovarit/gatherers/GroupingByGatherer::lambda$integrator$1 → SURVIVED
            return true;
32
        });
33
    }
34
35
    @Override
36
    public BiConsumer<HashMap<K, Stream.Builder<T>>, Downstream<? super Map.Entry<K, R>>> finisher() {
37 2 1. lambda$finisher$3 : removed call to java/util/HashMap::forEach → KILLED
2. finisher : replaced return value with null for com/pivovarit/gatherers/GroupingByGatherer::finisher → KILLED
        return (map, downstream) -> map.forEach((key, builder) -> downstream.push(Map.entry(key, builder.build()
38
          .collect(collector))));
39
    }
40
}

Mutations

24

1.1
Location : initializer
Killed by : com.pivovarit.gatherers.blackbox.GroupingByGathererTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.GroupingByGathererTest]/[method:shouldGroupEmptyWithCustomCollector()]
replaced return value with null for com/pivovarit/gatherers/GroupingByGatherer::initializer → KILLED

29

1.1
Location : integrator
Killed by : com.pivovarit.gatherers.blackbox.GroupingByGathererTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.GroupingByGathererTest]/[method:shouldGroupToList()]
replaced return value with null for com/pivovarit/gatherers/GroupingByGatherer::integrator → KILLED

30

1.1
Location : lambda$integrator$1
Killed by : com.pivovarit.gatherers.blackbox.GroupingByGathererTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.GroupingByGathererTest]/[method:shouldGroupToList()]
removed call to java/util/stream/Stream$Builder::accept → KILLED

2.2
Location : lambda$integrator$0
Killed by : com.pivovarit.gatherers.blackbox.GroupingByGathererTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.GroupingByGathererTest]/[method:shouldGroupToList()]
replaced return value with null for com/pivovarit/gatherers/GroupingByGatherer::lambda$integrator$0 → KILLED

31

1.1
Location : lambda$integrator$1
Killed by : none
replaced boolean return with false for com/pivovarit/gatherers/GroupingByGatherer::lambda$integrator$1 → SURVIVED
Covering tests

37

1.1
Location : lambda$finisher$3
Killed by : com.pivovarit.gatherers.blackbox.GroupingByGathererTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.GroupingByGathererTest]/[method:shouldGroupToList()]
removed call to java/util/HashMap::forEach → KILLED

2.2
Location : finisher
Killed by : com.pivovarit.gatherers.blackbox.GroupingByGathererTest.[engine:junit-jupiter]/[class:com.pivovarit.gatherers.blackbox.GroupingByGathererTest]/[method:shouldGroupEmptyWithCustomCollector()]
replaced return value with null for com/pivovarit/gatherers/GroupingByGatherer::finisher → KILLED

Active mutators

Tests examined


Report generated by PIT 1.18.0