Repository: graphhopper/graphhopper
Pull request #1907 (2020-02-13 09:09:02)

Extend RoadClass
* added support for footway, pedestrian, [platform](https://wiki.openstreetmap.org/wiki/Tag:highway=platform) and [corridor](https://wiki.openstreetmap.org/wiki/Tag:highway=corridor)*
* avoid Exceptions in `RoadClass.find(String name)`

\* we could add support for other indoor routing attributes in the future: https://wiki.openstreetmap.org/wiki/Key:indoor


Patch:
diff --git a/core/files/changelog.txt b/core/files/changelog.txt
index 681772d19..a3d29e034 100644
--- a/core/files/changelog.txt
+++ b/core/files/changelog.txt
@@ -1,4 +1,5 @@
 1.0
+    replaced command line arguments -Dgraphhopper.. with -Ddw.graphhopper.. due to #1879, see also #1897
     GraphHopper.init(CmdArgs)->GraphHopper.init(GraphHopperConfig), see #1879
     revert compression of landmark preparation data, see #1749 and #1376
     removed GenericWeighting and DataFlagEncoder as a normal CarFlagEncoder does the job too
diff --git a/core/src/main/java/com/graphhopper/routing/profiles/RoadClass.java b/core/src/main/java/com/graphhopper/routing/profiles/RoadClass.java
index 80daf7b6a..0abc2f2c9 100644
--- a/core/src/main/java/com/graphhopper/routing/profiles/RoadClass.java
+++ b/core/src/main/java/com/graphhopper/routing/profiles/RoadClass.java
@@ -17,8 +17,6 @@
  */
 package com.graphhopper.routing.profiles;
 
-import com.graphhopper.util.Helper;
-
 /**
  * This enum defines the road class of an edge. It is heavily influenced from the highway tag in OSM that can be
  * primary, cycleway etc.
@@ -29,7 +27,8 @@ public enum RoadClass {
     TERTIARY("tertiary"), RESIDENTIAL("residential"), UNCLASSIFIED("unclassified"),
     SERVICE("service"), ROAD("road"), TRACK("track"),
     BRIDLEWAY("bridleway"), STEPS("steps"), CYCLEWAY("cycleway"),
-    PATH("path"), LIVING_STREET("living_street");
+    PATH("path"), LIVING_STREET("living_street"), FOOTWAY("footway"),
+    PEDESTRIAN("pedestrian"), PLATFORM("platform"), CORRIDOR("corridor");
 
     public static final String KEY = "road_class";
 
@@ -45,12 +44,15 @@ public enum RoadClass {
     }
 
     public static RoadClass find(String name) {
-        if (name == null)
-            return OTHER;
-        try {
-            return RoadClass.valueOf(Helper.toUpperCase(name));
-        } catch (IllegalArgumentException ex) {
+        if (name == null || name.isEmpty())
             return OTHER;
+        
+        for (RoadClass roadClass : values()) {
+            if (roadClass.name().equalsIgnoreCase(name)) {
+                return roadClass;
+            }
         }
+        
+        return OTHER;
     }
 }


Test patch:
diff --git a/core/src/test/java/com/graphhopper/GraphHopperAPITest.java b/core/src/test/java/com/graphhopper/GraphHopperAPITest.java
index 7de12478d..108bc24cd 100644
--- a/core/src/test/java/com/graphhopper/GraphHopperAPITest.java
+++ b/core/src/test/java/com/graphhopper/GraphHopperAPITest.java
@@ -18,7 +18,6 @@
 package com.graphhopper;
 
 import com.graphhopper.json.geo.JsonFeature;
-import com.graphhopper.routing.util.CarFlagEncoder;
 import com.graphhopper.routing.util.EncodingManager;
 import com.graphhopper.storage.Graph;
 import com.graphhopper.storage.GraphBuilder;
@@ -114,8 +113,7 @@ public class GraphHopperAPITest {
     public void testDoNotInterpolateTwice1645() {
         String loc = "./target/issue1645";
         Helper.removeDir(new File(loc));
-        EncodingManager em = new EncodingManager.Builder().add(new CarFlagEncoder()).build();
-        GraphHopperStorage graph = GraphBuilder.start(em).setRAM(loc, true).set3D(true).create();
+        GraphHopperStorage graph = GraphBuilder.start(encodingManager).setRAM(loc, true).set3D(true).create();
 
         // we need elevation
         NodeAccess na = graph.getNodeAccess();
@@ -128,33 +126,32 @@ public class GraphHopperAPITest {
         graph.edge(2, 3, 10, true);
 
         final AtomicInteger counter = new AtomicInteger(0);
-        GraphHopper instance = new GraphHopper()
-                .setEncodingManager(em)
+        GraphHopper instance = createGraphHopper()
                 .setElevation(true).setGraphHopperLocation(loc).setCHEnabled(false)
                 .loadGraph(graph);
         instance.flush();
         instance.close();
         assertEquals(0, counter.get());
 
-        instance = new GraphHopper() {
+        instance = setupGraphHopper(new GraphHopper() {
             @Override
             void interpolateBridgesAndOrTunnels() {
                 counter.incrementAndGet();
                 super.interpolateBridgesAndOrTunnels();
             }
-        }.setEncodingManager(em).setElevation(true).setCHEnabled(false);
+        }).setElevation(true).setCHEnabled(false);
         instance.load(loc);
         instance.flush();
         instance.close();
         assertEquals(1, counter.get());
 
-        instance = new GraphHopper() {
+        instance = setupGraphHopper(new GraphHopper() {
             @Override
             void interpolateBridgesAndOrTunnels() {
                 counter.incrementAndGet();
                 super.interpolateBridgesAndOrTunnels();
             }
-        }.setEncodingManager(em).setElevation(true).setCHEnabled(false);
+        }).setElevation(true).setCHEnabled(false);
         instance.load(loc);
         instance.flush();
         instance.close();
@@ -192,7 +189,7 @@ public class GraphHopperAPITest {
 
         final CountDownLatch latch = new CountDownLatch(1);
         final AtomicInteger checkPointCounter = new AtomicInteger(0);
-        final GraphHopper graphHopper = new GraphHopper() {
+        final GraphHopper graphHopper = setupGraphHopper(new GraphHopper() {
             @Override
             protected ChangeGraphHelper createChangeGraphHelper(Graph graph, LocationIndex locationIndex) {
                 return new ChangeGraphHelper(graph, locationIndex) {
@@ -210,7 +207,7 @@ public class GraphHopperAPITest {
                     }
                 };
             }
-        }.setStoreOnFlush(false).setEncodingManager(encodingManager).setCHEnabled(false).
+        }).setStoreOnFlush(false).setCHEnabled(false).
                 loadGraph(graph);
 
         GHResponse rsp = graphHopper.route(new GHRequest(42, 10.4, 42, 10));
@@ -247,7 +244,11 @@ public class GraphHopperAPITest {
     }
 
     private GraphHopper createGraphHopper() {
-        return new GraphHopper().
-                setEncodingManager(encodingManager);
+        return setupGraphHopper(new GraphHopper());
+    }
+
+    private GraphHopper setupGraphHopper(GraphHopper hopper) {
+        hopper.setEncodingManager(encodingManager);
+        return hopper;
     }
 }
diff --git a/core/src/test/java/com/graphhopper/routing/profiles/EnumEncodedValueTest.java b/core/src/test/java/com/graphhopper/routing/profiles/EnumEncodedValueTest.java
index 6ae5fcc73..678039209 100644
--- a/core/src/test/java/com/graphhopper/routing/profiles/EnumEncodedValueTest.java
+++ b/core/src/test/java/com/graphhopper/routing/profiles/EnumEncodedValueTest.java
@@ -11,8 +11,8 @@ public class EnumEncodedValueTest {
     public void testInit() {
         EnumEncodedValue<RoadClass> prop = new EnumEncodedValue<>("road_class", RoadClass.class);
         EncodedValue.InitializerConfig init = new EncodedValue.InitializerConfig();
-        assertEquals(4, prop.init(init));
-        assertEquals(4, prop.bits);
+        assertEquals(5, prop.init(init));
+        assertEquals(5, prop.bits);
         assertEquals(0, init.dataIndex);
         assertEquals(0, init.shift);
         IntsRef ref = new IntsRef(1);