-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentComparator.java
More file actions
41 lines (31 loc) · 1.5 KB
/
StudentComparator.java
File metadata and controls
41 lines (31 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package data;
import java.util.Comparator;
public class StudentComparator {
public StudentComparator() {}
public static Comparator<Student> sortName(boolean ascending) {
return toAscending(Comparator.comparing(Student::getName), ascending);
}
public static Comparator<Student> sortSurname(boolean ascending) {
return toAscending(Comparator.comparing(Student::getSurname), ascending);
}
public static Comparator<Student> sortProgram(boolean ascending) {
return toAscending(Comparator.comparing(Student::getProgramID), ascending);
}
public static Comparator<Student> sortIdentifier(boolean ascending) {
return toAscending(Comparator.comparing(Student::getIdentifier), ascending);
}
public static Comparator<Student> sortMoyenneThenName(boolean ascending) {
return toAscending(Comparator.comparing(Student::moyenne).thenComparing(Student::getName), ascending);
}
public static Comparator<Student> sortCoursNote(String coursID, boolean ascending) {
Comparator<Student> studentComparator = (student1, student2) -> {
double noteS1 = student1.getNoteCours(coursID);
double noteS2 = student2.getNoteCours(coursID);
return Double.compare(noteS1, noteS2);
};
return toAscending(studentComparator, ascending);
}
public static Comparator<Student> toAscending(Comparator<Student> comparator, boolean ascending) {
return ascending ? comparator : comparator.reversed();
}
}