Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java @ 379:c21fb8de54f8
Enabled the FLYSArtifact to handle an array of inserted WQ values (without given ranges).
flys-artifacts/trunk@1793 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 02 May 2011 15:17:04 +0000 |
parents | ed3325a0232a |
children | 929137ee8154 |
comparison
equal
deleted
inserted
replaced
378:20c3a5b36434 | 379:c21fb8de54f8 |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | 2 |
3 import java.util.Map; | 3 import java.util.Map; |
4 | |
5 import gnu.trove.TDoubleArrayList; | |
4 | 6 |
5 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
6 | 8 |
7 import org.w3c.dom.Element; | 9 import org.w3c.dom.Element; |
8 | 10 |
38 public static final String DEFAULT_STEP_W = "30"; | 40 public static final String DEFAULT_STEP_W = "30"; |
39 | 41 |
40 /** The name of the 'mode' field. */ | 42 /** The name of the 'mode' field. */ |
41 public static final String WQ_MODE = "wq_mode"; | 43 public static final String WQ_MODE = "wq_mode"; |
42 | 44 |
45 /** The name of the 'selection' field.*/ | |
46 public static final String WQ_SELECTION = "wq_selection"; | |
47 | |
43 /** The name of the 'from' field. */ | 48 /** The name of the 'from' field. */ |
44 public static final String WQ_FROM = "wq_from"; | 49 public static final String WQ_FROM = "wq_from"; |
45 | 50 |
46 /** The name of the 'to' field. */ | 51 /** The name of the 'to' field. */ |
47 public static final String WQ_TO = "wq_to"; | 52 public static final String WQ_TO = "wq_to"; |
48 | 53 |
49 /** The name of the 'step' field. */ | 54 /** The name of the 'step' field. */ |
50 public static final String WQ_STEP = "wq_step"; | 55 public static final String WQ_STEP = "wq_step"; |
56 | |
57 /** The name of the 'single' field. */ | |
58 public static final String WQ_SINGLE = "wq_single"; | |
59 | |
51 | 60 |
52 /** | 61 /** |
53 * The default constructor that initializes an empty State object. | 62 * The default constructor that initializes an empty State object. |
54 */ | 63 */ |
55 public WQSelect() { | 64 public WQSelect() { |
193 throws IllegalArgumentException | 202 throws IllegalArgumentException |
194 { | 203 { |
195 logger.debug("WQSelect.validate"); | 204 logger.debug("WQSelect.validate"); |
196 | 205 |
197 Map<String, StateData> data = getData(); | 206 Map<String, StateData> data = getData(); |
207 | |
208 String selectionMode = (String) data.get(WQ_SELECTION).getValue(); | |
209 | |
210 if (selectionMode == null || selectionMode.equals("single")) { | |
211 return validateSingle(artifact, context); | |
212 } | |
213 else { | |
214 return validateRange(artifact, context); | |
215 } | |
216 } | |
217 | |
218 | |
219 protected boolean validateSingle(Artifact artifact, CallContext context) | |
220 throws IllegalArgumentException | |
221 { | |
222 logger.debug("WQSelect.validateSingle"); | |
223 | |
224 String tmp = (String) data.get(WQ_SINGLE).getValue(); | |
225 | |
226 if (tmp == null || tmp.length() == 0) { | |
227 throw new IllegalArgumentException("error_empty_state"); | |
228 } | |
229 | |
230 String[] strValues = tmp.split(" "); | |
231 TDoubleArrayList all = new TDoubleArrayList(); | |
232 | |
233 for (String strValue: strValues) { | |
234 try { | |
235 all.add(Double.parseDouble(strValue)); | |
236 } | |
237 catch (NumberFormatException nfe) { | |
238 logger.warn(nfe, nfe); | |
239 } | |
240 } | |
241 | |
242 all.sort(); | |
243 | |
244 String mode = (String) data.get(WQ_MODE).getValue(); | |
245 logger.debug("WQ Mode: " + mode); | |
246 | |
247 double[] minmax = null; | |
248 | |
249 if (mode != null && mode.trim().toLowerCase().equals("w")) { | |
250 minmax = determineMinMaxW(artifact); | |
251 } | |
252 else { | |
253 minmax = determineMinMaxQ(artifact); | |
254 } | |
255 | |
256 double min = all.get(0); | |
257 double max = all.get(all.size()-1); | |
258 | |
259 logger.debug("Inserted min value = " + min); | |
260 logger.debug("Inserted max value = " + max); | |
261 | |
262 return validateBounds(minmax[0], minmax[1], min, max, 0d); | |
263 } | |
264 | |
265 | |
266 protected boolean validateRange(Artifact artifact, CallContext context) | |
267 throws IllegalArgumentException | |
268 { | |
269 logger.debug("WQSelect.validateRange"); | |
198 | 270 |
199 String mode = (String) data.get(WQ_MODE).getValue(); | 271 String mode = (String) data.get(WQ_MODE).getValue(); |
200 logger.debug("WQ Mode: " + mode); | 272 logger.debug("WQ Mode: " + mode); |
201 | 273 |
202 String fromStr = (String) data.get(WQ_FROM).getValue(); | 274 String fromStr = (String) data.get(WQ_FROM).getValue(); |
249 { | 321 { |
250 logger.debug("WQSelect.validateW"); | 322 logger.debug("WQSelect.validateW"); |
251 | 323 |
252 double[] minmaxW = determineMinMaxW(artifact); | 324 double[] minmaxW = determineMinMaxW(artifact); |
253 | 325 |
254 return validateRange(minmaxW[0], minmaxW[1], from, to, step); | 326 return validateBounds(minmaxW[0], minmaxW[1], from, to, step); |
255 } | 327 } |
256 | 328 |
257 | 329 |
258 /** | 330 /** |
259 * Validates the inserted Q values. | 331 * Validates the inserted Q values. |
276 { | 348 { |
277 logger.debug("WQSelect.validateQ"); | 349 logger.debug("WQSelect.validateQ"); |
278 | 350 |
279 double[] minmaxQ = determineMinMaxQ(artifact); | 351 double[] minmaxQ = determineMinMaxQ(artifact); |
280 | 352 |
281 return validateRange(minmaxQ[0], minmaxQ[1], from, to, step); | 353 return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); |
282 } | 354 } |
283 } | 355 } |
284 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 356 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |