Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
wipfli committed Feb 26, 2025
1 parent a5512ac commit 6374d37
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
28 changes: 26 additions & 2 deletions tiles/src/main/java/com/protomaps/basemap/feature/Matcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static String getString(SourceFeature sf, List<Map<String, Object>> match
if (value instanceof String stringValue) {
return stringValue;
} else if (value instanceof FromTag fromTag) {
return sf.getString(fromTag.key);
return sf.getString(fromTag.key, defaultValue);
} else {
return defaultValue;
}
Expand All @@ -72,7 +72,31 @@ public static Integer getInteger(SourceFeature sf, List<Map<String, Object>> mat
if (value instanceof Integer integerValue) {
return integerValue;
} else if (value instanceof FromTag fromTag) {
return Integer.valueOf(sf.getString(fromTag.key, String.valueOf(defaultValue)));
try {
return sf.hasTag(fromTag.key) ? Integer.valueOf(sf.getString(fromTag.key)) : defaultValue;
} catch (NumberFormatException e) {
return defaultValue;
}
} else {
return defaultValue;
}
}
}
return defaultValue;
}

public static Double getDouble(SourceFeature sf, List<Map<String, Object>> matches, String key, Double defaultValue) {
for (var match : matches.reversed()) {
if (match.containsKey(key)) {
Object value = match.get(key);
if (value instanceof Double doubleValue) {
return doubleValue;
} else if (value instanceof FromTag fromTag) {
try {
return sf.hasTag(fromTag.key) ? Double.valueOf(sf.getString(fromTag.key)) : defaultValue;
} catch (NumberFormatException e) {
return defaultValue;
}
} else {
return defaultValue;
}
Expand Down
5 changes: 3 additions & 2 deletions tiles/src/main/java/com/protomaps/basemap/layers/Landuse.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.protomaps.basemap.layers;

import static com.protomaps.basemap.feature.Matcher.rule;
import static com.protomaps.basemap.feature.Matcher.fromTag;
import static com.protomaps.basemap.feature.Matcher.getString;
import static com.protomaps.basemap.feature.Matcher.rule;
import static com.protomaps.basemap.feature.Matcher.use;
import static com.protomaps.basemap.feature.Matcher.with;
import static com.protomaps.basemap.feature.Matcher.without;
Expand Down Expand Up @@ -62,7 +62,8 @@ public class Landuse implements ForwardingProfile.LayerPostProcessor {
use("kind", fromTag("military"))
),
rule(
with("leisure", "golf_course", "marina", "park", "stadium", "playground", "garden", "dog_park", "pitch", "nature_reserve"),
with("leisure", "golf_course", "marina", "park", "stadium", "playground", "garden", "dog_park", "pitch",
"nature_reserve"),
use("kind", fromTag("leisure"))
),
rule(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.protomaps.basemap.feature;

import static com.onthegomap.planetiler.TestUtils.newPoint;
import static com.protomaps.basemap.feature.Matcher.fromTag;
import static com.protomaps.basemap.feature.Matcher.getBoolean;
import static com.protomaps.basemap.feature.Matcher.getDouble;
import static com.protomaps.basemap.feature.Matcher.getInteger;
import static com.protomaps.basemap.feature.Matcher.getString;
import static com.protomaps.basemap.feature.Matcher.rule;
import static com.protomaps.basemap.feature.Matcher.use;
import static com.protomaps.basemap.feature.Matcher.with;
import static com.protomaps.basemap.feature.Matcher.without;
import static com.protomaps.basemap.feature.Matcher.getString;
import static com.protomaps.basemap.feature.Matcher.getInteger;
import static com.protomaps.basemap.feature.Matcher.getDouble;
import static com.protomaps.basemap.feature.Matcher.getBoolean;
import static com.protomaps.basemap.feature.Matcher.fromTag;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.onthegomap.planetiler.expression.Expression;
Expand Down Expand Up @@ -115,7 +115,7 @@ void testGetStringWithA() {
);
var matches = index.getMatches(sf);
assertEquals("d", getString(sf, matches, "b", "d"));

sf = SimpleFeature.create(
newPoint(0, 0),
Map.of("a", "something"),
Expand Down Expand Up @@ -522,5 +522,5 @@ void testGetBooleanFromTag() {
matches = index.getMatches(sf);
assertEquals(true, getBoolean(sf, matches, "a", false));
}

}

0 comments on commit 6374d37

Please sign in to comment.