Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.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 | 035c0095b427 |
children | c09c9e05ecfa |
comparison
equal
deleted
inserted
replaced
725:51afeced47de | 726:cbaa3ca86f2f |
---|---|
9 * This class represents a pool of data triples that consists of 'W', 'Q' and | 9 * This class represents a pool of data triples that consists of 'W', 'Q' and |
10 * 'KM' data. | 10 * 'KM' data. |
11 * | 11 * |
12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
13 */ | 13 */ |
14 public class WQKms extends NamedObject { | 14 public class WQKms |
15 | 15 extends WQ |
16 { | |
16 private static Logger logger = Logger.getLogger(WQKms.class); | 17 private static Logger logger = Logger.getLogger(WQKms.class); |
17 | |
18 | |
19 /** The array that contains the 'W' values.*/ | |
20 protected TDoubleArrayList w; | |
21 | |
22 /** The array that contains the 'Q' values.*/ | |
23 protected TDoubleArrayList q; | |
24 | 18 |
25 /** The array that contains the 'KMs' values.*/ | 19 /** The array that contains the 'KMs' values.*/ |
26 protected TDoubleArrayList kms; | 20 protected TDoubleArrayList kms; |
27 | 21 |
28 | 22 |
31 } | 25 } |
32 | 26 |
33 | 27 |
34 public WQKms(String name) { | 28 public WQKms(String name) { |
35 super(name); | 29 super(name); |
36 | |
37 this.w = new TDoubleArrayList(); | |
38 this.q = new TDoubleArrayList(); | |
39 this.kms = new TDoubleArrayList(); | 30 this.kms = new TDoubleArrayList(); |
40 } | 31 } |
41 | 32 |
42 | 33 |
43 public WQKms(int capacity) { | 34 public WQKms(int capacity) { |
45 } | 36 } |
46 | 37 |
47 | 38 |
48 public WQKms(int capacity, String name) { | 39 public WQKms(int capacity, String name) { |
49 super(name); | 40 super(name); |
50 | |
51 this.w = new TDoubleArrayList(capacity); | |
52 this.q = new TDoubleArrayList(capacity); | |
53 this.kms = new TDoubleArrayList(capacity); | 41 this.kms = new TDoubleArrayList(capacity); |
54 } | 42 } |
55 | 43 |
56 public static void removeNaNs(TDoubleArrayList [] arrays) { | 44 public WQKms(double [] kms, double [] qs, double [] ws) { |
57 | |
58 int dest = 0; | |
59 | |
60 int A = arrays.length; | |
61 int N = arrays[0].size(); | |
62 | |
63 OUTER: for (int i = 0; i < N; ++i) { | |
64 for (int j = 0; j < A; ++j) { | |
65 TDoubleArrayList a = arrays[j]; | |
66 double v = a.getQuick(i); | |
67 if (Double.isNaN(v)) { | |
68 continue OUTER; | |
69 } | |
70 a.setQuick(dest, v); | |
71 } | |
72 ++dest; | |
73 } | |
74 | |
75 if (dest < N) { | |
76 for (int i = 0; i < A; ++i) { | |
77 arrays[i].remove(dest, N-dest); | |
78 } | |
79 } | |
80 } | |
81 | |
82 public void removeNaNs() { | |
83 removeNaNs(new TDoubleArrayList [] { w, q, kms }); | |
84 } | |
85 | |
86 | |
87 public WQKms(double[] kms, double[] qs, double[] ws) { | |
88 this(kms, qs, ws, ""); | 45 this(kms, qs, ws, ""); |
89 } | 46 } |
90 | 47 |
91 | 48 |
92 public WQKms(double[] kms, double[] qs, double[] ws, String name) { | 49 public WQKms(double [] kms, double [] qs, double [] ws, String name) { |
93 super(name); | 50 super(qs, ws, name); |
94 | |
95 this.w = new TDoubleArrayList(ws); | |
96 this.q = new TDoubleArrayList(qs); | |
97 this.kms = new TDoubleArrayList(kms); | 51 this.kms = new TDoubleArrayList(kms); |
98 } | 52 } |
99 | 53 |
54 @Override | |
55 public void removeNaNs() { | |
56 removeNaNs(new TDoubleArrayList [] { w, q, kms }); | |
57 } | |
100 | 58 |
101 /** | 59 /** |
102 * Adds a new row to this data pool. | 60 * Adds a new row to this data pool. |
103 * | 61 * |
104 * @param w a W. | 62 * @param w a W. |
105 * @param q a Q. | 63 * @param q a Q. |
106 * @param kms a Kms. | 64 * @param kms a Kms. |
107 */ | 65 */ |
108 public void add(double w, double q, double kms) { | 66 public void add(double w, double q, double km) { |
109 this.w.add(w); | 67 super.add(w, q); |
110 this.q.add(q); | 68 kms.add(km); |
111 this.kms.add(kms); | |
112 } | |
113 | |
114 /** | |
115 * Returns the number of triples stored in this data pool. | |
116 * | |
117 * @return the number of triples stored in this data pool. | |
118 */ | |
119 public int size() { | |
120 return kms.size(); | |
121 } | 69 } |
122 | 70 |
123 /** | 71 /** |
124 * This method returns a triple of W, Q and Kms in a single 3dim array. | 72 * This method returns a triple of W, Q and Kms in a single 3dim array. |
125 * | 73 * |
126 * @param idx The position of the triple. | 74 * @param idx The position of the triple. |
127 * @param dst destination array | 75 * @param dst destination array |
128 * | 76 * |
129 * @return a triple of [W, Q, Kms] in dst. | 77 * @return a triple of [W, Q, Kms] in dst. |
130 */ | 78 */ |
79 @Override | |
131 public double[] get(int idx, double [] dst) { | 80 public double[] get(int idx, double [] dst) { |
132 dst[0] = w .getQuick(idx); | 81 dst[0] = w .getQuick(idx); |
133 dst[1] = q .getQuick(idx); | 82 dst[1] = q .getQuick(idx); |
134 dst[2] = kms.getQuick(idx); | 83 dst[2] = kms.getQuick(idx); |
135 return dst; | 84 return dst; |
136 } | 85 } |
137 | 86 |
138 | |
139 public double getKms(int idx) { | 87 public double getKms(int idx) { |
140 return kms.getQuick(idx); | 88 return kms.getQuick(idx); |
141 } | |
142 | |
143 public double getW(int idx) { | |
144 return w.getQuick(idx); | |
145 } | |
146 | |
147 public double getQ(int idx) { | |
148 return q.getQuick(idx); | |
149 } | 89 } |
150 | 90 |
151 public double[] getKms() { | 91 public double[] getKms() { |
152 return kms.toNativeArray(); | 92 return kms.toNativeArray(); |
153 } | 93 } |
154 | |
155 | |
156 public double[] getWs() { | |
157 return w.toNativeArray(); | |
158 } | |
159 | |
160 | |
161 public double[] getQs() { | |
162 return q.toNativeArray(); | |
163 } | |
164 | |
165 | 94 |
166 /** | 95 /** |
167 * Returns a string that consist of the first and last kilometer. | 96 * Returns a string that consist of the first and last kilometer. |
168 * | 97 * |
169 * @return a string that consist of the first and last kilometer. | 98 * @return a string that consist of the first and last kilometer. |