mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-27 14:27:15 +00:00
fixed comparator for mark passings structures: when mark passings for a single competitors are to be managed,
only the time shall be considered, and a comparison with a mark passing that has equal time shall result in 0. Only collections with mark passings from different competitors need to resolve by competitor in case times are equal.
This commit is contained in:
1 parent
9c49a504b4
commit
52d9dc176e
4 files changed
+49
-23
No files matched your search
+1
@@ -71,6 +71,7 @@ public abstract class AbstractRaceRankComparator<C extends Comparable<C>> implem
|
||||
TrackedLegOfCompetitor o1Leg;
|
||||
trackedRace.lockForRead(o1MarkPassings);
|
||||
try {
|
||||
// FIXME for the XMLExportTest.testExportingESSNice2014 the "inclusive" parameter doesn't seem to work properly; problem is caused by the MarkPassingByTimeComparator falling back to competitor ID if times are equal
|
||||
o1MarkPassingsBeforeTimePoint = o1MarkPassings.headSet(
|
||||
markPassingWithTimePoint, /* inclusive */true);
|
||||
o1MarkPassingsBeforeTimePointSize = o1MarkPassingsBeforeTimePoint.size();
|
||||
|
||||
+10
-21
@@ -6,35 +6,24 @@ import java.util.Comparator;
|
||||
import com.sap.sailing.domain.tracking.MarkPassing;
|
||||
|
||||
/**
|
||||
* Compares two {@link MarkPassing} objects, using their {@link MarkPassing#getTimePoint() time point} as the primary
|
||||
* ordering criterion in ascending order. If two mark passings have equal time points, the competitor IDs' string
|
||||
* representations are compared as the secondary ordering criterion to ensure that two competitors passing a mark at the
|
||||
* same time are still identified as not being equal.
|
||||
* Compares two {@link MarkPassing} objects, using their {@link MarkPassing#getTimePoint() time point} as the only
|
||||
* ordering criterion in ascending order. If two mark passings have equal time points, they are considered equal,
|
||||
* regardless the competitor. Don't use this comparator for collections in which mark passings for multiple competitors
|
||||
* may be managed and shall be treated as different. Use {@link MarkPassingsByTimeAndCompetitorIdComparator} instead.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
*/
|
||||
public class MarkPassingByTimeComparator implements Comparator<MarkPassing>, Serializable {
|
||||
private static final long serialVersionUID = 5758820139503482888L;
|
||||
public static MarkPassingByTimeComparator INSTANCE = new MarkPassingByTimeComparator();
|
||||
public static final MarkPassingByTimeComparator INSTANCE = new MarkPassingByTimeComparator();
|
||||
|
||||
@Override
|
||||
public int compare(MarkPassing o1, MarkPassing o2) {
|
||||
int result = o1 == null ? o2 == null ? 0 : -1 : o2 == null ? 1 : o1.getTimePoint() == null ? (o2.getTimePoint() == null ? 0 : -1) : o2.getTimePoint() == null ? 1 : o1.getTimePoint().compareTo(o2.getTimePoint());
|
||||
if (result == 0 && o1 != null) {
|
||||
assert o2 != null;
|
||||
Object c1ID = o1.getCompetitor().getId();
|
||||
Object c2ID = o2.getCompetitor().getId();
|
||||
// shortcut comparison and don't use expensive toString() in case IDs are comparable by nature
|
||||
if (c1ID instanceof Comparable<?> && c1ID.getClass() == c2ID.getClass()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Comparable<Object> c1OID = (Comparable<Object>) c1ID;
|
||||
result = c1OID.compareTo(o2.getCompetitor().getId());
|
||||
} else {
|
||||
result = o1.getCompetitor().getId().toString().compareTo(o2.getCompetitor().getId().toString());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return o1 == null ?
|
||||
o2 == null ? 0 : -1
|
||||
: o2 == null ? 1 : o1.getTimePoint() == null ?
|
||||
(o2.getTimePoint() == null ? 0 : -1)
|
||||
: o2.getTimePoint() == null ? 1 : o1.getTimePoint().compareTo(o2.getTimePoint());
|
||||
}
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.sap.sailing.domain.tracking.impl;
|
||||
|
||||
import com.sap.sailing.domain.tracking.MarkPassing;
|
||||
|
||||
/**
|
||||
* Compares two {@link MarkPassing} objects, using their {@link MarkPassing#getTimePoint() time point} as the primary
|
||||
* ordering criterion in ascending order. If two mark passings have equal time points, the competitor IDs' string
|
||||
* representations are compared as the secondary ordering criterion to ensure that two competitors passing a mark at the
|
||||
* same time are still identified as not being equal.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
*/
|
||||
public class MarkPassingsByTimeAndCompetitorIdComparator extends MarkPassingByTimeComparator {
|
||||
private static final long serialVersionUID = 5977491869367296660L;
|
||||
public static final MarkPassingsByTimeAndCompetitorIdComparator INSTANCE = new MarkPassingsByTimeAndCompetitorIdComparator();
|
||||
|
||||
@Override
|
||||
public int compare(MarkPassing o1, MarkPassing o2) {
|
||||
int result = super.compare(o1, o2);
|
||||
if (result == 0 && o1 != null) {
|
||||
assert o2 != null;
|
||||
Object c1ID = o1.getCompetitor().getId();
|
||||
Object c2ID = o2.getCompetitor().getId();
|
||||
// shortcut comparison and don't use expensive toString() in case IDs are comparable by nature
|
||||
if (c1ID instanceof Comparable<?> && c1ID.getClass() == c2ID.getClass()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
final Comparable<Object> c1OID = (Comparable<Object>) c1ID;
|
||||
result = c1OID.compareTo(o2.getCompetitor().getId());
|
||||
} else {
|
||||
result = o1.getCompetitor().getId().toString().compareTo(o2.getCompetitor().getId().toString());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -452,7 +452,7 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
|
||||
markPassingsForWaypoint = new ConcurrentHashMap<Waypoint, NavigableSet<MarkPassing>>();
|
||||
for (Waypoint waypoint : race.getCourse().getWaypoints()) {
|
||||
markPassingsForWaypoint.put(waypoint, new ConcurrentSkipListSet<MarkPassing>(
|
||||
MarkPassingByTimeComparator.INSTANCE));
|
||||
MarkPassingsByTimeAndCompetitorIdComparator.INSTANCE));
|
||||
}
|
||||
markPassingsTimes = new ArrayList<com.sap.sse.common.Util.Pair<Waypoint, com.sap.sse.common.Util.Pair<TimePoint, TimePoint>>>();
|
||||
loadingFromWindStoreState = LoadingFromStoresState.NOT_STARTED;
|
||||
@@ -697,7 +697,7 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
|
||||
|
||||
protected NavigableSet<MarkPassing> createMarkPassingsCollectionForWaypoint(Waypoint waypoint) {
|
||||
final ConcurrentSkipListSet<MarkPassing> result = new ConcurrentSkipListSet<MarkPassing>(
|
||||
MarkPassingByTimeComparator.INSTANCE);
|
||||
MarkPassingsByTimeAndCompetitorIdComparator.INSTANCE);
|
||||
LockUtil.lockForRead(getSerializationLock());
|
||||
try {
|
||||
markPassingsForWaypoint.put(waypoint, result);
|
||||
|
||||
Reference in new issue
Block a user