diff artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQ.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQ.java@bd047b71ab37
children 4897a58c8746
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/model/WQ.java	Thu Apr 25 15:23:37 2013 +0200
@@ -0,0 +1,104 @@
+package org.dive4elements.river.artifacts.model;
+
+import org.dive4elements.river.utils.DoubleUtil;
+
+import gnu.trove.TDoubleArrayList;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.log4j.Logger;
+
+public class WQ
+extends      W
+{
+    public static final Pattern NUMBERS_PATTERN =
+        Pattern.compile("\\D*(\\d++.\\d*)\\D*");
+
+    private static Logger log = Logger.getLogger(WQ.class);
+
+    protected TDoubleArrayList qs;
+
+    public WQ() {
+        this("");
+    }
+
+    public WQ(String name) {
+        super(name);
+        qs = new TDoubleArrayList();
+    }
+
+    public WQ(int capacity) {
+        this(capacity, "");
+    }
+
+
+    public WQ(int capacity, String name) {
+        super(capacity, name);
+        qs = new TDoubleArrayList(capacity);
+    }
+
+    public WQ(double [] qs, double [] ws) {
+        this(qs, ws, "");
+    }
+
+    public WQ(double [] qs, double [] ws, String name) {
+        super(name);
+        this.ws = new TDoubleArrayList(ws);
+        this.qs = new TDoubleArrayList(qs);
+    }
+
+
+    public Double getRawValue() {
+        if (name == null || name.length() == 0) {
+            // this should never happen
+            return null;
+        }
+
+        Matcher m = NUMBERS_PATTERN.matcher(name);
+
+        if (m.matches()) {
+            String raw = m.group(1);
+
+            try {
+                return Double.valueOf(raw);
+            }
+            catch (NumberFormatException nfe) {
+                // do nothing
+            }
+        }
+
+        return null;
+    }
+
+    public void add(double w, double q) {
+        ws.add(w);
+        qs.add(q);
+    }
+
+    public double getQ(int idx) {
+        return qs.getQuick(idx);
+    }
+
+    @Override
+    public double [] get(int idx) {
+        return get(idx, new double [2]);
+    }
+
+    @Override
+    public double [] get(int idx, double [] dst) {
+        dst[0] = ws.getQuick(idx);
+        dst[1] = qs.getQuick(idx);
+        return dst;
+    }
+
+    public double [] getQs() {
+        return qs.toNativeArray();
+    }
+
+    @Override
+    public void removeNaNs() {
+        DoubleUtil.removeNaNs(new TDoubleArrayList [] { ws, qs });
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org