[PATCH 32 of 45] (issue1755) Move KM Step handling from Winfo artifact to RangeAccess

Wald Commits scm-commit at wald.intevation.org
Tue Mar 10 17:06:00 CET 2015


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1424098732 -3600
# Node ID c62837ba37f313fc24d9e98b3d33215aa068b346
# Parent  2b3c8ea6cbee14fbaed6a81bbbcf3938d2d7fc25
(issue1755) Move KM Step handling from Winfo artifact to RangeAccess

diff -r 2b3c8ea6cbee -r c62837ba37f3 artifacts/src/main/java/org/dive4elements/river/artifacts/WINFOArtifact.java
--- 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);
diff -r 2b3c8ea6cbee -r c62837ba37f3 artifacts/src/main/java/org/dive4elements/river/artifacts/access/RangeAccess.java
--- 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 :


More information about the Dive4Elements-commits mailing list