fixing NoSuchElementException in TrackedRaceImpl.updateStartToNextMarkCacheInvalidationCacheListenersAfterWaypointRemoved for empty course

This commit is contained in:
Axel Uhl committed 2013-11-14 15:26:50 +01:00
1 parent 9c0d011416
commit e2089f4e70
1 file changed
+7 -5
@@ -1626,12 +1626,14 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
clearDirectionFromStartToNextMarkCache();
stopAndRemoveStartToNextMarkCacheInvalidationListener(waypointThatGotRemoved);
Iterator<Waypoint> waypointsIter = getRace().getCourse().getWaypoints().iterator();
waypointsIter.next(); // skip first
if (waypointsIter.hasNext()) {
waypointsIter.next(); // skip second
if (waypointsIter.hasNext()) { // catches the case of a course being empty
waypointsIter.next(); // skip first
if (waypointsIter.hasNext()) {
Waypoint newSecond = waypointsIter.next();
addStartToNextMarkCacheInvalidationListener(newSecond);
waypointsIter.next(); // skip second
if (waypointsIter.hasNext()) {
Waypoint newSecond = waypointsIter.next();
addStartToNextMarkCacheInvalidationListener(newSecond);
}
}
}
}