mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 11:23:50 +00:00
fixed wind comparator so it can deal with null positions
This commit is contained in:
1 parent
c325407e53
commit
f14da4404e
1 file changed
+15
-4
+15
-4
@@ -21,12 +21,23 @@ public class WindComparator implements Comparator<Timed> {
|
||||
int result = o1.getTimePoint().compareTo(o2.getTimePoint());
|
||||
if (result == 0) {
|
||||
if (o1 instanceof Wind && o2 instanceof Wind) {
|
||||
// try to decide based on position; note that position may be null
|
||||
Wind o1Wind = (Wind) o1;
|
||||
Wind o2Wind = (Wind) o2;
|
||||
// use the coordinates as secondary criteria:
|
||||
result = Double.compare(o1Wind.getPosition().getLatDeg(), o2Wind.getPosition().getLatDeg());
|
||||
if (result == 0) {
|
||||
result = Double.compare(o1Wind.getPosition().getLngDeg(), o2Wind.getPosition().getLngDeg());
|
||||
if (o1Wind.getPosition() == null) {
|
||||
if (o2Wind.getPosition() != null) {
|
||||
result = -1;
|
||||
} // else both are null and 0 is already the correct answer
|
||||
} else {
|
||||
if (o2Wind.getPosition() == null) {
|
||||
result = 1;
|
||||
} else {
|
||||
// use the coordinates as secondary criteria:
|
||||
result = Double.compare(o1Wind.getPosition().getLatDeg(), o2Wind.getPosition().getLatDeg());
|
||||
if (result == 0) {
|
||||
result = Double.compare(o1Wind.getPosition().getLngDeg(), o2Wind.getPosition().getLngDeg());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user