changeset 8562:c62837ba37f3

(issue1755) Move KM Step handling from Winfo artifact to RangeAccess
author Andre Heinecke <andre.heinecke@intevation.de>
date Mon, 16 Feb 2015 15:58:52 +0100
parents 2b3c8ea6cbee
children 59b4f6cf1cf4
files artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java
diffstat 2 files changed, 23 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java	Mon Feb 16 12:12:12 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java	Mon Feb 16 15:58:52 2015 +0100
@@ -85,9 +85,6 @@
      * range. */
     public static final int DEFAULT_Q_STEPS = 30;
 
-    /** The default step width between the start end end kilometer. */
-    public static final double DEFAULT_KM_STEPS = 0.1;
-
     private static final String [] INACTIVES = new String[] {
         LONGITUDINAL_Q,
         DURATION_Q,
@@ -823,42 +820,12 @@
     /**
      * Returns the selected Kms.
      *
-     * @param distance An 2dim array with [lower, upper] values.
-     *
-     * @return the selected Kms.
-     */
-    public double[] getKms(double[] distance) {
-        StateData dStep = getData("ld_step");
-
-        if (dStep == null) {
-            log.warn("No step width given. Cannot compute Kms.");
-            return null;
-        }
-
-        double step = Double.parseDouble((String) dStep.getValue());
-
-        // transform step from 'm' into 'km'
-        step = step / 1000;
-
-        if (step == 0d) {
-            step = DEFAULT_KM_STEPS;
-        }
-
-        return DoubleUtil.explode(distance[0], distance[1], step);
-    }
-
-
-    /**
-     * Returns the selected Kms.
-     *
      * @return the selected kms.
      */
     public double[] getKms() {
         if (isRange()) {
             RangeAccess rangeAccess = new RangeAccess(this);
-            double [] distance = rangeAccess.getKmRange();
-            return getKms(distance);
-
+            return rangeAccess.getKmSteps();
         }
         else {
             return LocationDistanceSelect.getLocations(this);
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java	Mon Feb 16 12:12:12 2015 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java	Mon Feb 16 15:58:52 2015 +0100
@@ -16,6 +16,7 @@
 import org.dive4elements.river.artifacts.WINFOArtifact;
 
 import org.dive4elements.river.utils.RiverUtils;
+import org.dive4elements.river.utils.DoubleUtil;
 
 
 /** For the moment, light-weight wrapper around RiverUtils. */
@@ -27,6 +28,9 @@
 
     public static enum KM_MODE { RANGE, LOCATIONS, NONE };
 
+    /** The default step width between the start end end kilometer. */
+    public static final double DEFAULT_KM_STEPS = 0.1;
+
     double[] kmRange;
 
     Double from;
@@ -214,5 +218,23 @@
     public double[] getKmFromTo() {
          return RiverUtils.getKmFromTo(this.getArtifact());
     }
+
+    /**
+     * Returns the selected Kms in steps as specified.
+     *
+     * @return Each step for this range.
+     */
+    public double[] getKmSteps() {
+        double step = getStep();
+
+        // transform step from 'm' into 'km'
+        step = step / 1000;
+
+        if (step == 0d) {
+            step = DEFAULT_KM_STEPS;
+        }
+
+        return DoubleUtil.explode(getFrom(), getTo(), step);
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org