Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQAdapted.java @ 8202:e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 12:58:17 +0200 |
parents | a0078e5e3b39 |
children | 5e38e2924c07 |
comparison
equal
deleted
inserted
replaced
8201:4b8c5a08de04 | 8202:e4606eae8ea5 |
---|---|
43 * State to input W/Q data. | 43 * State to input W/Q data. |
44 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 44 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
45 */ | 45 */ |
46 public class WQAdapted extends DefaultState { | 46 public class WQAdapted extends DefaultState { |
47 | 47 |
48 /** The logger used in this state.*/ | 48 /** The log used in this state.*/ |
49 private static Logger logger = Logger.getLogger(WQAdapted.class); | 49 private static Logger log = Logger.getLogger(WQAdapted.class); |
50 | 50 |
51 public static final String FIELD_WQ_MODE = "wq_isq"; | 51 public static final String FIELD_WQ_MODE = "wq_isq"; |
52 | 52 |
53 public static final String FIELD_WQ_VALUES = "wq_values"; | 53 public static final String FIELD_WQ_VALUES = "wq_values"; |
54 | 54 |
93 XMLUtils.ElementCreator cr, | 93 XMLUtils.ElementCreator cr, |
94 Artifact artifact, | 94 Artifact artifact, |
95 String name, | 95 String name, |
96 CallContext context) | 96 CallContext context) |
97 { | 97 { |
98 logger.debug("WQAdapted.createItems"); | 98 log.debug("WQAdapted.createItems"); |
99 | 99 |
100 if (name != null && name.equals(FIELD_WQ_MODE)) { | 100 if (name != null && name.equals(FIELD_WQ_MODE)) { |
101 return createModeItems(cr, artifact, name, context); | 101 return createModeItems(cr, artifact, name, context); |
102 } | 102 } |
103 else if (name != null && name.equals(FIELD_WQ_VALUES)) { | 103 else if (name != null && name.equals(FIELD_WQ_VALUES)) { |
104 return createValueItems(cr, artifact, name, context); | 104 return createValueItems(cr, artifact, name, context); |
105 } | 105 } |
106 else { | 106 else { |
107 logger.warn("Unknown data object: " + name); | 107 log.warn("Unknown data object: " + name); |
108 return null; | 108 return null; |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 | 112 |
115 XMLUtils.ElementCreator cr, | 115 XMLUtils.ElementCreator cr, |
116 Artifact artifact, | 116 Artifact artifact, |
117 String name, | 117 String name, |
118 CallContext context) | 118 CallContext context) |
119 { | 119 { |
120 logger.debug("WQAdapted.createModeItems"); | 120 log.debug("WQAdapted.createModeItems"); |
121 | 121 |
122 Element w = createItem(cr, new String[] { "w", "W" }); | 122 Element w = createItem(cr, new String[] { "w", "W" }); |
123 Element q = createItem(cr, new String[] { "q", "Q" }); | 123 Element q = createItem(cr, new String[] { "q", "Q" }); |
124 | 124 |
125 return new Element[] { w, q }; | 125 return new Element[] { w, q }; |
131 XMLUtils.ElementCreator cr, | 131 XMLUtils.ElementCreator cr, |
132 Artifact artifact, | 132 Artifact artifact, |
133 String name, | 133 String name, |
134 CallContext context) | 134 CallContext context) |
135 { | 135 { |
136 logger.debug("WQAdapted.createValueItems"); | 136 log.debug("WQAdapted.createValueItems"); |
137 | 137 |
138 D4EArtifact flysArtifact = (D4EArtifact) artifact; | 138 D4EArtifact flysArtifact = (D4EArtifact) artifact; |
139 | 139 |
140 RangeAccess rangeAccess = new RangeAccess(flysArtifact); | 140 RangeAccess rangeAccess = new RangeAccess(flysArtifact); |
141 double[] dist = rangeAccess.getKmRange(); | 141 double[] dist = rangeAccess.getKmRange(); |
145 List<Gauge> gauges = RiverUtils.getGauges(flysArtifact); | 145 List<Gauge> gauges = RiverUtils.getGauges(flysArtifact); |
146 | 146 |
147 int num = gauges != null ? gauges.size() : 0; | 147 int num = gauges != null ? gauges.size() : 0; |
148 | 148 |
149 if (num == 0) { | 149 if (num == 0) { |
150 logger.warn("Selected distance matches no gauges."); | 150 log.warn("Selected distance matches no gauges."); |
151 return null; | 151 return null; |
152 } | 152 } |
153 | 153 |
154 List<Element> elements = new ArrayList<Element>(); | 154 List<Element> elements = new ArrayList<Element>(); |
155 | 155 |
275 * @param wst | 275 * @param wst |
276 * | 276 * |
277 * @return the min and max Q values for the given gauge. | 277 * @return the min and max Q values for the given gauge. |
278 */ | 278 */ |
279 protected double[] determineMinMaxQ(Gauge gauge, Wst wst) { | 279 protected double[] determineMinMaxQ(Gauge gauge, Wst wst) { |
280 logger.debug("WQAdapted.determineMinMaxQ"); | 280 log.debug("WQAdapted.determineMinMaxQ"); |
281 | 281 |
282 double[] minmaxQ = gauge != null | 282 double[] minmaxQ = gauge != null |
283 ? wst.determineMinMaxQ(gauge.getRange()) | 283 ? wst.determineMinMaxQ(gauge.getRange()) |
284 : null; | 284 : null; |
285 | 285 |
299 | 299 |
300 @Override | 300 @Override |
301 public boolean validate(Artifact artifact) | 301 public boolean validate(Artifact artifact) |
302 throws IllegalArgumentException | 302 throws IllegalArgumentException |
303 { | 303 { |
304 logger.debug("WQAdapted.validate"); | 304 log.debug("WQAdapted.validate"); |
305 | 305 |
306 D4EArtifact flys = (D4EArtifact) artifact; | 306 D4EArtifact flys = (D4EArtifact) artifact; |
307 StateData data = getData(flys, FIELD_WQ_MODE); | 307 StateData data = getData(flys, FIELD_WQ_MODE); |
308 | 308 |
309 String mode = data != null ? (String) data.getValue() : null; | 309 String mode = data != null ? (String) data.getValue() : null; |
324 | 324 |
325 | 325 |
326 protected boolean validateW(Artifact artifact) | 326 protected boolean validateW(Artifact artifact) |
327 throws IllegalArgumentException | 327 throws IllegalArgumentException |
328 { | 328 { |
329 logger.debug("WQAdapted.validateW"); | 329 log.debug("WQAdapted.validateW"); |
330 D4EArtifact flys = (D4EArtifact) artifact; | 330 D4EArtifact flys = (D4EArtifact) artifact; |
331 | 331 |
332 RangeWithValues[] rwvs = extractInput(getData(flys, "wq_values")); | 332 RangeWithValues[] rwvs = extractInput(getData(flys, "wq_values")); |
333 | 333 |
334 if (rwvs == null) { | 334 if (rwvs == null) { |
354 | 354 |
355 | 355 |
356 protected boolean validateQ(Artifact artifact) | 356 protected boolean validateQ(Artifact artifact) |
357 throws IllegalArgumentException | 357 throws IllegalArgumentException |
358 { | 358 { |
359 logger.debug("WQAdapted.validateQ"); | 359 log.debug("WQAdapted.validateQ"); |
360 D4EArtifact flys = (D4EArtifact) artifact; | 360 D4EArtifact flys = (D4EArtifact) artifact; |
361 | 361 |
362 RangeWithValues[] rwvs = extractInput(getData(flys, "wq_values")); | 362 RangeWithValues[] rwvs = extractInput(getData(flys, "wq_values")); |
363 | 363 |
364 if (rwvs == null) { | 364 if (rwvs == null) { |
391 double[] minmax = gauge != null | 391 double[] minmax = gauge != null |
392 ? wst.determineMinMaxQ(gauge.getRange()) | 392 ? wst.determineMinMaxQ(gauge.getRange()) |
393 : null; | 393 : null; |
394 | 394 |
395 if (minmax == null) { | 395 if (minmax == null) { |
396 logger.warn("Could not determine min/max Q of gauge."); | 396 log.warn("Could not determine min/max Q of gauge."); |
397 return true; | 397 return true; |
398 } | 398 } |
399 | 399 |
400 if (logger.isDebugEnabled()) { | 400 if (log.isDebugEnabled()) { |
401 logger.debug("Validate Qs with:"); | 401 log.debug("Validate Qs with:"); |
402 logger.debug("-- Gauge: " + gauge.getName()); | 402 log.debug("-- Gauge: " + gauge.getName()); |
403 logger.debug("-- Gauge min: " + minmax[0]); | 403 log.debug("-- Gauge min: " + minmax[0]); |
404 logger.debug("-- Gauge max: " + minmax[1]); | 404 log.debug("-- Gauge max: " + minmax[1]); |
405 } | 405 } |
406 | 406 |
407 for (double q: qs) { | 407 for (double q: qs) { |
408 if (q < minmax[0] || q > minmax[1]) { | 408 if (q < minmax[0] || q > minmax[1]) { |
409 throw new IllegalArgumentException( | 409 throw new IllegalArgumentException( |
421 double[] minmax = gauge != null | 421 double[] minmax = gauge != null |
422 ? gauge.determineMinMaxW() | 422 ? gauge.determineMinMaxW() |
423 : null; | 423 : null; |
424 | 424 |
425 if (minmax == null) { | 425 if (minmax == null) { |
426 logger.warn("Could not determine min/max W of gauge."); | 426 log.warn("Could not determine min/max W of gauge."); |
427 return true; | 427 return true; |
428 } | 428 } |
429 | 429 |
430 if (logger.isDebugEnabled()) { | 430 if (log.isDebugEnabled()) { |
431 logger.debug("Validate Ws with:"); | 431 log.debug("Validate Ws with:"); |
432 logger.debug("-- Gauge: " + gauge.getName()); | 432 log.debug("-- Gauge: " + gauge.getName()); |
433 logger.debug("-- Gauge min: " + minmax[0]); | 433 log.debug("-- Gauge min: " + minmax[0]); |
434 logger.debug("-- Gauge max: " + minmax[1]); | 434 log.debug("-- Gauge max: " + minmax[1]); |
435 } | 435 } |
436 | 436 |
437 for (double w: ws) { | 437 for (double w: ws) { |
438 if (w < minmax[0] || w > minmax[1]) { | 438 if (w < minmax[0] || w > minmax[1]) { |
439 throw new IllegalArgumentException( | 439 throw new IllegalArgumentException( |
469 for (int i = 0; i < num; i++) { | 469 for (int i = 0; i < num; i++) { |
470 try { | 470 try { |
471 res[i] = Double.parseDouble(values[i]); | 471 res[i] = Double.parseDouble(values[i]); |
472 } | 472 } |
473 catch (NumberFormatException nfe) { | 473 catch (NumberFormatException nfe) { |
474 logger.warn(nfe, nfe); | 474 log.warn(nfe, nfe); |
475 } | 475 } |
476 } | 476 } |
477 | 477 |
478 rwv.add(new RangeWithValues(lower, upper, res)); | 478 rwv.add(new RangeWithValues(lower, upper, res)); |
479 } | 479 } |