comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WW.java @ 3318:dbe2f85bf160

merged flys-artifacts/2.8
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:35 +0200
parents 5642a83420f2
children bcf25d8c183e
comparison
equal deleted inserted replaced
2987:98c7a46ec5ae 3318:dbe2f85bf160
1 package de.intevation.flys.artifacts.model;
2
3 import de.intevation.flys.artifacts.math.Function;
4 import de.intevation.flys.artifacts.math.Identity;
5
6 import gnu.trove.TDoubleArrayList;
7
8 public class WW
9 extends W
10 {
11 public static class ApplyFunctionIterator
12 {
13 protected Function function1;
14 protected Function function2;
15 protected int pos;
16 protected WW ww;
17
18 public ApplyFunctionIterator(WW ww) {
19 this(ww, Identity.IDENTITY, Identity.IDENTITY);
20 }
21
22 public ApplyFunctionIterator(
23 WW ww,
24 Function function1,
25 Function function2
26 ) {
27 this.ww = ww;
28 this.function1 = function1;
29 this.function2 = function2;
30 }
31
32 public boolean hasNext() {
33 return pos < ww.size();
34 }
35
36 public int size() {
37 return ww.size();
38 }
39
40 public void reset() {
41 pos = 0;
42 }
43
44 public WW getWW() {
45 return ww;
46 }
47
48 public void get(int idx, double [] wwPair) {
49 wwPair[0] = function1.value(ww.getW(idx));
50 wwPair[1] = function2.value(ww.getW2(idx));
51 }
52
53 public void next(double [] wwPair) {
54 get(pos++, wwPair);
55 }
56 } // class FunctionIterator
57
58 protected TDoubleArrayList ws2;
59
60 protected double startKm;
61 protected double endKm;
62
63 protected Double startDatum;
64 protected Double endDatum;
65
66 public WW() {
67 this("");
68 }
69
70 public WW(String name) {
71 super(name);
72 }
73
74 public WW(int capacity) {
75 this(capacity, "");
76 }
77
78 public WW(int capacity, String name) {
79 super(capacity, name);
80 ws2 = new TDoubleArrayList(capacity);
81 }
82
83 public WW(
84 String name,
85 double startKm,
86 Double startDatum,
87 double [] ws,
88 double endKm,
89 Double endDatum,
90 double [] ws2
91 ) {
92 this.name = name;
93 this.ws = new TDoubleArrayList(ws);
94 this.ws2 = new TDoubleArrayList(ws2);
95 this.startKm = startKm;
96 this.startDatum = startDatum;
97 this.endKm = endKm;
98 this.endDatum = endDatum;
99 }
100
101 public WW(String name, TDoubleArrayList ws, TDoubleArrayList ws2) {
102 this.name = name;
103 this.ws = ws;
104 this.ws2 = ws2;
105 }
106
107 public void add(double w1, double w2) {
108 ws .add(w1);
109 ws2.add(w2);
110 }
111
112 public double getW1(int idx) {
113 return ws.getQuick(idx);
114 }
115
116 public double getW2(int idx) {
117 return ws2.getQuick(idx);
118 }
119
120 public double [] getWs2() {
121 return ws2.toNativeArray();
122 }
123
124 @Override
125 public double [] get(int idx) {
126 return get(idx, new double[2]);
127 }
128
129 @Override
130 public double [] get(int idx, double [] dst) {
131 dst[0] = ws .getQuick(idx);
132 dst[1] = ws2.getQuick(idx);
133 return dst;
134 }
135
136 public double getStartKm() {
137 return startKm;
138 }
139
140 public void setStartKm(double startKm) {
141 this.startKm = startKm;
142 }
143
144 public double getEndKm() {
145 return endKm;
146 }
147
148 public void setEndKm(double endKm) {
149 this.endKm = endKm;
150 }
151
152 public Double getStartDatum() {
153 return startDatum;
154 }
155
156 public boolean startAtGauge() {
157 return startDatum != null;
158 }
159
160 public boolean endAtGauge() {
161 return endDatum != null;
162 }
163
164 public void setStartDatum(Double startDatum) {
165 this.startDatum = startDatum;
166 }
167
168 public Double getEndDatum() {
169 return endDatum;
170 }
171
172 public void setEndDatum(Double endDatum) {
173 this.endDatum = endDatum;
174 }
175
176 @Override
177 public void removeNaNs() {
178 removeNaNs(new TDoubleArrayList [] { ws, ws2 });
179 }
180
181 public double minWs2() {
182 return ws2.min();
183 }
184
185 // Note that we can also easily define a Function to do so.
186 public double getRelHeight1Cm(int idx) {
187 if (this.startAtGauge()) {
188 return (ws.getQuick(idx) - getStartDatum())*100d;
189 }
190 else return ws.getQuick(idx)*100d;
191 }
192
193 public double getRelHeight2Cm(int idx) {
194 if (this.endAtGauge()) {
195 return (ws2.getQuick(idx) - getEndDatum())*100d;
196 }
197 else return ws2.getQuick(idx)*100d;
198 }
199 }
200 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org