refactor(collectors): remove duplicate collector implementations
This commit is contained in:
@@ -1,10 +0,0 @@
|
|||||||
package ru.test.maven.spring;
|
|
||||||
import java.util.stream.Collector;
|
|
||||||
public class MyCollectors
|
|
||||||
{
|
|
||||||
private MyCollectors() {
|
|
||||||
}
|
|
||||||
public static <T> Collector<T, MyList<T>, MyList<T>> toMyList() {
|
|
||||||
return new MyListCollector<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package ru.test.maven.spring;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.function.BinaryOperator;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Collector;
|
|
||||||
public class MyListCollector <T> implements Collector<T, MyList<T>, MyList<T>>
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public Supplier<MyList<T>> supplier()
|
|
||||||
{
|
|
||||||
return () -> new MyLinkedList<>();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public BiConsumer<MyList<T>, T> accumulator() {
|
|
||||||
|
|
||||||
return (list, element) -> list.add(element);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public BinaryOperator<MyList<T>> combiner() {
|
|
||||||
return (list1, list2) -> {
|
|
||||||
for (int i = 0; i < list2.size(); i++) {
|
|
||||||
list1.add(list2.get(i));
|
|
||||||
}
|
|
||||||
return list1;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Function<MyList<T>, MyList<T>> finisher()
|
|
||||||
{
|
|
||||||
return list -> list;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public Set<Collector.Characteristics> characteristics() {
|
|
||||||
return java.util.Set.of(
|
|
||||||
Collector.Characteristics.IDENTITY_FINISH
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user