From 4ad577e46e304927bfc7bd92e9c3c3851eec4aad Mon Sep 17 00:00:00 2001
From: Taylor Smock <tsmock@fb.com>
Date: Mon, 17 May 2021 10:14:01 -0600
Subject: [PATCH] pt_assistant: update for compatibility with JOSM r17896

Signed-off-by: Taylor Smock <tsmock@fb.com>
---
 gradle.properties                             |  4 +--
 .../CreateNewStopPointOperation.java          | 33 ++++++++++---------
 .../NearestWaySegment.java                    |  7 ++--
 .../actions/AddStopPositionAction.java        |  5 +--
 .../actions/DoubleSplitAction.java            |  5 +--
 5 files changed, 29 insertions(+), 25 deletions(-)

diff --git a/gradle.properties b/gradle.properties
index 914aa89a..7ee98bd1 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -10,6 +10,6 @@ plugin.canloadatruntime=true
 plugin.icon=images/bus.svg
 
 # Minimum JOSM version (any numeric version)
-plugin.main.version=15238
+plugin.main.version=17903
 # JOSM version to compile against (any numeric version available for download, or the special values "tested" or "latest")
-plugin.compile.version=17084
+plugin.compile.version=17903
diff --git a/src/main/java/org/openstreetmap/josm/plugins/customizepublictransportstop/CreateNewStopPointOperation.java b/src/main/java/org/openstreetmap/josm/plugins/customizepublictransportstop/CreateNewStopPointOperation.java
index 4d81e231..6a22408e 100644
--- a/src/main/java/org/openstreetmap/josm/plugins/customizepublictransportstop/CreateNewStopPointOperation.java
+++ b/src/main/java/org/openstreetmap/josm/plugins/customizepublictransportstop/CreateNewStopPointOperation.java
@@ -18,9 +18,10 @@
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.BBox;
 import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.INode;
+import org.openstreetmap.josm.data.osm.IWaySegment;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.Way;
-import org.openstreetmap.josm.data.osm.WaySegment;
 import org.openstreetmap.josm.data.projection.ProjectionRegistry;
 import org.openstreetmap.josm.gui.MainApplication;
 import org.openstreetmap.josm.gui.MapView;
@@ -154,8 +155,8 @@ public Boolean testWay(final Way way, final StopArea stopArea) {
      * @return a sorted map with the keys representing the perpendicular distance of
      *         their associated way segments to point p.
      */
-    private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p) {
-        Map<Double, List<WaySegment>> nearestMap = new TreeMap<>();
+    private Map<Double, List<IWaySegment<Node, Way>>> getNearestWaySegmentsImpl(Point p) {
+        Map<Double, List<IWaySegment<Node, Way>>> nearestMap = new TreeMap<>();
         DataSet ds = getCurrentDataSet();
 
         if (ds != null) {
@@ -192,14 +193,14 @@ private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p) {
                             Double.doubleToLongBits(a - (a - b + c) * (a - b + c) / 4 / c) >> 32 << 32);
 
                     if (perDistSq < snapDistanceSq && a < c + snapDistanceSq && b < c + snapDistanceSq) {
-                        List<WaySegment> wslist;
+                        List<IWaySegment<Node, Way>> wslist;
                         if (nearestMap.containsKey(perDistSq)) {
                             wslist = nearestMap.get(perDistSq);
                         } else {
                             wslist = new LinkedList<>();
                             nearestMap.put(perDistSq, wslist);
                         }
-                        wslist.add(new WaySegment(w, i));
+                        wslist.add(new IWaySegment<>(w, i));
                     }
 
                     lastN = n;
@@ -220,12 +221,12 @@ private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p) {
     protected NearestWaySegment getNearestWaySegment(LatLon platformCoord, StopArea stopArea) {
         MapView mapView = MainApplication.getMap().mapView;
         Point p = mapView.getPoint(platformCoord);
-        Map<Double, List<WaySegment>> dist_waySegments = getNearestWaySegmentsImpl(p);
-        for (Map.Entry<Double, List<WaySegment>> entry : dist_waySegments.entrySet()) {
-            for (WaySegment waySegment : entry.getValue()) {
-                if (testWay(waySegment.way, stopArea)) {
-                    Node n = waySegment.getFirstNode();
-                    Node lastN = waySegment.getSecondNode();
+        Map<Double, List<IWaySegment<Node, Way>>> dist_waySegments = getNearestWaySegmentsImpl(p);
+        for (Map.Entry<Double, List<IWaySegment<Node, Way>>> entry : dist_waySegments.entrySet()) {
+            for (IWaySegment<Node, Way> waySegment : entry.getValue()) {
+                if (testWay(waySegment.getWay(), stopArea)) {
+                    INode n = waySegment.getFirstNode();
+                    INode lastN = waySegment.getSecondNode();
 
                     EastNorth newPosition = Geometry.closestPointToSegment(n.getEastNorth(), lastN.getEastNorth(),
                             ProjectionRegistry.getProjection().latlon2eastNorth(platformCoord));
@@ -251,13 +252,13 @@ protected NearestWaySegment getNearestWaySegment(LatLon platformCoord, StopArea
      * @param waySegment Way segment including stop position node
      * @return Stop position node
      */
-    protected Node createNodeOnWay(Node newStopNode, WaySegment waySegment) {
+    protected Node createNodeOnWay(Node newStopNode, IWaySegment<?, Way> waySegment) {
         UndoRedoHandler.getInstance().add(new AddCommand(MainApplication.getLayerManager().getEditDataSet(), newStopNode));
-        List<Node> wayNodes = waySegment.way.getNodes();
-        wayNodes.add(waySegment.lowerIndex + 1, newStopNode);
-        Way newWay = new Way(waySegment.way);
+        List<Node> wayNodes = waySegment.getWay().getNodes();
+        wayNodes.add(waySegment.getUpperIndex(), newStopNode);
+        Way newWay = new Way(waySegment.getWay());
         newWay.setNodes(wayNodes);
-        UndoRedoHandler.getInstance().add(new ChangeCommand(waySegment.way, newWay));
+        UndoRedoHandler.getInstance().add(new ChangeCommand(waySegment.getWay(), newWay));
         return newStopNode;
     }
 
diff --git a/src/main/java/org/openstreetmap/josm/plugins/customizepublictransportstop/NearestWaySegment.java b/src/main/java/org/openstreetmap/josm/plugins/customizepublictransportstop/NearestWaySegment.java
index c779b4f2..3d5d1827 100644
--- a/src/main/java/org/openstreetmap/josm/plugins/customizepublictransportstop/NearestWaySegment.java
+++ b/src/main/java/org/openstreetmap/josm/plugins/customizepublictransportstop/NearestWaySegment.java
@@ -1,8 +1,9 @@
 // License: GPL. For details, see LICENSE file.
 package org.openstreetmap.josm.plugins.customizepublictransportstop;
 
+import org.openstreetmap.josm.data.osm.IWaySegment;
 import org.openstreetmap.josm.data.osm.Node;
-import org.openstreetmap.josm.data.osm.WaySegment;
+import org.openstreetmap.josm.data.osm.Way;
 
 /**
  * Distance from platform to ways
@@ -17,7 +18,7 @@ public class NearestWaySegment {
     /**
      * Way segment
      */
-    public WaySegment waySegment;
+    public IWaySegment<Node, Way> waySegment;
     /**
      * Node
      */
@@ -30,7 +31,7 @@ public class NearestWaySegment {
      * @param waySegment Way segment
      * @param newNode Node
      */
-    public NearestWaySegment(Double distanceSq, WaySegment waySegment, Node newNode) {
+    public NearestWaySegment(Double distanceSq, IWaySegment<Node, Way> waySegment, Node newNode) {
         this.distanceSq = distanceSq;
         this.waySegment = waySegment;
         this.newNode = newNode;
diff --git a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/AddStopPositionAction.java b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/AddStopPositionAction.java
index df40441f..11a390cb 100644
--- a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/AddStopPositionAction.java
+++ b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/AddStopPositionAction.java
@@ -24,6 +24,7 @@
 import org.openstreetmap.josm.command.SequenceCommand;
 import org.openstreetmap.josm.command.SplitWayCommand;
 import org.openstreetmap.josm.data.UndoRedoHandler;
+import org.openstreetmap.josm.data.osm.IWaySegment;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
@@ -103,8 +104,8 @@ public void mouseMoved(MouseEvent e) {
                 MainApplication.getMap().mapView.getNearestWaySegments(e.getPoint(), OsmPrimitive::isSelectable);
 
             if (!wss.isEmpty()) {
-                for (WaySegment ws : wss) {
-                    newHighlights.add(ws.way);
+                for (IWaySegment<?, Way> ws : wss) {
+                    newHighlights.add(ws.getWay());
                 }
                 newCurs = CURSOR_JOIN_WAY;
             }
diff --git a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/DoubleSplitAction.java b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/DoubleSplitAction.java
index 4361bbc0..276b80da 100644
--- a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/DoubleSplitAction.java
+++ b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/DoubleSplitAction.java
@@ -41,6 +41,7 @@
 import org.openstreetmap.josm.data.coor.ILatLon;
 import org.openstreetmap.josm.data.coor.LatLon;
 import org.openstreetmap.josm.data.osm.DataSet;
+import org.openstreetmap.josm.data.osm.IWaySegment;
 import org.openstreetmap.josm.data.osm.Node;
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
@@ -636,8 +637,8 @@ public void mouseMoved(MouseEvent e) {
                     OsmPrimitive::isSelectable);
 
             if (!wss.isEmpty()) {
-                for (WaySegment ws : wss) {
-                    newHighlights.add(ws.way);
+                for (IWaySegment<?, Way> ws : wss) {
+                    newHighlights.add(ws.getWay());
                 }
                 newCurs = cursorJoinWay;
             }