refactor: reorganize collection utilities and search imports

This commit is contained in:
2026-08-31 17:58:15 +04:00
parent b8f28830f7
commit a59d574c67
4 changed files with 165 additions and 163 deletions
@@ -1,15 +1,12 @@
package ru.project.collectors;
import java.util.stream.Collector;
import ru.project.collection.MyList;
public class MyCollectors
{
private MyCollectors() {
public class MyCollectors {
private MyCollectors() {}
}
public static <T> Collector<T, MyList<T>, MyList<T>> toMyList()
{
public static <T> Collector<T, MyList<T>, MyList<T>> toMyList() {
return new MyListCollector<>();
}
}
@@ -1,16 +1,17 @@
package ru.project.collectors;
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>>
{
import ru.project.collection.MyLinkedList;
import ru.project.collection.MyList;
public class MyListCollector<T> implements Collector<T, MyList<T>, MyList<T>> {
@Override
public Supplier<MyList<T>> supplier()
{
public Supplier<MyList<T>> supplier() {
return () -> new MyLinkedList<>();
}
@@ -29,15 +30,12 @@ public class MyListCollector <T> implements Collector<T, MyList<T>, MyList<T>>
}
@Override
public Function<MyList<T>, MyList<T>> finisher()
{
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
);
return java.util.Set.of(Collector.Characteristics.IDENTITY_FINISH);
}
}
@@ -1,9 +1,13 @@
package ru.project.finder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class StudentOccurrenceIndexFinder
{
import ru.project.collection.MyLinkedList;
import ru.project.collection.MyList;
import ru.project.student.Student;
public class StudentOccurrenceIndexFinder {
public int[] findOccurrences(MyList<Student> students, Student target) {
if (students == null) {
throw new IllegalArgumentException();
@@ -32,7 +36,9 @@ public class StudentOccurrenceIndexFinder
final int start = fromIndex;
final int end = toIndex;
Future<MyList<Integer>> future = executor.submit(() -> {
Future<MyList<Integer>> future =
executor.submit(
() -> {
return findInRange(students, target, start, end);
});
futures.add(future);
@@ -110,7 +116,8 @@ public class StudentOccurrenceIndexFinder
return (size + threadCount - 1) / threadCount;
}
private MyList<Integer> findInRange(MyList<Student> students, Student target, int fromIndex, int toIndex) {
private MyList<Integer> findInRange(
MyList<Student> students, Student target, int fromIndex, int toIndex) {
MyList<Integer> foundIndices = new MyLinkedList<>();
for (int i = fromIndex; i < toIndex; i++) {
@@ -1,7 +1,7 @@
package ru.project.search;
import ru.project.list.MyList;
import ru.project.list.MyLinkedList;
import ru.project.collection.MyLinkedList;
import ru.project.collection.MyList;
import ru.project.student.Student;
public class StudentSearchService {