Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FixationArtifactAccess.java @ 2793:6310b1582f2d
merged flys-artifacts/2.7
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:30 +0200 |
parents | f53173a8736b |
children | 3dd1c320cf81 |
comparison
equal
deleted
inserted
replaced
2548:ada02bbd3b7f | 2793:6310b1582f2d |
---|---|
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 if (log.isDebugEnabled()) { | |
354 log.debug("function: " + function); | |
355 } | |
356 return function; | |
357 } | |
358 | |
359 public double [] getQs() { | |
360 if (qs == null) { | |
361 StateData sd = artifact.getData("qs"); | |
362 if (sd == null) { | |
363 log.warn("missing 'qs'"); | |
364 return null; | |
365 } | |
366 String [] parts = ((String)sd.getValue()).split("[\\s;]"); | |
367 TDoubleArrayList list = new TDoubleArrayList(parts.length); | |
368 for (String part: parts) { | |
369 try { | |
370 list.add(Double.parseDouble(part)); | |
371 } | |
372 catch (NumberFormatException nfe) { | |
373 log.warn("'" + part + "' is not numeric."); | |
374 } | |
375 } | |
376 qs = list.toNativeArray(); | |
377 } | |
378 if (log.isDebugEnabled()) { | |
379 log.debug("qs: " + Arrays.toString(qs)); | |
380 } | |
381 return qs; | |
382 } | |
383 } | |
384 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |