From 850705b263da8658ec98428d9319bc394d553940 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Thu, 1 Mar 2012 17:39:31 +0100 Subject: [PATCH] the fix for bug 360 introduced a NoSuchElementException; added check for empty collection --- .../domain/tracking/impl/RaceRankComparator.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java index 833d78f59f0..346cd03d226 100755 --- a/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java +++ b/java/com.sap.sailing.domain/src/com/sap/sailing/domain/tracking/impl/RaceRankComparator.java @@ -45,25 +45,29 @@ public class RaceRankComparator implements Comparator { } else { NavigableSet o1MarkPassings = trackedRace.getMarkPassings(o1); NavigableSet o1MarkPassingsBeforeTimePoint; - MarkPassing o1LastMarkPassingBeforeTimePoint; + MarkPassing o1LastMarkPassingBeforeTimePoint = null; int o1MarkPassingsBeforeTimePointSize; TrackedLegOfCompetitor o1Leg; synchronized (o1MarkPassings) { o1MarkPassingsBeforeTimePoint = o1MarkPassings.headSet( markPassingWithTimePoint, /* inclusive */true); - o1LastMarkPassingBeforeTimePoint = o1MarkPassingsBeforeTimePoint.last(); o1MarkPassingsBeforeTimePointSize = o1MarkPassingsBeforeTimePoint.size(); + if (o1MarkPassingsBeforeTimePointSize > 0) { + o1LastMarkPassingBeforeTimePoint = o1MarkPassingsBeforeTimePoint.last(); + } o1Leg = trackedRace.getCurrentLeg(o1, timePoint); } NavigableSet o2MarkPassings = trackedRace.getMarkPassings(o2); NavigableSet o2MarkPassingsBeforeTimePoint; - MarkPassing o2LastMarkPassingBeforeTimePoint; + MarkPassing o2LastMarkPassingBeforeTimePoint = null; int o2MarkPassingsBeforeTimePointSize; TrackedLegOfCompetitor o2Leg; synchronized (o2MarkPassings) { o2MarkPassingsBeforeTimePoint = o2MarkPassings.headSet(markPassingWithTimePoint, /* inclusive */true); - o2LastMarkPassingBeforeTimePoint = o2MarkPassingsBeforeTimePoint.last(); o2MarkPassingsBeforeTimePointSize = o2MarkPassingsBeforeTimePoint.size(); + if (o2MarkPassingsBeforeTimePointSize > 0) { + o2LastMarkPassingBeforeTimePoint = o2MarkPassingsBeforeTimePoint.last(); + } o2Leg = trackedRace.getCurrentLeg(o2, timePoint); } result = o2MarkPassingsBeforeTimePointSize - o1MarkPassingsBeforeTimePointSize; // inverted: more legs means