From 4b422c1f3f099edbed3d0c42e9e5b3f0987beb9b Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Sat, 2 Nov 2024 07:53:02 -0400 Subject: [PATCH] sonar warnings --- .../custommap/expression/ConfigExpressionScript.java | 2 +- .../custommap/expression/stdlib/GeometryVal.java | 10 ++++++++++ .../expression/stdlib/PlanetilerTypeRegistry.java | 11 +++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/ConfigExpressionScript.java b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/ConfigExpressionScript.java index d90adea8e0..31f63c4d98 100644 --- a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/ConfigExpressionScript.java +++ b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/ConfigExpressionScript.java @@ -100,7 +100,7 @@ public static ConfigExpressionScript parse( */ public static ConfigExpressionScript parse(String string, ScriptEnvironment description, Class expected) { - var scriptHost = ScriptHost.newBuilder().registry(PlanetilerTypeRegistry.INSTANCE) + var scriptHost = ScriptHost.newBuilder().registry(new PlanetilerTypeRegistry()) .build(); try { var scriptBuilder = scriptHost.buildScript(string).withLibraries( diff --git a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/stdlib/GeometryVal.java b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/stdlib/GeometryVal.java index 133e384aed..3e904853c4 100644 --- a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/stdlib/GeometryVal.java +++ b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/stdlib/GeometryVal.java @@ -117,4 +117,14 @@ public Val get(Val index) { return Err.newErr(err, "Error getting %s", fieldName); } } + + @Override + public final boolean equals(Object o) { + return this == o || (o instanceof GeometryVal val && val.geometry.equals(geometry)); + } + + @Override + public int hashCode() { + return geometry.hashCode(); + } } diff --git a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/stdlib/PlanetilerTypeRegistry.java b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/stdlib/PlanetilerTypeRegistry.java index 70c58473d0..1df454c109 100644 --- a/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/stdlib/PlanetilerTypeRegistry.java +++ b/planetiler-custommap/src/main/java/com/onthegomap/planetiler/custommap/expression/stdlib/PlanetilerTypeRegistry.java @@ -13,8 +13,7 @@ import org.projectnessie.cel.common.types.ref.Val; /** Registers any types that are available to CEL expressions in planetiler configs. */ -public class PlanetilerTypeRegistry implements TypeRegistry { - public static final PlanetilerTypeRegistry INSTANCE = new PlanetilerTypeRegistry(); +public final class PlanetilerTypeRegistry implements TypeRegistry { @Override public TypeRegistry copy() { @@ -22,10 +21,14 @@ public TypeRegistry copy() { } @Override - public void register(Object t) {} + public void register(Object t) { + // types are defined statically + } @Override - public void registerType(Type... types) {} + public void registerType(Type... types) { + // types are defined statically + } @Override public Val nativeToValue(Object value) {