comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java @ 2725:8dbc86a0948d

Fixing analysis: Access to state data. flys-artifacts/trunk@4456 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 22 May 2012 12:55:52 +0000
parents
children f53173a8736b
comparison
equal deleted inserted replaced
2724:43474b346272 2725:8dbc86a0948d
1 package de.intevation.flys.artifacts;
2
3 import java.util.Arrays;
4
5 import de.intevation.artifactdatabase.data.StateData;
6
7 import gnu.trove.TDoubleArrayList;
8
9 import de.intevation.flys.utils.FLYSUtils;
10
11 import org.apache.log4j.Logger;
12
13 public class FixationArtifactAccess
14 {
15 private static Logger log = Logger.getLogger(FixationArtifactAccess.class);
16
17 protected FLYSArtifact artifact;
18
19 protected String river;
20
21 protected String calculationMode;
22
23 protected Double from;
24 protected Double to;
25 protected Double step;
26
27 protected Long start;
28 protected Long end;
29
30 protected Integer qSectorStart;
31 protected Integer qSectorEnd;
32
33 protected Long referenceStart;
34 protected Long referenceEnd;
35
36 protected long [][] analysisPeriods;
37
38 protected int [] events;
39
40 protected Boolean preprocessing;
41
42 protected String function;
43
44 protected double [] qs;
45
46 public FixationArtifactAccess() {
47 }
48
49 public FixationArtifactAccess(FLYSArtifact artifact) {
50 this.artifact = artifact;
51 }
52
53 public FLYSArtifact getArtifact() {
54 return artifact;
55 }
56
57 public String getRiver() {
58 if (river == null) {
59 StateData sd = artifact.getData("river");
60 if (sd == null) {
61 log.warn("missing 'river' value");
62 return null;
63 }
64 river = (String)sd.getValue();
65 }
66 if (log.isDebugEnabled()) {
67 log.debug("river: '" + river + "'");
68 }
69 return river;
70 }
71
72 public String getCalculationMode() {
73 if (calculationMode == null) {
74 StateData sd = artifact.getData("calculation.mode");
75 if (sd == null) {
76 log.warn("missing 'calculation.mode' value");
77 return null;
78 }
79 calculationMode = (String)sd.getValue();
80 }
81
82 if (log.isDebugEnabled()) {
83 log.debug("calculationMode: '" + calculationMode + "'");
84 }
85 return calculationMode;
86 }
87
88 public Double getFrom() {
89
90 if (from == null) {
91 StateData sd = artifact.getData("from");
92 if (sd == null) {
93 log.warn("missing 'from' value");
94 return null;
95 }
96 try {
97 from = Double.valueOf((String)sd.getValue());
98 }
99 catch (NumberFormatException nfe) {
100 log.warn("from '" + sd.getValue() + "' is not numeric.");
101 }
102 }
103
104 if (log.isDebugEnabled()) {
105 log.debug("from: '" + from + "'");
106 }
107
108 return from;
109 }
110
111 public Double getTo() {
112
113 if (to == null) {
114 StateData sd = artifact.getData("to");
115 if (sd == null) {
116 log.warn("missing 'to' value");
117 return null;
118 }
119 try {
120 to = Double.valueOf((String)sd.getValue());
121 }
122 catch (NumberFormatException nfe) {
123 log.warn("to '" + sd.getValue() + "' is not numeric.");
124 }
125 }
126
127 if (log.isDebugEnabled()) {
128 log.debug("to: '" + to + "'");
129 }
130
131 return to;
132 }
133
134 public Double getStep() {
135
136 if (step == null) {
137 StateData sd = artifact.getData("step");
138 if (sd == null) {
139 log.warn("missing 'step' value");
140 return null;
141 }
142 try {
143 step = Double.valueOf((String)sd.getValue());
144 }
145 catch (NumberFormatException nfe) {
146 log.warn("step '" + sd.getValue() + "' is not numeric.");
147 }
148 }
149
150 if (log.isDebugEnabled()) {
151 log.debug("step: '" + step + "'");
152 }
153
154 return step;
155 }
156
157 public Long getStart() {
158
159 if (start == null) {
160 StateData sd = artifact.getData("start");
161 if (sd == null) {
162 log.warn("missing 'start' value");
163 return null;
164 }
165 try {
166 start = Long.valueOf((String)sd.getValue());
167 }
168 catch (NumberFormatException nfe) {
169 log.warn("start '" + sd.getValue() + "' is not an integer.");
170 }
171 }
172
173 if (log.isDebugEnabled()) {
174 log.debug("start: '" + start + "'");
175 }
176
177 return start;
178 }
179
180 public Long getEnd() {
181
182 if (end == null) {
183 StateData sd = artifact.getData("end");
184 if (sd == null) {
185 log.warn("missing 'end' value");
186 return null;
187 }
188 try {
189 end = Long.valueOf((String)sd.getValue());
190 }
191 catch (NumberFormatException nfe) {
192 log.warn("end '" + sd.getValue() + "' is not an integer.");
193 }
194 }
195
196 if (log.isDebugEnabled()) {
197 log.debug("end: '" + end + "'");
198 }
199
200 return end;
201 }
202
203 public Integer getQSectorStart() {
204
205 if (qSectorStart == null) {
206 StateData sd = artifact.getData("q1");
207 if (sd == null) {
208 log.warn("missing 'q1' value");
209 return null;
210 }
211 try {
212 qSectorStart = Integer.valueOf((String)sd.getValue());
213 }
214 catch (NumberFormatException nfe) {
215 log.warn("q1 '" + sd.getValue() + "' is not an integer.");
216 }
217 }
218
219 return qSectorStart;
220 }
221
222 public Integer getQSectorEnd() {
223
224 if (qSectorEnd == null) {
225 StateData sd = artifact.getData("q2");
226 if (sd == null) {
227 log.warn("missing 'q2' value");
228 return null;
229 }
230 try {
231 qSectorEnd = Integer.valueOf((String)sd.getValue());
232 }
233 catch (NumberFormatException nfe) {
234 log.warn("q2 '" + sd.getValue() + "' is not an integer.");
235 }
236 }
237
238 return qSectorEnd;
239 }
240
241 public int [] getEvents() {
242 if (events == null) {
243 StateData sd = artifact.getData("events");
244 if (sd == null) {
245 log.warn("missing 'events' value");
246 return null;
247 }
248 events = FLYSUtils.intArrayFromString((String)sd.getValue());
249 }
250 return events;
251 }
252
253 public Long getReferenceStart() {
254 if (referenceStart == null) {
255 StateData sd = artifact.getData("ref_start");
256 if (sd == null) {
257 log.warn("missing 'ref_start' value");
258 return null;
259 }
260 try {
261 referenceStart = Long.valueOf((String)sd.getValue());
262 }
263 catch (NumberFormatException nfe) {
264 log.warn("ref_start '"
265 + sd.getValue() + "' is not an integer.");
266 }
267 }
268
269 if (log.isDebugEnabled()) {
270 log.debug("referenceStart: '" + referenceStart + "'");
271 }
272
273 return referenceStart;
274 }
275
276 public Long getReferenceEnd() {
277 if (referenceEnd == null) {
278 StateData sd = artifact.getData("ref_end");
279 if (sd == null) {
280 log.warn("missing 'ref_end' value");
281 return null;
282 }
283 try {
284 referenceEnd = Long.valueOf((String)sd.getValue());
285 }
286 catch (NumberFormatException nfe) {
287 log.warn("ref_end '"
288 + sd.getValue() + "' is not an integer.");
289 }
290 }
291
292 if (log.isDebugEnabled()) {
293 log.debug("referenceEnd: '" + referenceEnd + "'");
294 }
295
296 return referenceEnd;
297 }
298
299 public long [][] getAnalysisPeriods() {
300 if (analysisPeriods == null) {
301 /** TODO: Use real arrays here! */
302 StateData sdStart = artifact.getData("ana_start");
303 StateData sdEnd = artifact.getData("ana_end");
304
305 if (sdStart == null || sdEnd == null) {
306 log.warn("missing 'ana_start' or 'ana_end'");
307 return null;
308 }
309
310 try {
311 analysisPeriods = new long [][] {
312 { Long.parseLong((String)sdStart.getValue()),
313 Long.parseLong((String)sdEnd.getValue()) }
314 };
315 }
316 catch (NumberFormatException nfe) {
317 log.warn("'ana_start' or 'ana_end' is not an integer.");
318 return null;
319 }
320 }
321
322 if (log.isDebugEnabled()) {
323 for (int i = 0; i < analysisPeriods.length; ++i) {
324 long [] ap = analysisPeriods[i];
325 log.debug("analysis period " + ap[0] + " - " + ap[1]);
326 }
327 }
328
329 return analysisPeriods;
330 }
331
332 public Boolean getPreprocessing() {
333 if (preprocessing == null) {
334 StateData sd = artifact.getData("preprocessing");
335 if (sd == null) {
336 log.warn("missing 'preprocessing'");
337 return null;
338 }
339 preprocessing = Boolean.valueOf((String)sd.getValue());
340 }
341 return preprocessing;
342 }
343
344 public String getFunction() {
345 if (function == null) {
346 StateData sd = artifact.getData("function");
347 if (sd == null) {
348 log.warn("missing 'function'");
349 return null;
350 }
351 function = (String)sd.getValue();
352 }
353 return function;
354 }
355
356 public double [] getQs() {
357 if (qs == null) {
358 StateData sd = artifact.getData("qs");
359 if (sd == null) {
360 log.warn("missing 'qs'");
361 return null;
362 }
363 String [] parts = ((String)sd.getValue()).split("[\\s;]");
364 TDoubleArrayList list = new TDoubleArrayList(parts.length);
365 for (String part: parts) {
366 try {
367 list.add(Double.parseDouble(part));
368 }
369 catch (NumberFormatException nfe) {
370 log.warn("'" + part + "' is not numeric.");
371 }
372 }
373 qs = list.toNativeArray();
374 }
375 if (log.isDebugEnabled()) {
376 log.debug("qs: " + Arrays.toString(qs));
377 }
378 return qs;
379 }
380 }
381 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org