[PATCH] (issue1801) Code cleanups

Wald Commits scm-commit at wald.intevation.org
Wed Jun 24 15:49:27 CEST 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1435153763 -7200
# Node ID 26dedebbe39f0ecdd16c7b3bd29042465111ec7f
# Parent  30b1ddadf2754494a45ac56308132e84b263dcb6
(issue1801) Code cleanups

    Remove one indirecton level around RiverUtils.getGauge and remove
    the old and now unused determineGauge method.

diff -r 30b1ddadf275 -r 26dedebbe39f artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java
--- 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.
diff -r 30b1ddadf275 -r 26dedebbe39f artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java
--- 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
diff -r 30b1ddadf275 -r 26dedebbe39f artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java
--- 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);
         }
     }
 
diff -r 30b1ddadf275 -r 26dedebbe39f backend/src/main/java/org/dive4elements/river/model/River.java
--- 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.


More information about the Dive4Elements-commits mailing list