comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java @ 726:cbaa3ca86f2f

Added base class WQ for WQKms. flys-artifacts/trunk@2216 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 23 Jun 2011 12:19:12 +0000
parents
children b385577bcaca
comparison
equal deleted inserted replaced
725:51afeced47de 726:cbaa3ca86f2f
1 package de.intevation.flys.artifacts.model;
2
3 import gnu.trove.TDoubleArrayList;
4
5 public class WQ
6 extends NamedObject
7 {
8 protected TDoubleArrayList w;
9
10 protected TDoubleArrayList q;
11
12 public WQ() {
13 this("");
14 }
15
16 public WQ(String name) {
17 w = new TDoubleArrayList();
18 q = new TDoubleArrayList();
19 }
20
21 public WQ(int capacity) {
22 this(capacity, "");
23 }
24
25
26 public WQ(int capacity, String name) {
27 super(name);
28 w = new TDoubleArrayList(capacity);
29 q = new TDoubleArrayList(capacity);
30 }
31
32 public WQ(double [] qs, double [] ws) {
33 this(qs, ws, "");
34 }
35
36 public WQ(double [] qs, double [] ws, String name) {
37 super(name);
38 w = new TDoubleArrayList(ws);
39 q = new TDoubleArrayList(qs);
40 }
41
42 public void add(double w, double q) {
43 this.w.add(w);
44 this.q.add(q);
45 }
46
47 public int size() {
48 return w.size();
49 }
50
51 public double getW(int idx) {
52 return w.getQuick(idx);
53 }
54
55 public double getQ(int idx) {
56 return q.getQuick(idx);
57 }
58
59 public double [] get(int idx) {
60 return get(idx, new double [2]);
61 }
62
63 public double [] get(int idx, double [] dst) {
64 dst[0] = w.getQuick(idx);
65 dst[1] = q.getQuick(idx);
66 return dst;
67 }
68
69 public double [] getWs() {
70 return w.toNativeArray();
71 }
72
73 public double [] getQs() {
74 return q.toNativeArray();
75 }
76
77 public static void removeNaNs(TDoubleArrayList [] arrays) {
78
79 int dest = 0;
80
81 int A = arrays.length;
82 int N = arrays[0].size();
83
84 OUTER: for (int i = 0; i < N; ++i) {
85 for (int j = 0; j < A; ++j) {
86 TDoubleArrayList a = arrays[j];
87 double v = a.getQuick(i);
88 if (Double.isNaN(v)) {
89 continue OUTER;
90 }
91 a.setQuick(dest, v);
92 }
93 ++dest;
94 }
95
96 if (dest < N) {
97 for (int i = 0; i < A; ++i) {
98 arrays[i].remove(dest, N-dest);
99 }
100 }
101 }
102
103 public void removeNaNs() {
104 removeNaNs(new TDoubleArrayList [] { w, q });
105 }
106 }
107 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org