-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventComparator.java
More file actions
36 lines (29 loc) · 884 Bytes
/
EventComparator.java
File metadata and controls
36 lines (29 loc) · 884 Bytes
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
import java.util.Comparator;
class EventComparator implements Comparator<Event> {
private static final double threshold = 1E-15;
public int compare(Event p1, Event p2) {
Event e1 = p1;
Event e2 = p2;
if (equals(e1.getTime(), e2.getTime())) {
return Integer.valueOf(e1.getCustomer().toString()) -
Integer.valueOf(e2.getCustomer().toString());
}
return moreThan(e1.getTime(), e2.getTime());
}
int moreThan(double t1, double t2) {
if (Math.abs(t1 - t2) < threshold) {
return 0;
} else if (t1 - t2 < threshold) {
return -1;
} else {
return 1;
}
}
boolean equals(double t1, double t2) {
if (Math.abs(t1 - t2) < threshold) {
return true;
} else {
return false;
}
}
}