diff --git a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BicycleTransportMode.java b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BicycleTransportMode.java index 341857fa..23eaf1aa 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BicycleTransportMode.java +++ b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BicycleTransportMode.java @@ -1,10 +1,10 @@ package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; -import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import com.drew.lang.annotations.NotNull; import org.openstreetmap.josm.data.osm.IRelation; @@ -18,24 +18,25 @@ import org.openstreetmap.josm.tools.ImageProvider; public class BicycleTransportMode implements ITransportMode { + + private static final List suitableHighwaysForBicycle = Stream.concat( + // This list is ordered from most suitable to least suitable + Stream.of("cycleway", "cyclestreet", "path", "residential", "unclassified", "service", "track", "living_street"), + Stream.of("tertiary", "secondary", "primary", "trunk").flatMap(it -> Stream.of(it, it + "_link")) + ).collect(Collectors.toList()); + @Override public boolean canTraverseWay(@NotNull final IWay way, @NotNull final WayTraversalDirection direction) { final String onewayValue = way.get("oneway"); - List majorHighways = Arrays.asList( - "tertiary", "secondary", "primary", "trunk"); - majorHighways.forEach(v -> majorHighways.add(String.format("%s_link", v))); - // This list is ordered from most suitable to least suitable - List suitableHighwaysForBicycle = Arrays.asList( - "cycleway", "cyclestreet", "path", "residential", "unclassified", "service", "track", "living_street"); - suitableHighwaysForBicycle.addAll(majorHighways); // TODO do this only once when plugin starts - return !way.hasTag("bicycle", "no") && - (way.hasTag("highway", suitableHighwaysForBicycle) || - way.hasTag("bicycle", "yes")) - && ( - onewayValue == null || "no".equals(way.get("oneway:bicycle")) || - ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) || - ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) - ); + return + !way.hasTag("bicycle", "no") + && (way.hasTag("highway", suitableHighwaysForBicycle) || way.hasTag("bicycle", "yes")) + && ( + onewayValue == null + || "no".equals(way.get("oneway:bicycle")) + || ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) + || ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) + ); } @Override diff --git a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BusTransportMode.java b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BusTransportMode.java index f0b814e3..8665607c 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BusTransportMode.java +++ b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/BusTransportMode.java @@ -1,13 +1,10 @@ package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; - -import javax.swing.Icon; +import java.util.stream.Stream; import com.drew.lang.annotations.NotNull; import org.openstreetmap.josm.data.osm.IRelation; @@ -21,28 +18,30 @@ import org.openstreetmap.josm.tools.ImageProvider; public class BusTransportMode implements ITransportMode { + + private static final List suitableHighwaysForBus = Stream.concat( + Stream.of("unclassified", "residential", "service", "living_street", "cyclestreet"), + Stream.of("motorway", "trunk", "primary", "secondary", "tertiary").flatMap(it -> Stream.of(it, it + "_link")) + ).collect(Collectors.toList()); + @Override public boolean canTraverseWay(@NotNull final IWay way, @NotNull final WayTraversalDirection direction) { final String onewayValue = way.get("oneway"); - List majorHighways = Arrays.asList( - "motorway", "trunk", "primary", "secondary", "tertiary"); - majorHighways.forEach(v -> majorHighways.add(String.format("%s_link", v))); - List suitableHighwaysForBus = Arrays.asList( - "unclassified", "residential", "service", "living_street", "cyclestreet"); - suitableHighwaysForBus.addAll(majorHighways); // TODO do this only once when plugin starts - return (way.hasTag("highway", suitableHighwaysForBus) || - way.hasTag("psv", "yes") || way.hasTag ("bus", "yes")) - && ( - onewayValue == null || "no".equals(way.get("oneway:bus")) || - ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) || - ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) + return ( + way.hasTag("highway", suitableHighwaysForBus) + || way.hasTag("psv", "yes") || way.hasTag ("bus", "yes") + ) + && ( + onewayValue == null + || "no".equals(way.get("oneway:bus")) + || ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) + || ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) ); } @Override public boolean canBeUsedForRelation(@NotNull final IRelation relation) { - return relation.hasTag("type", "route") && relation.hasTag("route", - "bus", "coach", "minibus"); + return relation.hasTag("type", "route") && relation.hasTag("route", "bus", "coach", "minibus"); } @Override diff --git a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/HorseTransportMode.java b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/HorseTransportMode.java index f6928738..36d44026 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/HorseTransportMode.java +++ b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/HorseTransportMode.java @@ -1,10 +1,10 @@ package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; -import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.Stream; import com.drew.lang.annotations.NotNull; import org.openstreetmap.josm.data.osm.IRelation; @@ -18,24 +18,27 @@ import org.openstreetmap.josm.tools.ImageProvider; public class HorseTransportMode implements ITransportMode { + + private static final List suitableHighwaysForHorseRiders = Stream.concat( + // This list is ordered from most suitable to least suitable + Stream.of( + "bridleway", "pedestrian", "footway", "path", "track", "living_street", "residential", + "unclassified", "cyclestreet", "service", "cycleway" + ), + Stream.of("tertiary", "secondary", "primary", "trunk").flatMap(it -> Stream.of(it, it + "_link")) + ).collect(Collectors.toList()); + @Override public boolean canTraverseWay(@NotNull final IWay way, @NotNull final WayTraversalDirection direction) { final String onewayValue = way.get("oneway"); - List majorHighways = Arrays.asList( - "tertiary", "secondary", "primary", "trunk"); - majorHighways.forEach(v -> majorHighways.add(String.format("%s_link", v))); - // This list is ordered from most suitable to least suitable - List suitableHighwaysForHorseRiders = Arrays.asList( - "bridleway", "pedestrian", "footway", "path", "track", "living_street", "residential", "unclassified", "cyclestreet", "service", "cycleway"); - suitableHighwaysForHorseRiders.addAll(majorHighways); // TODO do this only once when plugin starts - return !way.hasTag("horse", "no") && - (way.hasTag("highway", suitableHighwaysForHorseRiders) || - way.hasTag("horse", "yes")) - && ( - onewayValue == null || - ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) || - ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) - ); + return + !way.hasTag("horse", "no") + && (way.hasTag("highway", suitableHighwaysForHorseRiders) || way.hasTag("horse", "yes")) + && ( + onewayValue == null + || ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) + || ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) + ); } @Override diff --git a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/PedestrianTransportMode.java b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/PedestrianTransportMode.java index 8fb9e2c3..0d4313e3 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/PedestrianTransportMode.java +++ b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/PedestrianTransportMode.java @@ -1,12 +1,10 @@ package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; -import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; - -import javax.swing.Icon; +import java.util.stream.Stream; import com.drew.lang.annotations.NotNull; import org.openstreetmap.josm.data.osm.IRelation; @@ -20,30 +18,34 @@ import org.openstreetmap.josm.tools.ImageProvider; public class PedestrianTransportMode implements ITransportMode { + + private static final List suitableHighwaysForPedestrians = Stream.concat( + // This list is ordered from most suitable to least suitable + Stream.of( + "pedestrian", "footway", "path", "track", "living_street", "residential", + "unclassified", "cyclestreet", "service", "cycleway", "bridleway" + ), + Stream.of("tertiary", "secondary", "primary", "trunk").flatMap(it -> Stream.of(it, it + "_link")) + ).collect(Collectors.toList()); + @Override public boolean canTraverseWay(@NotNull final IWay way, @NotNull final WayTraversalDirection direction) { final String onewayValue = way.get("oneway"); - List majorHighways = Arrays.asList( - "tertiary", "secondary", "primary", "trunk"); - majorHighways.forEach(v -> majorHighways.add(String.format("%s_link", v))); - // This list is ordered from most suitable to least suitable - List suitableHighwaysForPedestrians = Arrays.asList( - "pedestrian", "footway", "path", "track", "living_street", "residential", "unclassified", "cyclestreet", "service", "cycleway", "bridleway"); - suitableHighwaysForPedestrians.addAll(majorHighways); // TODO do this only once when plugin starts - return !way.hasTag("foot", "no") && - (way.hasTag("highway", suitableHighwaysForPedestrians) || - way.hasTag("foot", "yes")) - && ( - onewayValue == null || "no".equals(way.get("foot:backward")) || "no".equals(way.get("oneway:foot")) || - ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) || - ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) - ); + return + !way.hasTag("foot", "no") + && (way.hasTag("highway", suitableHighwaysForPedestrians) || way.hasTag("foot", "yes")) + && ( + onewayValue == null + || "no".equals(way.get("foot:backward")) + || "no".equals(way.get("oneway:foot")) + || ("yes".equals(onewayValue) && direction == WayTraversalDirection.FORWARD) + || ("-1".equals(onewayValue) && direction == WayTraversalDirection.BACKWARD) + ); } @Override public boolean canBeUsedForRelation(@NotNull final IRelation relation) { - return relation.hasTag("type", "route") && relation.hasTag("route", - "foot", "walking", "hiking"); + return relation.hasTag("type", "route") && relation.hasTag("route", "foot", "walking", "hiking"); } @Override diff --git a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/TrolleyBusTransportMode.java b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/TrolleyBusTransportMode.java index 12614a34..c089ff9f 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/TrolleyBusTransportMode.java +++ b/src/main/java/org/openstreetmap/josm/plugins/pt_assistant/actions/routinghelper/TrolleyBusTransportMode.java @@ -1,16 +1,8 @@ package org.openstreetmap.josm.plugins.pt_assistant.actions.routinghelper; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; - import com.drew.lang.annotations.NotNull; import org.openstreetmap.josm.data.osm.IRelation; import org.openstreetmap.josm.data.osm.IWay; -import org.openstreetmap.josm.data.osm.Node; -import org.openstreetmap.josm.data.osm.OsmPrimitiveType; -import org.openstreetmap.josm.data.osm.Relation; -import org.openstreetmap.josm.data.osm.Way; import org.openstreetmap.josm.plugins.pt_assistant.utils.PTIcons; import org.openstreetmap.josm.tools.I18n; import org.openstreetmap.josm.tools.ImageProvider; @@ -18,12 +10,12 @@ public class TrolleyBusTransportMode extends BusTransportMode { @Override public boolean canTraverseWay(@NotNull final IWay way, @NotNull final WayTraversalDirection direction) { - return canTraverseWay(way, direction) && way.hasTag("trolley_wire", "yes"); + return super.canTraverseWay(way, direction) && way.hasTag("trolley_wire", "yes"); } @Override public boolean canBeUsedForRelation(@NotNull final IRelation relation) { - return canBeUsedForRelation(relation) && relation.hasTag("route", "trolleybus"); + return relation.hasTag("type", "route") && relation.hasTag("route", "trolleybus"); } @Override