1 | package com.pivovarit.gatherers; | |
2 | ||
3 | import java.util.LinkedHashMap; | |
4 | import java.util.Objects; | |
5 | import java.util.function.BiConsumer; | |
6 | import java.util.function.Function; | |
7 | import java.util.function.Supplier; | |
8 | import java.util.stream.Gatherer; | |
9 | ||
10 | record DistinctByKeepLastGatherer<T, U>( | |
11 | Function<? super T, ? extends U> keyExtractor) implements Gatherer<T, LinkedHashMap<U, T>, T> { | |
12 | ||
13 | DistinctByKeepLastGatherer { | |
14 | Objects.requireNonNull(keyExtractor, "keyExtractor can't be null"); | |
15 | } | |
16 | ||
17 | @Override | |
18 | public Supplier<LinkedHashMap<U, T>> initializer() { | |
19 |
1
1. initializer : replaced return value with null for com/pivovarit/gatherers/DistinctByKeepLastGatherer::initializer → KILLED |
return LinkedHashMap::new; |
20 | } | |
21 | ||
22 | @Override | |
23 | public Integrator<LinkedHashMap<U, T>, T, T> integrator() { | |
24 |
1
1. integrator : replaced return value with null for com/pivovarit/gatherers/DistinctByKeepLastGatherer::integrator → KILLED |
return Integrator.ofGreedy((state, element, _) -> { |
25 | state.put(keyExtractor.apply(element), element); | |
26 |
1
1. lambda$integrator$0 : replaced boolean return with false for com/pivovarit/gatherers/DistinctByKeepLastGatherer::lambda$integrator$0 → SURVIVED |
return true; |
27 | }); | |
28 | } | |
29 | ||
30 | @Override | |
31 | public BiConsumer<LinkedHashMap<U, T>, Downstream<? super T>> finisher() { | |
32 |
1
1. finisher : replaced return value with null for com/pivovarit/gatherers/DistinctByKeepLastGatherer::finisher → KILLED |
return (state, downstream) -> { |
33 | for (T element : state.values()) { | |
34 | downstream.push(element); | |
35 | } | |
36 | }; | |
37 | } | |
38 | } | |
Mutations | ||
19 |
1.1 |
|
24 |
1.1 |
|
26 |
1.1 |
|
32 |
1.1 |