changeset 8756:26dedebbe39f

(issue1801) Code cleanups Remove one indirecton level around RiverUtils.getGauge and remove the old and now unused determineGauge method.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 24 Jun 2015 15:49:23 +0200
parents 30b1ddadf275
children bd17bd07db69
files artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java backend/src/main/java/org/dive4elements/river/model/River.java
diffstat 4 files changed, 7 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java	Wed Jun 24 14:07:26 2015 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java	Wed Jun 24 15:49:23 2015 +0200
@@ -319,7 +319,7 @@
             return error(null, "no.river.selected");
         }
 
-        Gauge g = getGauge();
+        Gauge g = RiverUtils.getGauge(this);
 
         if (g == null) {
            return error(null, "no.gauge.selected");
@@ -859,18 +859,6 @@
 
 
     /**
-     * Returns the gauge based on the current distance and river.
-     *
-     * @return the gauge.
-     */
-    public Gauge getGauge() {
-        return RiverUtils.getGauge(this);
-    }
-
-
-
-
-    /**
      * This method returns the Q values.
      *
      * @return the selected Q values or null, if no Q values are selected.
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java	Wed Jun 24 14:07:26 2015 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java	Wed Jun 24 15:49:23 2015 +0200
@@ -178,7 +178,7 @@
         NumberFormat nf = NumberFormat.getInstance(
             Resources.getLocale(cc.getMeta()));
 
-        Gauge gauge = winfo.getGauge();
+        Gauge gauge = RiverUtils.getGauge(winfo);
 
         boolean debug = log.isDebugEnabled();
 
@@ -401,7 +401,7 @@
     protected double[] determineMinMaxW(Artifact artifact) {
         log.debug("WQSelect.determineCurrentGauge");
 
-        Gauge    gauge   = ((WINFOArtifact) artifact).getGauge();
+        Gauge    gauge   = RiverUtils.getGauge((WINFOArtifact) artifact);
         double[] minmaxW = gauge != null ? gauge.determineMinMaxW() : null;
 
         double minW = minmaxW != null ? minmaxW[0] : Double.MIN_VALUE;
@@ -461,7 +461,7 @@
         WINFOArtifact flysArtifact = (WINFOArtifact) artifact;
 
         River river = RiverUtils.getRiver(flysArtifact);
-        Gauge gauge = flysArtifact.getGauge();
+        Gauge gauge = RiverUtils.getGauge(flysArtifact);
         Wst   wst   = WstFactory.getWst(river);
 
         double[] minmaxQ = gauge != null
--- a/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Wed Jun 24 14:07:26 2015 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java	Wed Jun 24 15:49:23 2015 +0200
@@ -524,7 +524,7 @@
         try {
             v = Double.valueOf(parts[1]);
 
-            namedMainValue = getNamedMainValue(winfo.getGauge(), v);
+            namedMainValue = getNamedMainValue(getGauge(winfo), v);
         }
         catch (NumberFormatException nfe) {
             log.warn("Cannot parse Double of: '" + parts[1] + "'");
@@ -566,7 +566,7 @@
         try {
             v = Double.valueOf(parts[1]);
 
-            namedMainValue = getNamedMainValue(winfo.getGauge(), v);
+            namedMainValue = getNamedMainValue(getGauge(winfo), v);
         }
         catch (NumberFormatException nfe) {
             log.warn("Cannot parse Double of: '" + parts[1] + "'");
@@ -605,7 +605,7 @@
             return null;
         }
         else {
-            return getNamedMainValue(winfo.getGauge(), value);
+            return getNamedMainValue(getGauge(winfo), value);
         }
     }
 
--- a/backend/src/main/java/org/dive4elements/river/model/River.java	Wed Jun 24 14:07:26 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/model/River.java	Wed Jun 24 15:49:23 2015 +0200
@@ -356,39 +356,6 @@
         return minmax;
     }
 
-
-    /**
-     * This method returns the first gauge that is intersected by <i>a</i> and
-     * <i>b</i>, but which possibly does not ends with a or starts with b.
-     *
-     * @param a A start point.
-     * @param b An end point.
-     *
-     * @return the first intersecting gauge that does not border with a or b,
-     * the first intersecting gauge if that is impossible.
-     */
-    public Gauge determineGauge(double a, double b) {
-        List<Gauge> gauges = determineGauges(a, b);
-
-        if (a > b) {
-            for (int i = gauges.size() - 1; i >= 0; i--) {
-                Gauge g = gauges.get(i);
-                if (KM_CMP.compare(g.getRange().getA().doubleValue(), a) == 0)
-                    continue;
-                return g;
-            }
-        }
-
-        for (Gauge g: gauges) {
-            if (KM_CMP.compare(g.getRange().getB().doubleValue(), a) == 0) {
-                continue;
-            }
-            return g;
-        }
-
-        return null;
-    }
-
     /**
      * Determine reference gauge dependent on direction of calculation
      * for a range calculation, otherwise dependent on flow direction.

http://dive4elements.wald.intevation.org