Skip to content

Commit

Permalink
Make the suitable ways in transport modes a static field
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Schäfer <[email protected]>
  • Loading branch information
PolyglotOpenstreetmap and floscher committed Nov 16, 2020
1 parent 3d3cc48 commit e6e452d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,24 +18,25 @@
import org.openstreetmap.josm.tools.ImageProvider;

public class BicycleTransportMode implements ITransportMode {

private static final List<String> 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<String> 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<String> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,28 +18,30 @@
import org.openstreetmap.josm.tools.ImageProvider;

public class BusTransportMode implements ITransportMode {

private static final List<String> 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<String> majorHighways = Arrays.asList(
"motorway", "trunk", "primary", "secondary", "tertiary");
majorHighways.forEach(v -> majorHighways.add(String.format("%s_link", v)));
List<String> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,24 +18,27 @@
import org.openstreetmap.josm.tools.ImageProvider;

public class HorseTransportMode implements ITransportMode {

private static final List<String> 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<String> 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<String> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -20,30 +18,34 @@
import org.openstreetmap.josm.tools.ImageProvider;

public class PedestrianTransportMode implements ITransportMode {

private static final List<String> 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<String> 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<String> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
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;

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
Expand Down

0 comments on commit e6e452d

Please sign in to comment.