TracTrac: instantiate single marks before two-mark control points for better handling with virtual marks

Change-Id: I0c47f3234d45c646271f76f3f494018ac6c1bf33
This commit is contained in:
Axel Uhl committed 2017-08-23 15:04:53 +02:00
1 parent a571da9101
commit 9174656b12
3 files changed
+26

No files matched your search

@@ -17,11 +17,13 @@ import com.sap.sailing.domain.tracking.TrackedRegatta;
import com.sap.sailing.domain.tractracadapter.DomainFactory;
import com.sap.sailing.domain.tractracadapter.LoadingQueueDoneCallBack;
import com.sap.sailing.domain.tractracadapter.Receiver;
import com.sap.sailing.domain.tractracadapter.TracTracControlPoint;
import com.sap.sse.common.Duration;
import com.sap.sse.common.Util;
import com.sap.sse.common.Util.Triple;
import com.tractrac.model.lib.api.event.IEvent;
import com.tractrac.model.lib.api.event.IRace;
import com.tractrac.model.lib.api.route.IControl;
import com.tractrac.subscription.lib.api.IEventSubscriber;
import com.tractrac.subscription.lib.api.IRaceSubscriber;
@@ -250,4 +252,14 @@ public abstract class AbstractReceiverWithQueue<A, B, C> implements Runnable, Re
}
}
}
protected void ensureAllSingleMarksOfCourseAreaAreCreated(final IRace tractracRace) {
for (final IControl tractracControlPoint : getDomainFactory().getControlsForCourseArea(getTracTracEvent(),
tractracRace.getCourseArea())) {
if (!tractracControlPoint.isMultiple()) {
final TracTracControlPoint ttcp = new ControlPointAdapter(tractracControlPoint);
getDomainFactory().getOrCreateControlPoint(ttcp);
}
}
}
}
@@ -43,6 +43,15 @@ public class MarkPositionReceiver extends AbstractReceiverWithQueue<IControl, IP
private final IRace tractracRace;
final IControlPointPositionListener listener;
/**
* In order to establish single marks by their native names in case they are also
* part of gates or lines as virtual marks, it's a good idea to ensure their {@link Mark}
* domain objects are created before the gates / lines create theirs. However, this must
* not happen upon each mark position received. Therefore, we do this once per receiver
* and remember having done so in this flag.
*/
private boolean singleMarksEnsuredAlready;
public MarkPositionReceiver(final DynamicTrackedRegatta trackedRegatta, IEvent tractracEvent,
IRace tractracRace, Simulator simulator, final DomainFactory domainFactory, IEventSubscriber eventSubscriber,
IRaceSubscriber raceSubscriber, long timeoutInMilliseconds) {
@@ -79,6 +88,10 @@ public class MarkPositionReceiver extends AbstractReceiverWithQueue<IControl, IP
System.out.println();
}
}
if (!singleMarksEnsuredAlready) {
singleMarksEnsuredAlready = true;
ensureAllSingleMarksOfCourseAreaAreCreated(tractracRace);
}
Mark mark = getDomainFactory().getMark(new ControlPointAdapter(event.getA()), event.getC());
DynamicTrackedRace trackedRace = getTrackedRace(tractracRace);
if (trackedRace != null) {
@@ -109,6 +109,7 @@ public class RaceCourseReceiver extends AbstractReceiverWithQueue<IControlRoute,
@Override
protected void handleEvent(Triple<IControlRoute, Long, Void> event) {
System.out.print("R");
ensureAllSingleMarksOfCourseAreaAreCreated(tractracRace); // this way, single marks will be known by their original name, even if used as virtual marks in gates/lines
final IRoute route = event.getA();
final String routeMetadataString = route.getMetadata() != null ? route.getMetadata().getText() : null;
final LinkedHashMap<IControl, TracTracControlPoint> ttControlPointsForAllOriginalEventControlPoints = new LinkedHashMap<>();