Repository: graphhopper/graphhopper
Pull request #2156 (2020-10-14 13:35:21)

improve enum encoded values


Patch:
diff --git a/core/src/main/java/com/graphhopper/routing/InstructionsFromEdges.java b/core/src/main/java/com/graphhopper/routing/InstructionsFromEdges.java
index 07d6fd24c..4cec4b5ba 100644
--- a/core/src/main/java/com/graphhopper/routing/InstructionsFromEdges.java
+++ b/core/src/main/java/com/graphhopper/routing/InstructionsFromEdges.java
@@ -169,7 +169,7 @@ public class InstructionsFromEdges implements Path.EdgeVisitor {
         int importance = 1;
         if (getOffBikeEnc != null) {
             if (edge.get(roadClassEnc) == RoadClass.CYCLEWAY
-                    || bikeRouteEnc != null && edge.get(bikeRouteEnc) != RouteNetwork.OTHER) {
+                    || bikeRouteEnc != null && edge.get(bikeRouteEnc) != RouteNetwork.MISSING) {
                 // for backward compatibility
                 importance = 0;
                 info = tr.tr("cycleway");
diff --git a/core/src/main/java/com/graphhopper/routing/ev/HazmatTunnel.java b/core/src/main/java/com/graphhopper/routing/ev/HazmatTunnel.java
index 0f20d44a2..2422be937 100644
--- a/core/src/main/java/com/graphhopper/routing/ev/HazmatTunnel.java
+++ b/core/src/main/java/com/graphhopper/routing/ev/HazmatTunnel.java
@@ -4,7 +4,7 @@ package com.graphhopper.routing.ev;
  * Defines the degree of restriction for the transport of hazardous goods through tunnels.<br>
  * If not tagged it will be {@link #A}
  * 
- * @see https://wiki.openstreetmap.org/wiki/Key:hazmat#Tunnel_restrictions
+ * @see <a href="https://wiki.openstreetmap.org/wiki/Key:hazmat#Tunnel_restrictions">Hazmat Tunnel restrictions</a>
  */
 public enum HazmatTunnel {
     /** driving with any dangerous goods allowed */
diff --git a/core/src/main/java/com/graphhopper/routing/ev/RoadAccess.java b/core/src/main/java/com/graphhopper/routing/ev/RoadAccess.java
index 4851349b7..32593f78d 100644
--- a/core/src/main/java/com/graphhopper/routing/ev/RoadAccess.java
+++ b/core/src/main/java/com/graphhopper/routing/ev/RoadAccess.java
@@ -20,11 +20,11 @@ package com.graphhopper.routing.ev;
 import com.graphhopper.util.Helper;
 
 /**
- * This enum defines the road access of an edge. Most edges are accessible from everyone but certain have restrictions
- * like accessible only for customers or when delivering.
+ * This enum defines the road access of an edge. Most edges are accessible from everyone and so the default value is
+ * YES. But some have restrictions like "accessible only for customers" or when delivering. Unknown tags will get the
+ * value OTHER. The NO value does not permit any access.
  */
 public enum RoadAccess {
-    // order is important here as we assume "smaller index" means "broader access"
     YES("yes"), DESTINATION("destination"), CUSTOMERS("customers"), DELIVERY("delivery"),
     FORESTRY("forestry"), AGRICULTURAL("agricultural"),
     PRIVATE("private"), OTHER("other"), NO("no");
diff --git a/core/src/main/java/com/graphhopper/routing/ev/RoadClass.java b/core/src/main/java/com/graphhopper/routing/ev/RoadClass.java
index 923d95628..827b0ceaf 100644
--- a/core/src/main/java/com/graphhopper/routing/ev/RoadClass.java
+++ b/core/src/main/java/com/graphhopper/routing/ev/RoadClass.java
@@ -19,7 +19,7 @@ package com.graphhopper.routing.ev;
 
 /**
  * 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.
+ * primary, cycleway etc. All edges that do not fit get OTHER as value.
  */
 public enum RoadClass {
     OTHER("other"), MOTORWAY("motorway"),
diff --git a/core/src/main/java/com/graphhopper/routing/ev/RouteNetwork.java b/core/src/main/java/com/graphhopper/routing/ev/RouteNetwork.java
index 7785f17d7..9c2a7fd63 100644
--- a/core/src/main/java/com/graphhopper/routing/ev/RouteNetwork.java
+++ b/core/src/main/java/com/graphhopper/routing/ev/RouteNetwork.java
@@ -19,10 +19,14 @@ package com.graphhopper.routing.ev;
 
 import com.graphhopper.util.Helper;
 
+/**
+ * This enum defines the route network of an edge when part of a hiking or biking network.
+ * If not tagged the value will be MISSING (default) and all edges that do not fit get OTHER as value.
+ */
 public enum RouteNetwork {
 
-    OTHER("other"), INTERNATIONAL("international"), NATIONAL("national"), REGIONAL("regional"),
-    LOCAL("local");
+    MISSING("missing"), INTERNATIONAL("international"), NATIONAL("national"), REGIONAL("regional"),
+    LOCAL("local"), OTHER("other");
 
     public static String key(String prefix) {
         return prefix + "_network";
@@ -41,11 +45,11 @@ public enum RouteNetwork {
 
     public static RouteNetwork find(String name) {
         if (Helper.isEmpty(name))
-            return OTHER;
+            return MISSING;
         try {
             return RouteNetwork.valueOf(Helper.toUpperCase(name));
         } catch (IllegalArgumentException ex) {
-            return OTHER;
+            return MISSING;
         }
     }
 }
diff --git a/core/src/main/java/com/graphhopper/routing/ev/Surface.java b/core/src/main/java/com/graphhopper/routing/ev/Surface.java
index fe7ff70f0..2252aa998 100644
--- a/core/src/main/java/com/graphhopper/routing/ev/Surface.java
+++ b/core/src/main/java/com/graphhopper/routing/ev/Surface.java
@@ -20,13 +20,17 @@ package com.graphhopper.routing.ev;
 import com.graphhopper.util.Helper;
 
 /**
- * This enum defines the road surface of an edge like unpaved or asphalt. If not tagged it will be "other".
+ * This enum defines the road surface of an edge like unpaved or asphalt. If not tagged the value will be MISSING, which
+ * the default and best surface value (as surface is currently often not tagged). All unknown surface tags will get
+ * OTHER (the worst surface).
  */
 public enum Surface {
-    MISSING("missing"), OTHER("other"),
+    // Order is important to make it roughly comparable
+    MISSING("missing"),
     PAVED("paved"), ASPHALT("asphalt"), CONCRETE("concrete"), PAVING_STONES("paving_stones"), COBBLESTONE("cobblestone"),
     UNPAVED("unpaved"), COMPACTED("compacted"), FINE_GRAVEL("fine_gravel"), GRAVEL("gravel"),
-    GROUND("ground"), DIRT("dirt"), GRASS("grass"), SAND("sand");
+    GROUND("ground"), DIRT("dirt"), GRASS("grass"), SAND("sand"),
+    OTHER("other");
 
     public static final String KEY = "surface";
 
diff --git a/core/src/main/java/com/graphhopper/routing/ev/TrackType.java b/core/src/main/java/com/graphhopper/routing/ev/TrackType.java
index ca1cf1c96..6421609b2 100644
--- a/core/src/main/java/com/graphhopper/routing/ev/TrackType.java
+++ b/core/src/main/java/com/graphhopper/routing/ev/TrackType.java
@@ -20,15 +20,15 @@ package com.graphhopper.routing.ev;
 import com.graphhopper.util.Helper;
 
 /**
- * This enum defines the track type of an edge which describes how
- * well-maintained a certain track is. All edges that do not fit get "other" as
- * value.
+ * This enum defines the track type of an edge which describes how well-maintained a certain track is.
+ * If not tagged the value will be MISSING (the default and easiest grad) and all edges that do not fit get OTHER as
+ * value (the worst grade).
  *
- * @see https://wiki.openstreetmap.org/wiki/Tracktype
+ * @see <a href="https://wiki.openstreetmap.org/wiki/Tracktype">Tracktype Wiki</a>
  */
 public enum TrackType {
-    MISSING("missing"), OTHER("other"), GRADE1("grade1"), GRADE2("grade2"),
-    GRADE3("grade3"), GRADE4("grade4"), GRADE5("grade5");
+    MISSING("missing"), GRADE1("grade1"), GRADE2("grade2"),
+    GRADE3("grade3"), GRADE4("grade4"), GRADE5("grade5"), OTHER("other");
 
     public static final String KEY = "track_type";
 
diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/OSMBikeNetworkTagParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/OSMBikeNetworkTagParser.java
index 703345dc9..b1839bb3b 100644
--- a/core/src/main/java/com/graphhopper/routing/util/parsers/OSMBikeNetworkTagParser.java
+++ b/core/src/main/java/com/graphhopper/routing/util/parsers/OSMBikeNetworkTagParser.java
@@ -55,7 +55,7 @@ public class OSMBikeNetworkTagParser implements RelationTagParser {
             } else if ("icn".equals(tag)) {
                 newBikeNetwork = RouteNetwork.INTERNATIONAL;
             }
-            if (oldBikeNetwork == RouteNetwork.OTHER || oldBikeNetwork.ordinal() > newBikeNetwork.ordinal())
+            if (oldBikeNetwork == RouteNetwork.MISSING || oldBikeNetwork.ordinal() > newBikeNetwork.ordinal())
                 transformerRouteRelEnc.setEnum(false, relFlags, newBikeNetwork);
         }
 
diff --git a/core/src/main/java/com/graphhopper/routing/util/parsers/OSMFootNetworkTagParser.java b/core/src/main/java/com/graphhopper/routing/util/parsers/OSMFootNetworkTagParser.java
index fa495502d..71609f9dc 100644
--- a/core/src/main/java/com/graphhopper/routing/util/parsers/OSMFootNetworkTagParser.java
+++ b/core/src/main/java/com/graphhopper/routing/util/parsers/OSMFootNetworkTagParser.java
@@ -55,7 +55,7 @@ public class OSMFootNetworkTagParser implements RelationTagParser {
             } else if ("iwn".equals(tag)) {
                 newFootNetwork = RouteNetwork.INTERNATIONAL;
             }
-            if (oldFootNetwork == RouteNetwork.OTHER || oldFootNetwork.ordinal() > newFootNetwork.ordinal())
+            if (oldFootNetwork == RouteNetwork.MISSING || oldFootNetwork.ordinal() > newFootNetwork.ordinal())
                 transformerRouteRelEnc.setEnum(false, relFlags, newFootNetwork);
         }
 
diff --git a/core/src/main/java/com/graphhopper/util/Constants.java b/core/src/main/java/com/graphhopper/util/Constants.java
index 7eefc7396..7f012f9a7 100644
--- a/core/src/main/java/com/graphhopper/util/Constants.java
+++ b/core/src/main/java/com/graphhopper/util/Constants.java
@@ -67,7 +67,7 @@ public class Constants {
     private static final int JVM_MINOR_VERSION;
 
     public static final int VERSION_NODE = 5;
-    public static final int VERSION_EDGE = 16;
+    public static final int VERSION_EDGE = 17;
     public static final int VERSION_SHORTCUT = 6;
     public static final int VERSION_GEOMETRY = 4;
     public static final int VERSION_LOCATION_IDX = 3;


Test patch:
diff --git a/core/src/test/java/com/graphhopper/routing/util/EncodingManagerTest.java b/core/src/test/java/com/graphhopper/routing/util/EncodingManagerTest.java
index 8f29b530a..ec4e342b1 100644
--- a/core/src/test/java/com/graphhopper/routing/util/EncodingManagerTest.java
+++ b/core/src/test/java/com/graphhopper/routing/util/EncodingManagerTest.java
@@ -129,7 +129,7 @@ public class EncodingManagerTest {
         BikeFlagEncoder lessRelationCodes = new BikeFlagEncoder() {
             @Override
             public IntsRef handleWayTags(IntsRef edgeFlags, ReaderWay way, EncodingManager.Access access) {
-                if (bikeRouteEnc.getEnum(false, edgeFlags) != RouteNetwork.OTHER)
+                if (bikeRouteEnc.getEnum(false, edgeFlags) != RouteNetwork.MISSING)
                     priorityEnc.setDecimal(false, edgeFlags, PriorityCode.getFactor(2));
                 return edgeFlags;
             }