[PATCH] Reduce code duplication

Wald Commits scm-commit at wald.intevation.org
Thu Nov 10 18:31:02 CET 2022


# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1668100585 -3600
#      Thu Nov 10 18:16:25 2022 +0100
# Branch 3.2.x
# Node ID c088f7a5797d961df36f2c953d05145ed713c640
# Parent  9bbb29142ddb3edfb6582f99a7f3ffc89150e85e
Reduce code duplication

RiverUtils.getValueFromWQ(wq) was equivalent to wq.getRawValue().

diff -r 9bbb29142ddb -r c088f7a5797d artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java	Thu Nov 10 15:42:16 2022 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java	Thu Nov 10 18:16:25 2022 +0100
@@ -638,7 +638,7 @@
                     winfo, wqkms.getRawValue());
                 // For 'W am Pegel' s
                 if (colDesc == null) {
-                    Double value = RiverUtils.getValueFromWQ(wqkms);
+                    Double value = wqkms.getRawValue();
                     colDesc = (value != null) ?
                         Formatter.getWaterlevelW(context).format(value) : null;
                 }
diff -r 9bbb29142ddb -r c088f7a5797d artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java
--- a/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Thu Nov 10 15:42:16 2022 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Thu Nov 10 18:16:25 2022 +0100
@@ -20,7 +20,6 @@
 import org.dive4elements.river.artifacts.model.LocationProvider;
 import org.dive4elements.river.artifacts.model.RiverFactory;
 import org.dive4elements.river.artifacts.model.WKms;
-import org.dive4elements.river.artifacts.model.WQ;
 import org.dive4elements.river.artifacts.states.WDifferencesState;
 import org.dive4elements.river.artifacts.states.WaterlevelSelectState;
 import org.dive4elements.river.backend.SessionFactoryProvider;
@@ -38,8 +37,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 import javax.xml.xpath.XPathConstants;
 
@@ -82,9 +79,6 @@
      */
     public static enum WQ_INPUT { ADAPTED, SINGLE, RANGE, NONE };
 
-    public static final Pattern NUMBERS_PATTERN =
-        Pattern.compile("\\D*(\\d++.\\d*)\\D*");
-
     public static final String XPATH_FLOODMAP_RIVER_PROJECTION =
         "/artifact-database/floodmap/river[@name=$name]/srid/@value";
 
@@ -448,29 +442,6 @@
     }
 
 
-    public static Double getValueFromWQ(WQ wq) {
-        if (wq == null) {
-            return null;
-        }
-
-        Matcher m = NUMBERS_PATTERN.matcher(wq.getName());
-
-        if (m.matches()) {
-            log.debug("Found a number.");
-
-            String raw = m.group(1);
-
-            try {
-                return Double.valueOf(raw);
-            }
-            catch (NumberFormatException nfe) {
-            }
-        }
-
-        return null;
-    }
-
-
     /** Creates human-readable name for a wsp (waterlevel/longitudinal section).
      * @param name will be split at '='s.
      */


More information about the Dive4Elements-commits mailing list