diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java @ 1672:0b6dac664bbb

Moved some generic double array code from BackjumpCorrector to DoubleUtil flys-artifacts/trunk@2885 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 04 Oct 2011 15:29:39 +0000
parents c09c9e05ecfa
children b5209452f6bb
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java	Tue Oct 04 15:23:31 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java	Tue Oct 04 15:29:39 2011 +0000
@@ -17,6 +17,8 @@
 
 import de.intevation.flys.artifacts.model.Calculation;
 
+import de.intevation.flys.utils.DoubleUtil;
+
 public class BackJumpCorrector
 implements   Serializable
 {
@@ -47,23 +49,23 @@
         double []   ws,
         Calculation errors
     ) {
-        boolean wsUp = isIncreasing(ws);
+        boolean wsUp = DoubleUtil.isIncreasing(ws);
 
         if (wsUp) {
-            km = swapClone(km);
-            ws = swapClone(ws);
+            km = DoubleUtil.swapClone(km);
+            ws = DoubleUtil.swapClone(ws);
         }
 
-        boolean kmUp = isIncreasing(km);
+        boolean kmUp = DoubleUtil.isIncreasing(km);
 
         if (!kmUp) {
-            km = sumDiffs(km);
+            km = DoubleUtil.sumDiffs(km);
         }
 
         if (log.isDebugEnabled()) {
             log.debug("BackJumpCorrector.doCorrection ------- enter");
-            log.debug("  km increasing: " + isIncreasing(km));
-            log.debug("  ws increasing: " + isIncreasing(ws));
+            log.debug("  km increasing: " + DoubleUtil.isIncreasing(km));
+            log.debug("  ws increasing: " + DoubleUtil.isIncreasing(ws));
             log.debug("BackJumpCorrector.doCorrection ------- leave");
         }
 
@@ -71,7 +73,7 @@
 
         if (hasBackJumps && wsUp) {
             // mirror back
-            swap(corrected);
+            DoubleUtil.swap(corrected);
         }
 
         return hasBackJumps;
@@ -245,56 +247,5 @@
 
         return !backjumps.isEmpty();
     }
-
-    public static final boolean isIncreasing(double [] array) {
-        int inc = 0;
-        int dec = 0;
-        int sweet = (array.length-1)/2;
-        for (int i = 1; i < array.length; ++i) {
-            if (array[i] > array[i-1]) {
-                if (++inc > sweet) {
-                    return true;
-                }
-            }
-            else if (++dec > sweet) {
-                return false;
-            }
-        }
-        return inc > sweet;
-    }
-
-    public static final double [] swap(double [] array) {
-        int lo = 0;
-        int hi = array.length-1;
-        while (hi > lo) {
-            double t  = array[lo];
-            array[lo] = array[hi];
-            array[hi] = t;
-            ++lo;
-            --hi;
-        }
-
-        return array;
-    }
-
-    public static final double [] swapClone(double [] in) {
-        double [] out = new double[in.length];
-
-        for (int j = out.length-1, i = 0; j >= 0;) {
-            out[j--] = in[i++];
-        }
-
-        return out;
-    }
-
-    public static final double [] sumDiffs(double [] in) {
-        double [] out = new double[in.length];
-
-        for (int i = 1; i < out.length; ++i) {
-            out[i] = out[i-1] + Math.abs(in[i-1] - in[i]);
-        }
-
-        return out;
-    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org