| 1 | package com.pivovarit.gatherers; | |
| 2 | ||
| 3 | import java.util.HashSet; | |
| 4 | import java.util.Objects; | |
| 5 | import java.util.function.Function; | |
| 6 | import java.util.function.Supplier; | |
| 7 | import java.util.stream.Gatherer; | |
| 8 | ||
| 9 | record DistinctByGatherer<T, U>(Function<? super T, ? extends U> keyExtractor) implements Gatherer<T, HashSet<U>, T> { | |
| 10 | ||
| 11 | DistinctByGatherer { | |
| 12 | Objects.requireNonNull(keyExtractor, "keyExtractor can't be null"); | |
| 13 | } | |
| 14 | ||
| 15 | @Override | |
| 16 | public Supplier<HashSet<U>> initializer() { | |
| 17 |
1
1. initializer : replaced return value with null for com/pivovarit/gatherers/DistinctByGatherer::initializer → KILLED |
return HashSet::new; |
| 18 | } | |
| 19 | ||
| 20 | @Override | |
| 21 | public Integrator<HashSet<U>, T, T> integrator() { | |
| 22 |
1
1. integrator : replaced return value with null for com/pivovarit/gatherers/DistinctByGatherer::integrator → KILLED |
return (state, element, downstream) -> { |
| 23 |
1
1. lambda$integrator$0 : negated conditional → KILLED |
if (state.add(keyExtractor.apply(element))) { |
| 24 |
2
1. lambda$integrator$0 : replaced boolean return with true for com/pivovarit/gatherers/DistinctByGatherer::lambda$integrator$0 → SURVIVED 2. lambda$integrator$0 : replaced boolean return with false for com/pivovarit/gatherers/DistinctByGatherer::lambda$integrator$0 → KILLED |
return downstream.push(element); |
| 25 | } | |
| 26 |
1
1. lambda$integrator$0 : replaced boolean return with false for com/pivovarit/gatherers/DistinctByGatherer::lambda$integrator$0 → KILLED |
return true; |
| 27 | }; | |
| 28 | } | |
| 29 | } | |
Mutations | ||
| 17 |
1.1 |
|
| 22 |
1.1 |
|
| 23 |
1.1 |
|
| 24 |
1.1 2.2 |
|
| 26 |
1.1 |