fix for bug 2976: don't compare by number of mark passings but by the index of the current leg

This commit is contained in:
Axel Uhl committed 2015-07-03 13:50:26 +02:00
1 parent 028f3c1a42
commit a37fd177f4
3 files changed
+27 -3

No files matched your search

@@ -2,8 +2,23 @@ package com.sap.sailing.domain.base;
import java.io.Serializable;
public interface Leg extends Serializable {
/**
* When two legs are compared, their natural order is by the index of their {@link #getFrom() start waypoint} in the
* {@link Course} to which they belong. A leg closer to the beginning of the course ranks "less" than one that is closer
* to the end of the course.
*
* @author Axel Uhl (D043530)
*
*/
public interface Leg extends Serializable, Comparable<Leg> {
Waypoint getFrom();
Waypoint getTo();
/**
* The index of this leg's {@link #getFrom() start waypoint} in the sequence of the
* {@link Course}'s {@link Course#getWaypoints waypoints}. The first waypoint in
* the course has index 0.
*/
int getZeroBasedIndexOfStartWaypoint();
}
@@ -28,4 +28,14 @@ public class LegImpl implements Leg {
public String toString() {
return getFrom() + " -> " + getTo();
}
@Override
public int getZeroBasedIndexOfStartWaypoint() {
return indexOfStartWaypoint;
}
@Override
public int compareTo(Leg o) {
return getZeroBasedIndexOfStartWaypoint() - o.getZeroBasedIndexOfStartWaypoint();
}
}
@@ -92,8 +92,7 @@ public abstract class AbstractRaceRankComparator<C extends Comparable<C>> implem
} finally {
trackedRace.unlockAfterRead(o2MarkPassings);
}
result = o2MarkPassingsBeforeTimePointSize - o1MarkPassingsBeforeTimePointSize; // inverted: more legs means
// smaller rank
result = o1Leg == null ? o2Leg == null ? 0 : 1 : o2Leg == null ? -1 : o2Leg.getLeg().compareTo(o1Leg.getLeg()); // don't compare mark passing sizes! bug 2976
if (result == 0 && o1MarkPassingsBeforeTimePointSize > 0) {
// Competitors are on same leg and both have already started the first leg.
// TrackedLegOfCompetitor comparison also correctly uses finish times for a leg