comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/access/FixAnalysisAccess.java @ 3408:50d61a2494cb

FixA: Renamed FixationArtifactAccess to FixAnalysisAccess flys-artifacts/trunk@5061 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 19 Jul 2012 12:55:45 +0000
parents
children 0ef83077c93f
comparison
equal deleted inserted replaced
3407:70e9d56e21fc 3408:50d61a2494cb
1 package de.intevation.flys.artifacts.access;
2
3 import de.intevation.artifactdatabase.data.StateData;
4 import de.intevation.flys.artifacts.FLYSArtifact;
5 import de.intevation.flys.artifacts.model.DateRange;
6
7 import java.util.Arrays;
8 import java.util.Date;
9
10 import org.apache.log4j.Logger;
11
12
13 public class FixAnalysisAccess
14 extends Access
15 {
16 private static Logger log = Logger.getLogger(FixAnalysisAccess.class);
17
18 protected String river;
19
20 protected String calculationMode;
21
22 protected Double from;
23 protected Double to;
24 protected Double step;
25
26 protected Long start;
27 protected Long end;
28
29 protected Integer qSectorStart;
30 protected Integer qSectorEnd;
31
32 protected DateRange referencePeriod;
33 protected DateRange [] analysisPeriods;
34
35 protected int [] events;
36
37 protected Boolean preprocessing;
38
39 protected String function;
40
41 protected double [] qs;
42
43 public FixAnalysisAccess() {
44 }
45
46 public FixAnalysisAccess(FLYSArtifact artifact) {
47 super(artifact);
48 }
49
50 public String getRiver() {
51 if (river == null) {
52 river = getString("river");
53 }
54 if (log.isDebugEnabled()) {
55 log.debug("river: '" + river + "'");
56 }
57 return river;
58 }
59
60 public String getCalculationMode() {
61 if (calculationMode == null) {
62 calculationMode = getString("calculation.mode");
63 }
64
65 if (log.isDebugEnabled()) {
66 log.debug("calculationMode: '" + calculationMode + "'");
67 }
68 return calculationMode;
69 }
70
71 public Double getFrom() {
72
73 if (from == null) {
74 from = getDouble("from");
75 }
76
77 if (log.isDebugEnabled()) {
78 log.debug("from: '" + from + "'");
79 }
80
81 return from;
82 }
83
84 public Double getTo() {
85
86 if (to == null) {
87 to = getDouble("to");
88 }
89
90 if (log.isDebugEnabled()) {
91 log.debug("to: '" + to + "'");
92 }
93
94 return to;
95 }
96
97 public Double getStep() {
98
99 if (step == null) {
100 step = getDouble("step");
101 }
102
103 if (log.isDebugEnabled()) {
104 log.debug("step: '" + step + "'");
105 }
106
107 return step;
108 }
109
110 public Long getStart() {
111
112 if (start == null) {
113 start = getLong("start");
114 }
115
116 if (log.isDebugEnabled()) {
117 log.debug("start: '" + start + "'");
118 }
119
120 return start;
121 }
122
123 public Long getEnd() {
124
125 if (end == null) {
126 end = getLong("end");
127 }
128
129 if (log.isDebugEnabled()) {
130 log.debug("end: '" + end + "'");
131 }
132
133 return end;
134 }
135
136 public Integer getQSectorStart() {
137
138 if (qSectorStart == null) {
139 qSectorStart = getInteger("q1");
140 }
141
142 if (log.isDebugEnabled()) {
143 log.debug("q1: '" + qSectorStart + "'");
144 }
145
146 return qSectorStart;
147 }
148
149 public Integer getQSectorEnd() {
150
151 if (qSectorEnd == null) {
152 qSectorEnd = getInteger("q2");
153 }
154
155 if (log.isDebugEnabled()) {
156 log.debug("q2: '" + qSectorEnd + "'");
157 }
158
159 return qSectorEnd;
160 }
161
162 public int [] getEvents() {
163 if (events == null) {
164 events = getIntArray("events");
165 }
166 if (log.isDebugEnabled() && events != null) {
167 log.debug("events: " + Arrays.toString(events));
168 }
169 return events;
170 }
171
172 public DateRange getReferencePeriod() {
173 if (referencePeriod == null) {
174 StateData refStart = artifact.getData("ref_start");
175 StateData refEnd = artifact.getData("ref_end");
176
177 if (refStart == null || refEnd == null) {
178 log.warn("missing 'ref_start' or 'ref_start' value");
179 return null;
180 }
181
182 try {
183 long rs = Long.parseLong((String)refStart.getValue());
184 long re = Long.parseLong((String)refEnd .getValue());
185
186 if (rs > re) { long t = rs; rs = re; re = t; }
187
188 Date from = new Date(rs);
189 Date to = new Date(re);
190 referencePeriod = new DateRange(from, to);
191 }
192 catch (NumberFormatException nfe) {
193 log.warn("ref_start or ref_end is not an integer.");
194 }
195 }
196
197 return referencePeriod;
198 }
199
200 public DateRange [] getAnalysisPeriods() {
201 if (analysisPeriods == null) {
202 analysisPeriods = getDateRange("ana_data");
203 }
204
205 return analysisPeriods;
206 }
207
208 /**
209 * @return DateRange object ranging from eldest to youngest date
210 * of analysis and reference periods.
211 */
212 public DateRange getDateRange() {
213 DateRange refP = getReferencePeriod();
214
215 Date from = refP.getFrom();
216 Date to = refP.getTo();
217
218 DateRange[] rs = getAnalysisPeriods();
219 for(DateRange r : rs) {
220 if(r.getFrom().before(from)) {
221 from = r.getFrom();
222 }
223 if(r.getTo().after(to)) {
224 to = r.getTo();
225 }
226 }
227
228 return new DateRange(from, to);
229 }
230
231 public Boolean getPreprocessing() {
232 if (preprocessing == null) {
233 preprocessing = getBoolean("preprocessing");
234 }
235 if (log.isDebugEnabled()) {
236 log.debug("preprocessing: " + preprocessing);
237 }
238 return preprocessing;
239 }
240
241 public String getFunction() {
242 if (function == null) {
243 function = getString("function");
244 }
245 if (log.isDebugEnabled()) {
246 log.debug("function: " + function);
247 }
248 return function;
249 }
250
251 public double [] getQs() {
252 if (qs == null) {
253 qs = getDoubleArray("qs");
254 }
255
256 if (log.isDebugEnabled() && qs != null) {
257 log.debug("qs: " + Arrays.toString(qs));
258 }
259 return qs;
260 }
261 }
262 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org