diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 655:913b52064449

Refactored version of "Berechnung 4" flys-artifacts/trunk@2053 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 05 Jun 2011 18:24:46 +0000
parents 6695e03e9b82
children ed7c901ee712
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Fri Jun 03 10:21:13 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Sun Jun 05 18:24:46 2011 +0000
@@ -33,6 +33,8 @@
 import de.intevation.artifactdatabase.state.StateEngine;
 import de.intevation.artifactdatabase.transition.TransitionEngine;
 
+import de.intevation.flys.utils.DoubleUtil;
+
 import de.intevation.flys.model.Gauge;
 import de.intevation.flys.model.Range;
 import de.intevation.flys.model.River;
@@ -79,8 +81,6 @@
     /** The default step width between the start end end kilometer.*/
     public static final double DEFAULT_KM_STEPS = 0.1;
 
-    public static final double DEFAULT_PRECISION = 1e6;
-
 
     /** The identifier of the current state. */
     protected String currentStateId;
@@ -611,6 +611,36 @@
         }
     }
 
+    public double [] getFromToStep() {
+        if (!isRange()) {
+            return null;
+        }
+        double [] fromTo = getDistance();
+
+        if (fromTo == null) {
+            return null;
+        }
+
+        StateData dStep = getData("ld_step");
+        if (dStep == null) {
+            return null;
+        }
+
+        double [] result = new double[3];
+        result[0] = fromTo[0];
+        result[1] = fromTo[1];
+
+        try {
+            String step = (String)dStep.getValue();
+            result[2] = DoubleUtil.round(Double.parseDouble(step) / 1000d);
+        }
+        catch (NumberFormatException nfe) {
+            return null;
+        }
+
+        return result;
+    }
+
 
     /**
      * Returns the gauge based on the current distance and river.
@@ -967,36 +997,9 @@
         double to, 
         double step
     ) {
-        return getExplodedValues(from, to, step, DEFAULT_PRECISION);
+        return DoubleUtil.explode(from, to, step);
     }
 
-    public static double[] getExplodedValues(
-        double from, 
-        double to, 
-        double step,
-        double precision
-    ) {
-        double lower = from;
-
-        double diff = to - from;
-        double tmp  = diff / step;
-        int    num = (int)Math.abs(Math.ceil(tmp)) + 1;
-
-        double [] values = new double[num];
-
-        if (from > to) {
-            step = -step;
-        }
-
-        for (int idx = 0; idx < num; idx++) {
-            values[idx] = Math.round(lower * precision)/precision;
-            lower      += step;
-        }
-
-        return values;
-    }
-
-
     /**
      * Method to dump the artifacts state/data.
      */

http://dive4elements.wald.intevation.org