comparison artifacts/src/main/java/org/dive4elements/river/artifacts/model/WW.java @ 5838:5aa05a7a34b7

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

http://dive4elements.wald.intevation.org