diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java @ 1033:821aaceb2776

Fix for flys/issue191 flys-artifacts/trunk@2494 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 15 Aug 2011 10:56:58 +0000
parents 659608128823
children 03fbf1b30e72
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java	Fri Aug 12 12:54:19 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java	Mon Aug 15 10:56:58 2011 +0000
@@ -4,9 +4,13 @@
 
 import java.util.Random;
 
+import org.apache.log4j.Logger;
+
 public class WQ
 extends      NamedObjectImpl
 {
+    private static Logger logger = Logger.getLogger(WQ.class);
+
     // TODO: s/w/ws/g
     protected TDoubleArrayList w;
 
@@ -135,5 +139,53 @@
         return up > samples/2;
     }
 
+    public int [] longestIncreasingWRangeIndices() {
+        return longestIncreasingWRangeIndices(new int[2]);
+    }
+
+    public int [] longestIncreasingWRangeIndices(int [] bounds) {
+
+        int N = size();
+        int start = 0;
+        int stop  = 0;
+
+        double lastW = Double.MAX_VALUE;
+
+        for (int i = 0; i < N; ++i) {
+            double v = w.getQuick(i);
+            if (v <= lastW) {
+                if (stop-start > bounds[1]-bounds[0]) {
+                    bounds[0] = start;
+                    bounds[1] = stop;
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("new range: " +
+                            bounds[0] + " - " + bounds[1] + " (" +
+                            w.getQuick(bounds[0]) + ", " +
+                            w.getQuick(bounds[1]) + ")");
+
+                    }
+                }
+                start = stop = i;
+            }
+            else {
+                stop = i;
+            }
+            lastW = v;
+        }
+
+        if (stop-start > bounds[1]-bounds[0]) {
+            bounds[0] = start;
+            bounds[1] = stop;
+            if (logger.isDebugEnabled()) {
+                logger.debug("new range @end: " +
+                    bounds[0] + " - " + bounds[1] + " (" +
+                    w.getQuick(bounds[0]) + ", " +
+                    w.getQuick(bounds[1]) + ")");
+
+            }
+        }
+
+        return bounds;
+    }
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org