feat: implement composite pattern for student search
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package ru.project.search;
|
||||
|
||||
import ru.project.list.MyList;
|
||||
import ru.project.list.MyLinkedList;
|
||||
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<Student> find(MyList<Student> students) {
|
||||
if (students == null) {
|
||||
return new MyLinkedList<>();
|
||||
}
|
||||
MyList<Student> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user