diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/WithTags.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/WithTags.java index 2eb39ba8..f5808a77 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/WithTags.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/reader/WithTags.java @@ -30,19 +30,33 @@ public interface WithTags { return value.equals(getTag(key)); } - /** Returns true if the value for {@code key} is {@code value1} or {@code value2}. */ + /** + * Returns true if the value for {@code key} is {@code value1} or {@code value2}. + *

+ * Specialized version of {@link #hasTag(String, Object, Object, Object...)} for the most common use-case of small + * number of values to test against that avoids allocating an array. + */ default boolean hasTag(String key, Object value1, Object value2) { Object actual = getTag(key); - return value1.equals(actual) || value2.equals(actual); + if (actual == null) { + return false; + } else { + return value1.equals(actual) || value2.equals(actual); + } } - /** Returns true if the value for {@code key} is {@code value1} or {@code value2}. */ - default boolean hasTag(String key, Object... values) { + /** Returns true if the value for {@code key} is equal to any one of the values. */ + default boolean hasTag(String key, Object value1, Object value2, Object... others) { Object actual = getTag(key); - for (Object value : values) { - if (value.equals(actual)) { + if (actual != null) { + if (value1.equals(actual) || value2.equals(actual)) { return true; } + for (Object value : others) { + if (value.equals(actual)) { + return true; + } + } } return false; }