package ru.project.search; import ru.project.collection.MyLinkedList; import ru.project.collection.MyList; import ru.project.student.Student; public class StudentSearchService { private final StudentSearchCriteria criteria; public StudentSearchService(StudentSearchCriteria criteria) { if (criteria == null) { throw new IllegalArgumentException("Criteria must not be null"); } this.criteria = criteria; } public MyList find(MyList students) { if (students == null) { return new MyLinkedList<>(); } MyList result = new MyLinkedList<>(); for (int i = 0; i < students.size(); i++) { Student s = students.get(i); if (criteria.matches(s)) { result.add(s); } } return result; } }