mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-04 11:23:50 +00:00
Merge branch 'master' of ssh://195.227.10.246/home/trac/git
This commit is contained in:
commit
95bdfdfceb
3 files changed
+23
-17
No files matched your search
+23
-6
@@ -132,13 +132,30 @@ public class DomainFactoryImpl implements DomainFactory {
|
|||||||
public void updateCourseWaypoints(Course courseToUpdate, List<ControlPoint> controlPoints) throws PatchFailedException {
|
public void updateCourseWaypoints(Course courseToUpdate, List<ControlPoint> controlPoints) throws PatchFailedException {
|
||||||
Iterable<Waypoint> courseWaypoints = courseToUpdate.getWaypoints();
|
Iterable<Waypoint> courseWaypoints = courseToUpdate.getWaypoints();
|
||||||
List<Waypoint> newWaypointList = new LinkedList<Waypoint>();
|
List<Waypoint> newWaypointList = new LinkedList<Waypoint>();
|
||||||
|
// key existing waypoints by control points and re-use each one at most once during construction of the
|
||||||
|
// new waypoint list; since several waypoints can have the same control point, the map goes from
|
||||||
|
// control point to List<Waypoint>. The waypoints in the lists are held in the order of their
|
||||||
|
// occurrence in courseToUpdate.getWaypoints().
|
||||||
|
Map<com.sap.sailing.domain.base.ControlPoint, List<Waypoint>> existingWaypointsByControlPoint =
|
||||||
|
new HashMap<com.sap.sailing.domain.base.ControlPoint, List<Waypoint>>();
|
||||||
|
for (Waypoint waypoint : courseToUpdate.getWaypoints()) {
|
||||||
|
List<Waypoint> wpl = existingWaypointsByControlPoint.get(waypoint.getControlPoint());
|
||||||
|
if (wpl == null) {
|
||||||
|
wpl = new ArrayList<Waypoint>();
|
||||||
|
existingWaypointsByControlPoint.put(waypoint.getControlPoint(), wpl);
|
||||||
|
}
|
||||||
|
wpl.add(waypoint);
|
||||||
|
}
|
||||||
for (ControlPoint tractracControlPoint : controlPoints) {
|
for (ControlPoint tractracControlPoint : controlPoints) {
|
||||||
// The following creates new waypoints; those using equal control points (equality controlled by their UUID)
|
com.sap.sailing.domain.base.ControlPoint domainControlPoint = getControlPoint(tractracControlPoint);
|
||||||
// are considered equal. Therefore, the diff will try to construct a minimal set of changes where those
|
List<Waypoint> waypoints = existingWaypointsByControlPoint.get(domainControlPoint);
|
||||||
// old waypoints remain the same but where the patch may alter their positions. Deleted waypoints are trivial
|
Waypoint waypoint;
|
||||||
// regarding ID retention. Waypoints added obtain a new ID during the createWaypoint and will be inserted
|
if (waypoints == null || waypoints.isEmpty()) {
|
||||||
// with this new ID.
|
// must be a new control point for which we don't have a waypoint yet
|
||||||
Waypoint waypoint = createWaypoint(tractracControlPoint);
|
waypoint = createWaypoint(tractracControlPoint);
|
||||||
|
} else {
|
||||||
|
waypoint = waypoints.remove(0); // take the first from the list
|
||||||
|
}
|
||||||
newWaypointList.add(waypoint);
|
newWaypointList.add(waypoint);
|
||||||
}
|
}
|
||||||
Patch<Waypoint> patch = DiffUtils.diff(courseWaypoints, newWaypointList);
|
Patch<Waypoint> patch = DiffUtils.diff(courseWaypoints, newWaypointList);
|
||||||
|
|||||||
@@ -5,9 +5,6 @@ package com.sap.sailing.domain.base;
|
|||||||
* {@link ControlPoint}, such as a {@link Buoy} or a {@link Gate}. The same control point can be used by multiple
|
* {@link ControlPoint}, such as a {@link Buoy} or a {@link Gate}. The same control point can be used by multiple
|
||||||
* waypoints.<p>
|
* waypoints.<p>
|
||||||
*
|
*
|
||||||
* Two waypoints {@link Object#equals(Object) equal} each other if they have the <em>same</em>
|
|
||||||
* {@link #getControlPoint() control point}.
|
|
||||||
*
|
|
||||||
* @author Axel Uhl (d043530)
|
* @author Axel Uhl (d043530)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -14,14 +14,6 @@ public class WaypointImpl implements Waypoint {
|
|||||||
id = idCounter++;
|
id = idCounter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
return getControlPoint() == ((Waypoint) o).getControlPoint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int hashCode() {
|
|
||||||
return 984637 ^ getControlPoint().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ControlPoint getControlPoint() {
|
public ControlPoint getControlPoint() {
|
||||||
return controlPoint;
|
return controlPoint;
|
||||||
|
|||||||
Reference in new issue
Block a user