diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/GaugeMainValueFinder.java @ 9533:d9fda7af24ca

No discharge zone calculation and output for gauges unknown in flys for sinfo collision (Meilenstein 2, 2.2.1)
author mschaefer
date Thu, 04 Oct 2018 12:48:57 +0200
parents b38be7ea53e2
children 0c114309d2a0
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/GaugeMainValueFinder.java	Tue Oct 02 18:19:44 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/GaugeMainValueFinder.java	Thu Oct 04 12:48:57 2018 +0200
@@ -17,6 +17,7 @@
 import org.dive4elements.river.model.Gauge;
 import org.dive4elements.river.model.MainValue;
 import org.dive4elements.river.model.MainValueType.MainValueTypeKey;
+import org.dive4elements.river.model.River;
 
 /**
  * Loading the main values of a gauge to find relative positions of a value and build a corresponding zone name
@@ -49,15 +50,17 @@
 
     /***** CONSTRUCTORS *****/
 
-    private GaugeMainValueFinder(final MainValueTypeKey keyType, final Gauge gauge, final Calculation problems) {
+    private GaugeMainValueFinder(final MainValueTypeKey keyType, final Gauge gauge, final String gaugeName, final Calculation problems) {
         this.gauge = gauge;
         this.problems = problems;
         this.keyType = keyType;
         this.mainValues = new TreeMap<>();
-        for (final MainValue mainValue : MainValue.getValuesOfGaugeAndType(gauge, keyType))
-            this.mainValues.put(Double.valueOf(mainValue.getValue().doubleValue()), mainValue);
+        if (gauge != null) {
+            for (final MainValue mainValue : MainValue.getValuesOfGaugeAndType(gauge, keyType))
+                this.mainValues.put(Double.valueOf(mainValue.getValue().doubleValue()), mainValue);
+        }
         if (this.mainValues.isEmpty() && (this.problems != null)) {
-            this.problems.addProblem("gauge_main_values.missing", gauge.getName());
+            this.problems.addProblem("gauge_main_values.missing", gaugeName);
             // Report only once
             this.problems = null;
         }
@@ -67,12 +70,22 @@
     /***** METHODS *****/
 
     /**
-     * Loads the the main values table of a type and a gauge (GAUGE.sta)
+     * Loads the the main values table of a type and a gauge ({gauge}.sta)
      *
      * @return The main values finder of a type and a gauge, or null
      */
     public static GaugeMainValueFinder loadValues(final MainValueTypeKey type, final Gauge gauge, final Calculation problems) {
-        return new GaugeMainValueFinder(type, gauge, problems);
+        return new GaugeMainValueFinder(type, gauge, gauge.getName(), problems);
+    }
+
+    /**
+     * Loads the the main values table of a type and a river's gauge ({gauge}.sta)
+     *
+     * @return The main values finder of the type and gauge, or null
+     */
+    public static GaugeMainValueFinder loadValues(final MainValueTypeKey type, final River river, final String gaugeName, final Calculation problems) {
+        final Gauge gauge = river.determineGaugeByName(gaugeName);
+        return new GaugeMainValueFinder(type, gauge, gaugeName, problems);
     }
 
     /**

http://dive4elements.wald.intevation.org