comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java @ 402:eb22ffe4d74c

Implemented methods to retrieve and compute the data used to create discharge longitudinal sections. flys-artifacts/trunk@1843 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 06 May 2011 14:19:27 +0000
parents 5f55047a17e8
children 5606ba4139e0
comparison
equal deleted inserted replaced
401:34de11dcf355 402:eb22ffe4d74c
1 package de.intevation.flys.artifacts.model; 1 package de.intevation.flys.artifacts.model;
2 2
3 import java.io.Serializable; 3 import java.io.Serializable;
4 4
5 import gnu.trove.TDoubleArrayList; 5 import gnu.trove.TDoubleArrayList;
6
7 import org.apache.log4j.Logger;
6 8
7 9
8 /** 10 /**
9 * This class represents a pool of data triples that consists of 'W', 'Q' and 11 * This class represents a pool of data triples that consists of 'W', 'Q' and
10 * 'KM' data. 12 * 'KM' data.
11 * 13 *
12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
13 */ 15 */
14 public class WQKms implements Serializable { 16 public class WQKms implements Serializable {
17
18 private static Logger logger = Logger.getLogger(WQKms.class);
19
15 20
16 /** The array that contains the 'W' values.*/ 21 /** The array that contains the 'W' values.*/
17 protected TDoubleArrayList w; 22 protected TDoubleArrayList w;
18 23
19 /** The array that contains the 'Q' values.*/ 24 /** The array that contains the 'Q' values.*/
34 this.q = new TDoubleArrayList(capacity); 39 this.q = new TDoubleArrayList(capacity);
35 this.kms = new TDoubleArrayList(capacity); 40 this.kms = new TDoubleArrayList(capacity);
36 } 41 }
37 42
38 43
44 public WQKms(double[] kms, double[] qs, double[] ws) {
45 this.w = new TDoubleArrayList(ws);
46 this.q = new TDoubleArrayList(qs);
47 this.kms = new TDoubleArrayList(kms);
48 }
49
50
39 /** 51 /**
40 * Adds a new row to this data pool. 52 * Adds a new row to this data pool.
41 * 53 *
42 * @param w a W. 54 * @param w a W.
43 * @param q a Q. 55 * @param q a Q.
44 * @param kms a Kms. 56 * @param kms a Kms.
45 */ 57 */
46 public void add(double w, double q, double kms) { 58 public void add(double w, double q, double kms) {
59 this.w.add(w);
60 this.q.add(q);
61 this.kms.add(kms);
62 }
63
64
65 public void add(double[] w, double[] q, double[] kms) {
47 this.w.add(w); 66 this.w.add(w);
48 this.q.add(q); 67 this.q.add(q);
49 this.kms.add(kms); 68 this.kms.add(kms);
50 } 69 }
51 70
76 95
77 96
78 public double getKms(int idx) { 97 public double getKms(int idx) {
79 return kms.get(idx); 98 return kms.get(idx);
80 } 99 }
100
101
102 public double[] getKms() {
103 return kms.toNativeArray();
104 }
105
106
107 public double[] getWs() {
108 return w.toNativeArray();
109 }
110
111
112 public double[] getQs() {
113 return q.toNativeArray();
114 }
115
116
117 /**
118 * Returns a string that consist of the first and last kilometer.
119 *
120 * @return a string that consist of the first and last kilometer.
121 */
122 public String toString() {
123 double from = getKms(0);
124 double to = getKms(size()-1);
125 return Double.toString(from) + " - " + Double.toString(to);
126 }
127
128
129 /**
130 * Merges the WQKms objects of an incoming 2dim array (table) where the
131 * objects of a column belong together.
132 *
133 * @param toMerge The objects that need to be merged.
134 *
135 * @return an array of merged WQKms objects.
136 */
137 public static WQKms[] merge(WQKms[][] toMerge) {
138 int num = toMerge[0].length;
139
140 // TODO IS THE LENGTH CORRECT?
141 WQKms[] merged = new WQKms[num];
142 for (int i = 0; i < num; i++) {
143 merged[i] = new WQKms();
144 }
145
146 for (int i = 0; i < toMerge.length; i++) {
147 WQKms[] tmp = toMerge[i];
148
149 for (int j = 0; j < num; j++) {
150 WQKms toAdd = tmp[j];
151 merged[j].add(toAdd.getWs(), toAdd.getQs(), toAdd.getKms());
152 }
153 }
154
155 return merged;
156 }
81 } 157 }
82 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 158 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org