diff --git a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java index a8e1677bc4..2296dd9ad7 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/TransportRoutePlanner.java @@ -371,11 +371,11 @@ public class TransportRoutePlanner { } public List getGeometry() { - List list = new ArrayList(); + List list = new ArrayList<>(); route.mergeForwardWays(); - if(DISPLAY_FULL_SEGMENT_ROUTE) { + if (DISPLAY_FULL_SEGMENT_ROUTE) { System.out.println("TOTAL SEGMENTS: " + route.getForwardWays().size()); - if(route.getForwardWays().size() > DISPLAY_SEGMENT_IND) { + if (route.getForwardWays().size() > DISPLAY_SEGMENT_IND) { return Collections.singletonList(route.getForwardWays().get(DISPLAY_SEGMENT_IND)); } return route.getForwardWays(); @@ -386,38 +386,36 @@ public class TransportRoutePlanner { LatLon str = getStart().getLocation(); LatLon en = getEnd().getLocation(); int endInd = -1; - List res = new ArrayList(); - for(int i = 0; i < fw.size() ; i++) { + List res = new ArrayList<>(); + for (int i = 0; i < fw.size() ; i++) { List nodes = fw.get(i).getNodes(); - for(int j = 0; j < nodes.size(); j++) { + for (int j = 0; j < nodes.size(); j++) { Node n = nodes.get(j); - if(MapUtils.getDistance(str, n.getLatitude(), n.getLongitude()) < minStart) { + if (MapUtils.getDistance(str, n.getLatitude(), n.getLongitude()) < minStart) { minStart = MapUtils.getDistance(str, n.getLatitude(), n.getLongitude()); res.clear(); } res.add(n); - if(MapUtils.getDistance(en, n.getLatitude(), n.getLongitude()) < minEnd) { + if (MapUtils.getDistance(en, n.getLatitude(), n.getLongitude()) < minEnd) { endInd = res.size(); minEnd = MapUtils.getDistance(en, n.getLatitude(), n.getLongitude()); } } } Way way = new Way(-1); - if (res.isEmpty()) { + if (res.isEmpty() || endInd == -1) { for (int i = start; i <= end; i++) { LatLon l = getStop(i).getLocation(); Node n = new Node(l.getLatitude(), l.getLongitude(), -1); way.addNode(n); } - list.add(way); } else { - for(int k = 0; k < res.size() && k < endInd; k++) { + for(int k = 0; k < res.size() && k < endInd; k++) { way.addNode(res.get(k)); } } list.add(way); return list; - } public double getTravelDist() {