Fixed Util.Pair

This commit is contained in:
Nicolas committed 2014-06-05 21:41:15 +02:00
1 parent 53b6c6d5b7
commit 7d079f143c
10 files changed
+67 -71

No files matched your search

@@ -228,7 +228,7 @@ public abstract class AbstractMarkPassingTest extends OnlineTracTracBasedTest {
} finally {
getTrackedRace().getTrack(c).unlockAfterRead();
}
Pair<Iterable<Candidate>, Iterable<Candidate>> f = finder.getCandidateDeltas(c, fixes);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> f = finder.getCandidateDeltas(c, fixes);
chooser.calculateMarkPassDeltas(c, f.getA(), f.getB());
boolean gotPassed = true;
boolean gotOther = false;
@@ -68,8 +68,8 @@ public class AbstractMockedRaceMarkPassingTest {
race = new DynamicTrackedRaceImpl(new TrackedRegattaImpl(r), raceDef, new ArrayList<Sideline>(), new EmptyWindStore(), EmptyGPSFixStore.INSTANCE, 0, 10000, 10000);
race.setStartTimeReceived(new MillisecondsTimePoint(10000));
TimePoint t = new MillisecondsTimePoint(30000);
List<Pair<Mark, Position>> pos = Arrays.asList(new Pair<Mark, Position>(m, new DegreePosition(0, 0)),
new Pair<Mark, Position>(gate1, new DegreePosition(-0.001, -0.00005)), new Pair<Mark, Position>(gate2, new DegreePosition(-0.001, 0.00005)), new Pair<Mark, Position>(reaching, new DegreePosition(-0.0005, -0.0005)));
List<Util.Pair<Mark, Position>> pos = Arrays.asList(new Util.Pair<Mark, Position>(m, new DegreePosition(0, 0)),
new Util.Pair<Mark, Position>(gate1, new DegreePosition(-0.001, -0.00005)), new Util.Pair<Mark, Position>(gate2, new DegreePosition(-0.001, 0.00005)), new Util.Pair<Mark, Position>(reaching, new DegreePosition(-0.0005, -0.0005)));
for (Util.Pair<Mark, Position> pair : pos) {
race.recordFix(pair.getA(), new GPSFixImpl(pair.getB(), t));
}
@@ -19,7 +19,6 @@ import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
import com.sap.sailing.domain.common.impl.DegreePosition;
import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl;
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.domain.markpassingcalculation.Candidate;
import com.sap.sailing.domain.markpassingcalculation.CandidateFinder;
import com.sap.sailing.domain.markpassingcalculation.impl.CandidateChooserImpl;
@@ -31,6 +30,7 @@ import com.sap.sailing.domain.test.measurements.MeasurementXMLFile;
import com.sap.sailing.domain.tracking.GPSFix;
import com.sap.sailing.domain.tracking.GPSFixMoving;
import com.sap.sailing.domain.tracking.impl.GPSFixMovingImpl;
import com.sap.sse.common.Util;
public class MarkPassingCalculatorPerformanceTest extends AbstractMockedRaceMarkPassingTest {
@@ -97,7 +97,7 @@ public class MarkPassingCalculatorPerformanceTest extends AbstractMockedRaceMark
private CandidateImpl randomCan() {
int id = rnd.nextInt(3);
return new CandidateImpl(id + 1, new MillisecondsTimePoint((long) (rnd.nextDouble() * 200000)),
0.5 + 0.5 * rnd.nextDouble(), Util.get(race.getRace().getCourse().getWaypoints(), id));
0.5 + 0.5 * rnd.nextDouble(), Util.get(race.getRace().getCourse().getWaypoints(), id));
}
private GPSFixMoving rndFix() {
@@ -18,8 +18,6 @@ import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
import com.sap.sailing.domain.common.impl.DegreePosition;
import com.sap.sailing.domain.common.impl.KnotSpeedWithBearingImpl;
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.domain.markpassingcalculation.Candidate;
import com.sap.sailing.domain.markpassingcalculation.CandidateChooser;
import com.sap.sailing.domain.markpassingcalculation.CandidateFinder;
@@ -30,6 +28,7 @@ import com.sap.sailing.domain.tracking.GPSFix;
import com.sap.sailing.domain.tracking.GPSFixMoving;
import com.sap.sailing.domain.tracking.MarkPassing;
import com.sap.sailing.domain.tracking.impl.GPSFixMovingImpl;
import com.sap.sse.common.Util;
/**
* Tests tricky situation that can fail easily. Created with help of http://itouchmap.com/latlong.html
@@ -54,7 +53,7 @@ public class MarkPassingWhiteBoxTest extends AbstractMockedRaceMarkPassingTest {
List<GPSFix> fixes = new ArrayList<GPSFix>();
fixes.add(fix1);
fixes.add(fix2);
Pair<Iterable<Candidate>, Iterable<Candidate>> candidateDeltas = finder.getCandidateDeltas(ron, fixes);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> candidateDeltas = finder.getCandidateDeltas(ron, fixes);
assertEquals(0, Util.size(candidateDeltas.getA()));
race.recordFix(ron, fix3);
@@ -86,7 +85,7 @@ public class MarkPassingWhiteBoxTest extends AbstractMockedRaceMarkPassingTest {
List<GPSFix> fixes = new ArrayList<>();
fixes.add(fix1);
fixes.add(fix3);
Pair<Iterable<Candidate>, Iterable<Candidate>> cans = finder.getCandidateDeltas(tom, fixes);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> cans = finder.getCandidateDeltas(tom, fixes);
assertEquals(Util.size(cans.getA()), 0);
assertEquals(Util.size(cans.getB()), 0);
@@ -116,7 +115,7 @@ public class MarkPassingWhiteBoxTest extends AbstractMockedRaceMarkPassingTest {
race.recordFix(tom, fix2);
List<GPSFix> fixes = new ArrayList<>();
fixes.addAll(Arrays.asList(fix1, fix2));
Pair<Iterable<Candidate>, Iterable<Candidate>> cans = finder.getCandidateDeltas(tom, fixes);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> cans = finder.getCandidateDeltas(tom, fixes);
Double inFront = cans.getA().iterator().next().getProbability();
assertTrue(Util.size(cans.getA()) == 1);
// Passing of one mark, close but wrong side and direction
@@ -184,7 +183,7 @@ public class MarkPassingWhiteBoxTest extends AbstractMockedRaceMarkPassingTest {
race.recordFix(ben, fix3);
List<GPSFix> fixes = new ArrayList<>();
fixes.addAll(Arrays.asList(fix1, fix2, fix3));
Pair<Iterable<Candidate>, Iterable<Candidate>> cans = finder.getCandidateDeltas(ben, fixes);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> cans = finder.getCandidateDeltas(ben, fixes);
Candidate inFront = Util.get(cans.getA(), 0);
race.recordFix(ben, fix4);
race.recordFix(ben, fix5);
@@ -261,33 +260,33 @@ public class MarkPassingWhiteBoxTest extends AbstractMockedRaceMarkPassingTest {
Course course = race.getRace().getCourse();
// Before adding
Pair<Iterable<Candidate>, Iterable<Candidate>> allCandidatesBefore = finder.getAllCandidates(ron);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> allCandidatesBefore = finder.getAllCandidates(ron);
assertEquals(Util.size(allCandidatesBefore.getB()), 0);
assertEquals(Util.size(allCandidatesBefore.getA()), 0);
// The process of adding
course.addWaypoint(4, newWaypoint);
Pair<List<Candidate>, List<Candidate>> addedCans = finder.updateWaypoints(Arrays.asList(newWaypoint), new ArrayList<Waypoint>(), 4).get(ron);
Util.Pair<List<Candidate>, List<Candidate>> addedCans = finder.updateWaypoints(Arrays.asList(newWaypoint), new ArrayList<Waypoint>(), 4).get(ron);
assertEquals(Util.size(addedCans.getA()), 1);
for (Candidate c : addedCans.getA()) {
assertEquals(c.getWaypoint(), newWaypoint);
}
// Before removing
Pair<Iterable<Candidate>, Iterable<Candidate>> allCandidatesInBetween = finder.getAllCandidates(ron);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> allCandidatesInBetween = finder.getAllCandidates(ron);
assertEquals(Util.size(allCandidatesInBetween.getA()), 1);
assertEquals(Util.size(allCandidatesInBetween.getB()), 0);
// The Process of removing
course.removeWaypoint(4);
Pair<List<Candidate>, List<Candidate>> removedCans = finder.updateWaypoints(new ArrayList<Waypoint>(), Arrays.asList(newWaypoint), 4).get(ron);
Util.Pair<List<Candidate>, List<Candidate>> removedCans = finder.updateWaypoints(new ArrayList<Waypoint>(), Arrays.asList(newWaypoint), 4).get(ron);
assertEquals(Util.size(removedCans.getB()), 1);
for (Candidate c : removedCans.getB()) {
assertEquals(c.getWaypoint(), newWaypoint);
}
// After removing
Pair<Iterable<Candidate>, Iterable<Candidate>> allCansAfterRemoving = finder.getAllCandidates(ron);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> allCansAfterRemoving = finder.getAllCandidates(ron);
assertEquals(Util.size(allCansAfterRemoving.getB()), 0);
assertEquals(Util.size(allCansAfterRemoving.getA()), 0);
}
@@ -8,7 +8,6 @@ import com.sap.sailing.domain.tracking.DynamicTrackedRace;
import com.sap.sailing.domain.tracking.MarkPassing;
public interface CandidateChooser {
import com.sap.sse.common.Util;
/**
* Calculates any new {@link MarkPassing}s and notifies the {@link DynamicTrackedRace}.
@@ -27,14 +27,14 @@ public interface CandidateFinder {
* fixes.
* @return new {@link Candidate}s and those that should be removed.
*/
Pair<Iterable<Candidate>, Iterable<Candidate>> getCandidateDeltas(Competitor c, Iterable<GPSFix> fixes);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> getCandidateDeltas(Competitor c, Iterable<GPSFix> fixes);
/**
* When initializing or refreshing the calculator, the whole race until now is evaluated. For that purpose all of the
* {@link Candidate}s are needed instead of just the deltas.
*/
Pair<Iterable<Candidate>, Iterable<Candidate>> getAllCandidates(Competitor c);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> getAllCandidates(Competitor c);
Map<Competitor, Pair<List<Candidate>, List<Candidate>>> updateWaypoints(Iterable<Waypoint> addedWaypoints, Iterable<Waypoint> removedWaypoints, Integer smallestIndex);
Map<Competitor, Util.Pair<List<Candidate>, List<Candidate>>> updateWaypoints(Iterable<Waypoint> addedWaypoints, Iterable<Waypoint> removedWaypoints, Integer smallestIndex);
}
@@ -67,7 +67,7 @@ public class MarkPassingCalculator {
finder = new CandidateFinderImpl(race);
chooser = new CandidateChooserImpl(race);
for (Competitor c : race.getRace().getCompetitors()) {
Pair<Iterable<Candidate>, Iterable<Candidate>> allCandidates = finder.getAllCandidates(c);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> allCandidates = finder.getAllCandidates(c);
chooser.calculateMarkPassDeltas(c, allCandidates.getA(), allCandidates.getB());
}
if (listen) {
@@ -115,12 +115,12 @@ public class MarkPassingCalculator {
if (!suspended) {
// TODO Interplay between changing waypoints and setting fixed passes?
if (smallestChangedWaypointIndex != null) {
Map<Competitor, Pair<List<Candidate>, List<Candidate>>> candidateDeltas = finder
Map<Competitor, Util.Pair<List<Candidate>, List<Candidate>>> candidateDeltas = finder
.updateWaypoints(addedWaypoints, removedWaypoints, smallestChangedWaypointIndex);
chooser.removeWaypoints(removedWaypoints);
for (Entry<Competitor, Pair<List<Candidate>, List<Candidate>>> entry : candidateDeltas
for (Entry<Competitor, Util.Pair<List<Candidate>, List<Candidate>>> entry : candidateDeltas
.entrySet()) {
Pair<List<Candidate>, List<Candidate>> pair = entry.getValue();
Util.Pair<List<Candidate>, List<Candidate>> pair = entry.getValue();
chooser.calculateMarkPassDeltas(entry.getKey(), pair.getA(), pair.getB());
}
}
@@ -209,7 +209,7 @@ public class MarkPassingCalculator {
@Override
public void run() {
logger.finest("Calculating MarkPassings for " + c);
Pair<Iterable<Candidate>, Iterable<Candidate>> candidateDeltas = finder.getCandidateDeltas(c, fixes);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> candidateDeltas = finder.getCandidateDeltas(c, fixes);
chooser.calculateMarkPassDeltas(c, candidateDeltas.getA(), candidateDeltas.getB());
}
}
@@ -261,7 +261,7 @@ public class MarkPassingCalculator {
finder = new CandidateFinderImpl(race);
chooser = new CandidateChooserImpl(race);
for (Competitor c : race.getRace().getCompetitors()) {
Pair<Iterable<Candidate>, Iterable<Candidate>> allCandidates = finder.getAllCandidates(c);
Util.Pair<Iterable<Candidate>, Iterable<Candidate>> allCandidates = finder.getAllCandidates(c);
chooser.calculateMarkPassDeltas(c, allCandidates.getA(), allCandidates.getB());
}
}
@@ -15,7 +15,6 @@ import com.sap.sailing.domain.tracking.GPSFixMoving;
import com.sap.sailing.domain.tracking.MarkPassing;
import com.sap.sailing.domain.tracking.TrackedRace;
import com.sap.sailing.domain.tracking.impl.AbstractRaceChangeListener;
import com.sap.sse.common.Util;
/**
* Listens for changes that might affect the MarkPassingCalculator: new Fixes of a Competitor or a Mark and when the
@@ -20,13 +20,13 @@ import com.sap.sailing.domain.common.Distance;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.impl.MeterDistance;
import com.sap.sailing.domain.common.impl.MillisecondsTimePoint;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.domain.markpassingcalculation.Candidate;
import com.sap.sailing.domain.markpassingcalculation.CandidateChooser;
import com.sap.sailing.domain.tracking.DynamicTrackedRace;
import com.sap.sailing.domain.tracking.MarkPassing;
import com.sap.sailing.domain.tracking.TrackedLeg;
import com.sap.sailing.domain.tracking.impl.MarkPassingImpl;
import com.sap.sse.common.Util;
/**
* The standard implementation of {@link CandidateChooser}. A graph is created, with each {@link Candidate} as a
@@ -221,26 +221,26 @@ public class CandidateChooserImpl implements CandidateChooser {
if (oneBasedIndexOfSuppressedWaypoint >= endOfFixedInterval.getOneBasedIndexOfWaypoint()) {
endOfFixedInterval = end;
}
NavigableSet<Pair<Edge, Double>> currentEdgesCheapestFirst = new TreeSet<>(new Comparator<Pair<Edge, Double>>() {
NavigableSet<Util.Pair<Edge, Double>> currentEdgesCheapestFirst = new TreeSet<>(new Comparator<Util.Pair<Edge, Double>>() {
@Override
public int compare(Pair<Edge, Double> o1, Pair<Edge, Double> o2) {
public int compare(Util.Pair<Edge, Double> o1, Util.Pair<Edge, Double> o2) {
int result = o1.getB().compareTo(o2.getB());
return result != 0 ? result : o1.getA().compareTo(o2.getA());
}
});
Map<Candidate, Pair<Candidate, Double>> candidateWithParentAndSmallestTotalCost = new HashMap<>();
Map<Candidate, Util.Pair<Candidate, Double>> candidateWithParentAndSmallestTotalCost = new HashMap<>();
int indexOfEndOfFixedInterval = endOfFixedInterval.getOneBasedIndexOfWaypoint();
boolean endFound = false;
currentEdgesCheapestFirst.add(new Pair<Edge, Double>(new Edge(new CandidateImpl(-1, null, 1, null), startOfFixedInterval, 0,
currentEdgesCheapestFirst.add(new Util.Pair<Edge, Double>(new Edge(new CandidateImpl(-1, null, 1, null), startOfFixedInterval, 0,
race.getRace().getCourse()), 0.0));
while (!endFound) {
Pair<Edge, Double> cheapestEdgeWithCost = currentEdgesCheapestFirst.pollFirst();
Util.Pair<Edge, Double> cheapestEdgeWithCost = currentEdgesCheapestFirst.pollFirst();
Edge currentCheapestEdge = cheapestEdgeWithCost.getA();
Double currentCheapestCost = cheapestEdgeWithCost.getB();
// If the shortest path to this candidate is already known the new edge is not added.
if (!candidateWithParentAndSmallestTotalCost.containsKey(currentCheapestEdge.getEnd())) {
candidateWithParentAndSmallestTotalCost.put(currentCheapestEdge.getEnd(), new Pair<Candidate, Double>(
candidateWithParentAndSmallestTotalCost.put(currentCheapestEdge.getEnd(), new Util.Pair<Candidate, Double>(
currentCheapestEdge.getStart(), currentCheapestCost));
endFound = currentCheapestEdge.getEnd() == endOfFixedInterval;
if (!endFound) {
@@ -249,7 +249,7 @@ public class CandidateChooserImpl implements CandidateChooser {
int oneBasedIndexOFEndOfEdge = e.getEnd().getOneBasedIndexOfWaypoint();
if (oneBasedIndexOFEndOfEdge <= indexOfEndOfFixedInterval
&& (oneBasedIndexOFEndOfEdge < oneBasedIndexOfSuppressedWaypoint || e.getEnd() == end)) {
currentEdgesCheapestFirst.add(new Pair<Edge, Double>(e, currentCheapestCost + e.getCost()));
currentEdgesCheapestFirst.add(new Util.Pair<Edge, Double>(e, currentCheapestCost + e.getCost()));
}
}
}
@@ -26,8 +26,6 @@ import com.sap.sailing.domain.common.Position;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
import com.sap.sailing.domain.common.impl.MeterDistance;
import com.sap.sailing.domain.common.impl.Util;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.domain.markpassingcalculation.Candidate;
import com.sap.sailing.domain.markpassingcalculation.CandidateFinder;
import com.sap.sailing.domain.tracking.DynamicGPSFixTrack;
@@ -35,6 +33,7 @@ import com.sap.sailing.domain.tracking.DynamicTrackedRace;
import com.sap.sailing.domain.tracking.GPSFix;
import com.sap.sailing.domain.tracking.GPSFixMoving;
import com.sap.sailing.domain.tracking.GPSFixTrack;
import com.sap.sse.common.Util;
/**
* The standard implemantation of {@link CandidateFinder}. There are two kinds of {@link Candidate}s. First of all,
@@ -106,7 +105,7 @@ public class CandidateFinderImpl implements CandidateFinder {
}
@Override
public Pair<Iterable<Candidate>, Iterable<Candidate>> getAllCandidates(Competitor c) {
public Util.Pair<Iterable<Candidate>, Iterable<Candidate>> getAllCandidates(Competitor c) {
Set<GPSFix> fixes = getAllFixes(c);
distanceCache.get(c).clear();
xteCache.get(c).clear();
@@ -121,7 +120,7 @@ public class CandidateFinderImpl implements CandidateFinder {
public Map<Competitor, List<GPSFix>> calculateFixesAffectedByNewMarkFixes(Mark mark, Iterable<GPSFix> markFixes) {
Map<Competitor, List<GPSFix>> affectedFixes = new HashMap<>();
for (GPSFix fix : markFixes) {
Pair<TimePoint, TimePoint> timePoints = race.getOrCreateTrack(mark)
Util.Pair<TimePoint, TimePoint> timePoints = race.getOrCreateTrack(mark)
.getEstimatedPositionTimePeriodAffectedBy(fix);
for (Competitor c : race.getRace().getCompetitors()) {
List<GPSFix> comFixes = new ArrayList<>();
@@ -147,13 +146,13 @@ public class CandidateFinderImpl implements CandidateFinder {
}
@Override
public Pair<Iterable<Candidate>, Iterable<Candidate>> getCandidateDeltas(Competitor c, Iterable<GPSFix> fixes) {
public Util.Pair<Iterable<Candidate>, Iterable<Candidate>> getCandidateDeltas(Competitor c, Iterable<GPSFix> fixes) {
List<Candidate> newCans = new ArrayList<>();
List<Candidate> wrongCans = new ArrayList<>();
Pair<List<Candidate>, List<Candidate>> distanceCandidates = checkForDistanceCandidateChanges(c, fixes, race
Util.Pair<List<Candidate>, List<Candidate>> distanceCandidates = checkForDistanceCandidateChanges(c, fixes, race
.getRace().getCourse().getWaypoints());
Pair<List<Candidate>, List<Candidate>> xteCandidates = checkForXTECandidatesChanges(c, fixes, race.getRace()
Util.Pair<List<Candidate>, List<Candidate>> xteCandidates = checkForXTECandidatesChanges(c, fixes, race.getRace()
.getCourse().getWaypoints());
newCans.addAll(xteCandidates.getA());
newCans.addAll(distanceCandidates.getA());
@@ -166,11 +165,11 @@ public class CandidateFinderImpl implements CandidateFinder {
* if (c.getName().equals("ChinaSpirit")) { System.out.println("Number Of Fixes: " + Util.size(fixes));
* System.out.println("Number Of Calculations: " + xteCalculationCounter); }
*/
return new Pair<Iterable<Candidate>, Iterable<Candidate>>(newCans, wrongCans);
return new Util.Pair<Iterable<Candidate>, Iterable<Candidate>>(newCans, wrongCans);
}
private Map<Competitor, Pair<List<Candidate>, List<Candidate>>> invalidateAfterCourseChange(int indexOfChange) {
Map<Competitor, Pair<List<Candidate>, List<Candidate>>> result = new HashMap<>();
private Map<Competitor, Util.Pair<List<Candidate>, List<Candidate>>> invalidateAfterCourseChange(int indexOfChange) {
Map<Competitor, Util.Pair<List<Candidate>, List<Candidate>>> result = new HashMap<>();
Course course = race.getRace().getCourse();
for (Competitor c : race.getRace().getCompetitors()) {
distanceCache.get(c).clear();
@@ -197,20 +196,20 @@ public class CandidateFinderImpl implements CandidateFinder {
Set<GPSFix> allFixes = getAllFixes(c);
newCans.addAll(checkForDistanceCandidateChanges(c, allFixes, changedWaypoints).getA());
newCans.addAll(checkForXTECandidatesChanges(c, allFixes, changedWaypoints).getA());
result.put(c, new Pair<List<Candidate>, List<Candidate>>(newCans, badCans));
result.put(c, new Util.Pair<List<Candidate>, List<Candidate>>(newCans, badCans));
}
return result;
}
@Override
public Map<Competitor, Pair<List<Candidate>, List<Candidate>>> updateWaypoints(Iterable<Waypoint> addedWaypoints,
public Map<Competitor, Util.Pair<List<Candidate>, List<Candidate>>> updateWaypoints(Iterable<Waypoint> addedWaypoints,
Iterable<Waypoint> removedWaypoints, Integer smallestIndex) {
Course course = race.getRace().getCourse();
for (Waypoint w : addedWaypoints) {
processNewWaypoint(w, course.getFirstWaypoint(), course.getLastWaypoint());
}
Map<Competitor, List<Candidate>> removedWaypointCandidates = removeWaypoints(removedWaypoints);
Map<Competitor, Pair<List<Candidate>, List<Candidate>>> newAndUpdatedCandidates = invalidateAfterCourseChange(smallestIndex);
Map<Competitor, Util.Pair<List<Candidate>, List<Candidate>>> newAndUpdatedCandidates = invalidateAfterCourseChange(smallestIndex);
for (Entry<Competitor, List<Candidate>> entry : removedWaypointCandidates.entrySet()) {
newAndUpdatedCandidates.get(entry.getKey()).getB().addAll(entry.getValue());
}
@@ -284,9 +283,9 @@ public class CandidateFinderImpl implements CandidateFinder {
/**
* For each fix the distance to each waypoint is calculated. Then the fix is checked for being a candidate.
*/
private Pair<List<Candidate>, List<Candidate>> checkForDistanceCandidateChanges(Competitor c,
private Util.Pair<List<Candidate>, List<Candidate>> checkForDistanceCandidateChanges(Competitor c,
Iterable<GPSFix> fixes, Iterable<Waypoint> waypoints) {
Pair<List<Candidate>, List<Candidate>> result = new Pair<List<Candidate>, List<Candidate>>(
Util.Pair<List<Candidate>, List<Candidate>> result = new Util.Pair<List<Candidate>, List<Candidate>>(
new ArrayList<Candidate>(), new ArrayList<Candidate>());
TreeSet<GPSFix> affectedFixes = new TreeSet<GPSFix>(comp);
GPSFixTrack<Competitor, GPSFixMoving> track = race.getTrack(c);
@@ -425,14 +424,14 @@ public class CandidateFinderImpl implements CandidateFinder {
*/
/**
* For each fix the cross-track error(s) to each waypoint are calculated. Then all pairs of fixes are checked for
* For each fix the cross-track error(s) to each waypoint are calculated. Then all Util.Pairs of fixes are checked for
* being a candidate.
*
* @param waypointAsList
*/
private Pair<List<Candidate>, List<Candidate>> checkForXTECandidatesChanges(Competitor c, Iterable<GPSFix> fixes,
private Util.Pair<List<Candidate>, List<Candidate>> checkForXTECandidatesChanges(Competitor c, Iterable<GPSFix> fixes,
Iterable<Waypoint> waypoints) {
Pair<List<Candidate>, List<Candidate>> result = new Pair<List<Candidate>, List<Candidate>>(
Util.Pair<List<Candidate>, List<Candidate>> result = new Util.Pair<List<Candidate>, List<Candidate>>(
new ArrayList<Candidate>(), new ArrayList<Candidate>());
for (GPSFix fix : fixes) {
TimePoint t = fix.getTimePoint();
@@ -554,7 +553,7 @@ public class CandidateFinderImpl implements CandidateFinder {
for (Waypoint w : passingInstructions.keySet()) {
List<Distance> distances = new ArrayList<>();
result.put(w, distances);
for (Pair<Position, Bearing> crossingInfo : getCrossingInformation(w, t)) {
for (Util.Pair<Position, Bearing> crossingInfo : getCrossingInformation(w, t)) {
distances.add(p.crossTrackError(crossingInfo.getA(), crossingInfo.getB()));
}
}
@@ -572,7 +571,7 @@ public class CandidateFinderImpl implements CandidateFinder {
* waypointsToCalculate) { for (GPSFix fix : fixes) { Position fixPos = fix.getPosition(); TimePoint t =
* fix.getTimePoint(); Map<Waypoint, List<Double>> waypointXTE = new HashMap<Waypoint, List<Double>>();
* crossTrackErrors.get(c).put(fix, waypointXTE); for (Waypoint w : race.getRace().getCourse().getWaypoints()) {
* List<Double> xte = new ArrayList<>(); waypointXTE.put(w, xte); for (Pair<Position, Bearing> crossingInfo :
* List<Double> xte = new ArrayList<>(); waypointXTE.put(w, xte); for (Util.Pair<Position, Bearing> crossingInfo :
* getCrossingInformation(w, t)) { xte.add(fixPos.crossTrackError(crossingInfo.getA(),
* crossingInfo.getB()).getMeters()); } } } }
*/
@@ -623,11 +622,11 @@ public class CandidateFinderImpl implements CandidateFinder {
m = w.getMarks().iterator().next();
}
if (instruction == PassingInstruction.Gate) {
Pair<Mark, Mark> pair = getPortAndStarboardMarks(t, w);
Util.Pair<Mark, Mark> pair = getPortAndStarboardMarks(t, w);
m = portMark ? pair.getA() : pair.getB();
}
if (m != null) {
Pair<Position, Bearing> crossingInfo = Util.get(getCrossingInformation(w, t), portMark ? 0 : 1);
Util.Pair<Position, Bearing> crossingInfo = Util.get(getCrossingInformation(w, t), portMark ? 0 : 1);
result = p.crossTrackError(crossingInfo.getA(), crossingInfo.getB().add(new DegreeBearingImpl(90)))
.getMeters() < 0;
}
@@ -704,7 +703,7 @@ public class CandidateFinderImpl implements CandidateFinder {
singleMark = true;
break;
case Gate:
Pair<Mark, Mark> posGate = getPortAndStarboardMarks(t, w);
Util.Pair<Mark, Mark> posGate = getPortAndStarboardMarks(t, w);
Position portGatePosition = posGate.getA() == null ? null : race.getOrCreateTrack(posGate.getA())
.getEstimatedPosition(t, false);
Position starboardGatePosition = posGate.getB() == null ? null : race.getOrCreateTrack(posGate.getB())
@@ -714,7 +713,7 @@ public class CandidateFinderImpl implements CandidateFinder {
break;
case Line:
Pair<Mark, Mark> posLine = getPortAndStarboardMarks(t, w);
Util.Pair<Mark, Mark> posLine = getPortAndStarboardMarks(t, w);
Position portLinePosition = race.getOrCreateTrack(posLine.getA()).getEstimatedPosition(t, false);
Position starboardLinePosition = race.getOrCreateTrack(posLine.getB()).getEstimatedPosition(t, false);
distances.add((portLinePosition != null && starboardLinePosition != null) ? p.getDistanceToLine(
@@ -742,11 +741,11 @@ public class CandidateFinderImpl implements CandidateFinder {
* @return all possible ways to pass a waypoint, described as a position and a bearing. The line out of those two
* muss be crossed.
*/
private Iterable<Pair<Position, Bearing>> getCrossingInformation(Waypoint w, TimePoint t) {
List<Pair<Position, Bearing>> result = new ArrayList<>();
private Iterable<Util.Pair<Position, Bearing>> getCrossingInformation(Waypoint w, TimePoint t) {
List<Util.Pair<Position, Bearing>> result = new ArrayList<>();
PassingInstruction instruction = passingInstructions.get(w);
if (instruction == PassingInstruction.Line) {
Pair<Mark, Mark> marks = getPortAndStarboardMarks(t, w);
Util.Pair<Mark, Mark> marks = getPortAndStarboardMarks(t, w);
Position portPosition = null;
Bearing b = null;
Mark portMark = marks.getA();
@@ -758,24 +757,24 @@ public class CandidateFinderImpl implements CandidateFinder {
b = portPosition.getBearingGreatCircle(starboardPosition);
}
}
result.add(new Pair<Position, Bearing>(portPosition, b));
result.add(new Util.Pair<Position, Bearing>(portPosition, b));
} else if (instruction == PassingInstruction.Gate) {
Position before = race.getApproximatePosition(race.getTrackedLegFinishingAt(w).getLeg().getFrom(), t);
Position after = race.getApproximatePosition(race.getTrackedLegStartingAt(w).getLeg().getTo(), t);
Pair<Mark, Mark> pos = getPortAndStarboardMarks(t, w);
Util.Pair<Mark, Mark> pos = getPortAndStarboardMarks(t, w);
Mark portMark = pos.getA();
if (portMark != null) {
Position portPosition = race.getOrCreateTrack(portMark).getEstimatedPosition(t, false);
Bearing crossingPort = before.getBearingGreatCircle(portPosition).middle(
after.getBearingGreatCircle(portPosition));
result.add(new Pair<Position, Bearing>(portPosition, crossingPort));
result.add(new Util.Pair<Position, Bearing>(portPosition, crossingPort));
}
Mark starboardMark = pos.getB();
if (starboardMark != null) {
Position starboardPosition = race.getOrCreateTrack(starboardMark).getEstimatedPosition(t, false);
Bearing crossingStarboard = before.getBearingGreatCircle(starboardPosition).middle(
after.getBearingGreatCircle(starboardPosition));
result.add(new Pair<Position, Bearing>(starboardPosition, crossingStarboard));
result.add(new Util.Pair<Position, Bearing>(starboardPosition, crossingStarboard));
}
} else {
Bearing b = null;
@@ -790,7 +789,7 @@ public class CandidateFinderImpl implements CandidateFinder {
}
}
p = race.getOrCreateTrack(w.getMarks().iterator().next()).getEstimatedPosition(t, false);
result.add(new Pair<Position, Bearing>(p, b));
result.add(new Util.Pair<Position, Bearing>(p, b));
}
return result;
}
@@ -799,13 +798,13 @@ public class CandidateFinderImpl implements CandidateFinder {
* @return the marks of a waypoint with two marks in the order port, starboard (when approching the waypoint from
* the direction of the waypoint beforehand.
*/
private Pair<Mark, Mark> getPortAndStarboardMarks(TimePoint t, Waypoint w) {
private Util.Pair<Mark, Mark> getPortAndStarboardMarks(TimePoint t, Waypoint w) {
List<Position> markPositions = new ArrayList<Position>();
for (Mark mark : w.getMarks()) {
final Position estimatedMarkPosition = race.getOrCreateTrack(mark).getEstimatedPosition(t, /* extrapolate */
false);
if (estimatedMarkPosition == null) {
return new Pair<Mark, Mark>(null, null);
return new Util.Pair<Mark, Mark>(null, null);
}
markPositions.add(estimatedMarkPosition);
}
@@ -815,7 +814,7 @@ public class CandidateFinderImpl implements CandidateFinder {
final Bearing legDeterminingDirectionBearing = race.getTrackedLeg(
legs.get(isStartLine ? 0 : indexOfWaypoint - 1)).getLegBearing(t);
if (legDeterminingDirectionBearing == null) {
return new Pair<Mark, Mark>(null, null);
return new Util.Pair<Mark, Mark>(null, null);
}
Distance crossTrackErrorOfMark0OnLineFromMark1ToNextWaypoint = markPositions.get(0).crossTrackError(
markPositions.get(1), legDeterminingDirectionBearing);
@@ -828,7 +827,7 @@ public class CandidateFinderImpl implements CandidateFinder {
portMarkWhileApproachingLine = Util.get(w.getMarks(), 1);
starboardMarkWhileApproachingLine = Util.get(w.getMarks(), 0);
}
return new Pair<Mark, Mark>(portMarkWhileApproachingLine, starboardMarkWhileApproachingLine);
return new Util.Pair<Mark, Mark>(portMarkWhileApproachingLine, starboardMarkWhileApproachingLine);
}
}