Skip to content

Commit

Permalink
Merge pull request #57 from GIScience/fix/multiple_vehicle_access_res…
Browse files Browse the repository at this point in the history
…trictions

Methods for handling OSM tags containing enumerations
  • Loading branch information
takb authored Feb 23, 2023
2 parents 74aba0c + 286265c commit 4d3c5e7
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions core/src/main/java/com/graphhopper/reader/ReaderElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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> T getTag(String key, T defaultValue) {
T val = (T) properties.get(key);
Expand Down Expand Up @@ -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<String> 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
}

/**
Expand All @@ -155,7 +175,10 @@ public final boolean hasTag(String key, Set<String> values) {
*/
public boolean hasTag(List<String> keyList, Set<String> 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;
Expand All @@ -172,6 +195,17 @@ public String getFirstPriorityTag(List<String> restrictions) {
return "";
}

// ORS-GH MOD START - account for enumerations of multiple values
public String [] getFirstPriorityTagValues(List<String> 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);
}
Expand Down

0 comments on commit 4d3c5e7

Please sign in to comment.