diff artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java @ 8755:30b1ddadf275

(issue1801) Unify reference gauge finding code The basic way as described in the method comment of the determineRefGauge method is now used in the WINFOArtifact, MainValuesService and RiverUtils.getGauge method. RiverUtils.getGauge previously just returned the first gauge found. While this is now a behavior change I believe that it is always more correct then the undeterministic behavior of the previous implmenentation.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 24 Jun 2015 14:07:26 +0200
parents 1655588ed479
children 26dedebbe39f
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Fri Jun 19 17:42:23 2015 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Wed Jun 24 14:07:26 2015 +0200
@@ -434,37 +434,19 @@
     /**
      * Return the (first) Gauge corresponding to the given location(s) of
      * the artifact.
+     *
+     * This method is left for compatibility. Use river.determineRefGauge()
+     * directly in new code.
+     *
      * @param flys the artifact in question.
-     * @return (First) gauge of locations of river of artifact.
+     * @return Reference / first gauge of locations of river of artifact.
      */
     public static Gauge getGauge(D4EArtifact flys) {
         River river = getRiver(flys);
-
-        if (river == null) {
-            log.debug("no river found");
-            return null;
-        }
-
         RangeAccess rangeAccess = new RangeAccess(flys);
         double[] dist = rangeAccess.getKmRange();
 
-        if (dist == null) {
-            log.debug("no range found");
-            return null;
-        }
-
-        if (log.isDebugEnabled()) {
-            log.debug("Determine gauge for:");
-            log.debug("... river: " + river.getName());
-            log.debug("... distance: " + dist[0] + " - " + dist[1]);
-        }
-
-        Gauge gauge = river.determineGauge(dist[0], dist[1]);
-
-        String name = gauge != null ? gauge.getName() : "'n/a";
-        log.debug("Found gauge: " + name);
-
-        return gauge;
+        return river.determineRefGauge(dist, rangeAccess.isRange());
     }
 
 

http://dive4elements.wald.intevation.org