From 286265cbc72ca7c72fa773129ba830be36a7e01e Mon Sep 17 00:00:00 2001 From: aoles Date: Wed, 5 Oct 2022 13:30:25 +0200 Subject: [PATCH] Methods for handling OSM tags containing enumerations --- .../com/graphhopper/reader/ReaderElement.java | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/graphhopper/reader/ReaderElement.java b/core/src/main/java/com/graphhopper/reader/ReaderElement.java index d94b27c3e2e..7b59503cf1f 100644 --- a/core/src/main/java/com/graphhopper/reader/ReaderElement.java +++ b/core/src/main/java/com/graphhopper/reader/ReaderElement.java @@ -103,6 +103,19 @@ public String getTag(String name) { return (String) properties.get(name); } + // ORS-GH MOD START - account for enumerations of multiple values + public String [] getTagValues(String name) { + String tagValue = getTag(name); + if (tagValue==null) + return new String[0]; + + String [] tagValues = {tagValue}; + if (tagValue.contains(";")) + tagValues = tagValue.split(";"); + return tagValues; + } + // ORS-GH MOD END + @SuppressWarnings("unchecked") public T getTag(String key, T defaultValue) { T val = (T) properties.get(key); @@ -146,7 +159,14 @@ public boolean hasTag(String key, String... values) { * Check that a given tag has one of the specified values. */ public final boolean hasTag(String key, Set values) { - return values.contains(getTag(key, "")); + // ORS-GH MOD START - account for enumerations of multiple values + String [] tagValues = getTagValues(key); + for (String tagValue: tagValues) { + if (values.contains(tagValue)) + return true; + } + return false; + // ORS-GH MOD END } /** @@ -155,7 +175,10 @@ public final boolean hasTag(String key, Set values) { */ public boolean hasTag(List keyList, Set values) { for (String key : keyList) { - if (values.contains(getTag(key, ""))) + // ORS-GH MOD START + //if (values.contains(getTag(key, ""))) + if (hasTag(key, values)) + // ORS-GH MOD END return true; } return false; @@ -172,6 +195,17 @@ public String getFirstPriorityTag(List restrictions) { return ""; } + // ORS-GH MOD START - account for enumerations of multiple values + public String [] getFirstPriorityTagValues(List restrictions) { + String [] empty = {}; + for (String str : restrictions) { + if (hasTag(str)) + return getTagValues(str); + } + return empty; + } + // ORS-GH MOD END + public void removeTag(String name) { properties.remove(name); }