comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQKms.java @ 3468:f37e7e8907cb

merged flys-artifacts/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:39 +0200
parents b2ea89a665bc
children 4d457c68b1d3
comparison
equal deleted inserted replaced
3387:5ffad8bde8ad 3468:f37e7e8907cb
1 package de.intevation.flys.artifacts.model;
2
3 import gnu.trove.TDoubleArrayList;
4
5 import org.apache.log4j.Logger;
6
7
8 /**
9 * This class represents a pool of data triples that consists of 'W', 'Q' and
10 * 'KM' data.
11 *
12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
13 */
14 public class WQKms
15 extends WQ
16 implements WKms
17 {
18 private static Logger logger = Logger.getLogger(WQKms.class);
19
20 /** The array that contains the 'KMs' values. */
21 protected TDoubleArrayList kms;
22
23
24 public WQKms() {
25 this("");
26 }
27
28
29 public WQKms(String name) {
30 super(name);
31 this.kms = new TDoubleArrayList();
32 }
33
34
35 public WQKms(int capacity) {
36 this(capacity, "");
37 }
38
39
40 public WQKms(int capacity, String name) {
41 super(capacity, name);
42 this.kms = new TDoubleArrayList(capacity);
43 }
44
45 public WQKms(double [] kms, double [] qs, double [] ws) {
46 this(kms, qs, ws, "");
47 }
48
49
50 public WQKms(double [] kms, double [] qs, double [] ws, String name) {
51 super(qs, ws, name);
52 this.kms = new TDoubleArrayList(kms);
53 }
54
55 @Override
56 public void removeNaNs() {
57 removeNaNs(new TDoubleArrayList [] { ws, qs, kms });
58 }
59
60 /**
61 * Adds a new row to this data pool.
62 *
63 * @param w a W.
64 * @param q a Q.
65 * @param km a kms.
66 */
67 public void add(double w, double q, double km) {
68 super.add(w, q);
69 kms.add(km);
70 }
71
72 @Override
73 public double [] get(int idx) {
74 return get(idx, new double [3]);
75 }
76
77 /**
78 * This method returns a triple of W, Q and Kms in a single 3dim array.
79 *
80 * @param idx The position of the triple.
81 * @param dst destination array
82 *
83 * @return a triple of [W, Q, Kms] in dst.
84 */
85 @Override
86 public double [] get(int idx, double [] dst) {
87 dst[0] = ws .getQuick(idx);
88 dst[1] = qs .getQuick(idx);
89 dst[2] = kms.getQuick(idx);
90 return dst;
91 }
92
93 @Override
94 public double getKm(int idx) {
95 return kms.getQuick(idx);
96 }
97
98 @Override
99 public TDoubleArrayList allKms() {
100 return kms;
101 }
102
103 @Override
104 public TDoubleArrayList allWs() {
105 return ws;
106 }
107
108 public double[] getKms() {
109 return kms.toNativeArray();
110 }
111
112 /**
113 * Returns a string that consist of the first and last kilometer.
114 *
115 * @return a string that consist of the first and last kilometer.
116 */
117 public String toString() {
118 double from = getKm(0);
119 double to = getKm(size()-1);
120 return from + " - " + to;
121 }
122 }
123 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org