-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicantDefaultComparator.java
More file actions
60 lines (53 loc) · 1.83 KB
/
ApplicantDefaultComparator.java
File metadata and controls
60 lines (53 loc) · 1.83 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.Comparator;
/**
* <h3>COMP90041, Sem2, 2022: Final Project</h3>
* <p>Class ApplicantDefaultComparator is used to sort applicant based on availabilitty and name
*
* @author Gia Han Ly
*/
public class ApplicantDefaultComparator implements Comparator<Applicant> {
/**
* Return order of two applicants based on
* <p>   Date: If there are ties, break by comparing lastname<br>
* <p>   Lastname: If there are ties, break by comparing firstname<br></p>
* <p> Null date are listed last, with its order based on lastname and firstname if there are ties</p>
*
* @param a - Applicant a
* @param b - Applicant b
* @return int
*/
@Override
public int compare(Applicant a, Applicant b) {
int dateResult;
// If both a and b start date are null, return tie
if (a.getStartDate() == null && b.getStartDate() == null){
dateResult = 0;
}
// If b start date is null
else if (b.getStartDate() == null){
dateResult = -1;
}
// If a start date is null
else if (a.getStartDate() == null){
dateResult = 1;
}
// Other case compare two dates
else {
dateResult = a.getStartDate().compareTo(b.getStartDate());
}
// If there is tie in date, resolve by comparing lastname
if (dateResult == 0){
int lastnameResult = a.getLastname().compareToIgnoreCase(b.getLastname());
// If there is tie in lastname, resolve by comparing first name
if (lastnameResult == 0){
return a.getFirstname().compareToIgnoreCase(b.getFirstname());
}
else {
return lastnameResult;
}
}
else {
return dateResult;
}
}
}