Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.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 | 5c880567a020 |
children | 26dedebbe39f |
comparison
equal
deleted
inserted
replaced
8201:4b8c5a08de04 | 8202:e4606eae8ea5 |
---|---|
43 /** | 43 /** |
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 WQSelect extends DefaultState { | 46 public class WQSelect extends DefaultState { |
47 | 47 |
48 /** The logger used in this class. */ | 48 /** The log used in this class. */ |
49 private static Logger logger = Logger.getLogger(WQSelect.class); | 49 private static Logger log = Logger.getLogger(WQSelect.class); |
50 | 50 |
51 /** The default step width for Qs. */ | 51 /** The default step width for Qs. */ |
52 public static final String DEFAULT_STEP_Q = "50"; | 52 public static final String DEFAULT_STEP_Q = "50"; |
53 | 53 |
54 /** The default step width for Qs. */ | 54 /** The default step width for Qs. */ |
178 NumberFormat nf = NumberFormat.getInstance( | 178 NumberFormat nf = NumberFormat.getInstance( |
179 Resources.getLocale(cc.getMeta())); | 179 Resources.getLocale(cc.getMeta())); |
180 | 180 |
181 Gauge gauge = winfo.getGauge(); | 181 Gauge gauge = winfo.getGauge(); |
182 | 182 |
183 boolean debug = logger.isDebugEnabled(); | 183 boolean debug = log.isDebugEnabled(); |
184 | 184 |
185 StringBuilder label = new StringBuilder(); | 185 StringBuilder label = new StringBuilder(); |
186 | 186 |
187 for (String value: values) { | 187 for (String value: values) { |
188 try { | 188 try { |
192 String mv = RiverUtils.getNamedMainValue(gauge, v); | 192 String mv = RiverUtils.getNamedMainValue(gauge, v); |
193 | 193 |
194 if (mv != null && mv.length() > 0) { | 194 if (mv != null && mv.length() > 0) { |
195 tmp = mv + ": " + tmp; | 195 tmp = mv + ": " + tmp; |
196 if (debug) { | 196 if (debug) { |
197 logger.debug("Add main value: '" + mv + "'"); | 197 log.debug("Add main value: '" + mv + "'"); |
198 } | 198 } |
199 } | 199 } |
200 if (label.length() > 0) { | 200 if (label.length() > 0) { |
201 label.append(';'); | 201 label.append(';'); |
202 } | 202 } |
397 * @param artifact The D4EArtifact. | 397 * @param artifact The D4EArtifact. |
398 * | 398 * |
399 * @return the min and max W values for the current gauge. | 399 * @return the min and max W values for the current gauge. |
400 */ | 400 */ |
401 protected double[] determineMinMaxW(Artifact artifact) { | 401 protected double[] determineMinMaxW(Artifact artifact) { |
402 logger.debug("WQSelect.determineCurrentGauge"); | 402 log.debug("WQSelect.determineCurrentGauge"); |
403 | 403 |
404 Gauge gauge = ((WINFOArtifact) artifact).getGauge(); | 404 Gauge gauge = ((WINFOArtifact) artifact).getGauge(); |
405 double[] minmaxW = gauge != null ? gauge.determineMinMaxW() : null; | 405 double[] minmaxW = gauge != null ? gauge.determineMinMaxW() : null; |
406 | 406 |
407 double minW = minmaxW != null ? minmaxW[0] : Double.MIN_VALUE; | 407 double minW = minmaxW != null ? minmaxW[0] : Double.MIN_VALUE; |
419 * @param artifact The D4EArtifact. | 419 * @param artifact The D4EArtifact. |
420 * | 420 * |
421 * @return the min and max W values. | 421 * @return the min and max W values. |
422 */ | 422 */ |
423 protected double[] determineMinMaxWFree(Artifact artifact) { | 423 protected double[] determineMinMaxWFree(Artifact artifact) { |
424 logger.debug("WQSelect.determineMinMaxWFree"); | 424 log.debug("WQSelect.determineMinMaxWFree"); |
425 | 425 |
426 WINFOArtifact winfo = (WINFOArtifact) artifact; | 426 WINFOArtifact winfo = (WINFOArtifact) artifact; |
427 WstValueTable valueTable = WstValueTableFactory.getTable( | 427 WstValueTable valueTable = WstValueTableFactory.getTable( |
428 RiverUtils.getRiver(winfo)); | 428 RiverUtils.getRiver(winfo)); |
429 | 429 |
454 * @param artifact The D4EArtifact. | 454 * @param artifact The D4EArtifact. |
455 * | 455 * |
456 * @return the min and max Q values for the current gauge. | 456 * @return the min and max Q values for the current gauge. |
457 */ | 457 */ |
458 protected double[] determineMinMaxQAtGauge(Artifact artifact) { | 458 protected double[] determineMinMaxQAtGauge(Artifact artifact) { |
459 logger.debug("WQSelect.determineMinMaxQAtGauge"); | 459 log.debug("WQSelect.determineMinMaxQAtGauge"); |
460 | 460 |
461 WINFOArtifact flysArtifact = (WINFOArtifact) artifact; | 461 WINFOArtifact flysArtifact = (WINFOArtifact) artifact; |
462 | 462 |
463 River river = RiverUtils.getRiver(flysArtifact); | 463 River river = RiverUtils.getRiver(flysArtifact); |
464 Gauge gauge = flysArtifact.getGauge(); | 464 Gauge gauge = flysArtifact.getGauge(); |
482 * @param artifact The D4EArtifact. | 482 * @param artifact The D4EArtifact. |
483 * | 483 * |
484 * @return the min and max Q values for the current kilometer range. | 484 * @return the min and max Q values for the current kilometer range. |
485 */ | 485 */ |
486 protected double[] determineMinMaxQ(Artifact artifact) { | 486 protected double[] determineMinMaxQ(Artifact artifact) { |
487 logger.debug("WQSelect.determineMinMaxQ"); | 487 log.debug("WQSelect.determineMinMaxQ"); |
488 | 488 |
489 WINFOArtifact winfo = (WINFOArtifact) artifact; | 489 WINFOArtifact winfo = (WINFOArtifact) artifact; |
490 WstValueTable valueTable = WstValueTableFactory.getTable( | 490 WstValueTable valueTable = WstValueTableFactory.getTable( |
491 RiverUtils.getRiver(winfo)); | 491 RiverUtils.getRiver(winfo)); |
492 | 492 |
519 | 519 |
520 @Override | 520 @Override |
521 public boolean validate(Artifact artifact) | 521 public boolean validate(Artifact artifact) |
522 throws IllegalArgumentException | 522 throws IllegalArgumentException |
523 { | 523 { |
524 logger.debug("WQSelect.validate"); | 524 log.debug("WQSelect.validate"); |
525 | 525 |
526 WINFOArtifact flys = (WINFOArtifact) artifact; | 526 WINFOArtifact flys = (WINFOArtifact) artifact; |
527 | 527 |
528 StateData data = getData(flys, WQ_SELECTION); | 528 StateData data = getData(flys, WQ_SELECTION); |
529 boolean isRange = data != null | 529 boolean isRange = data != null |
544 protected boolean validateBounds( | 544 protected boolean validateBounds( |
545 double fromValid, double toValid, | 545 double fromValid, double toValid, |
546 double from, double to, double step) | 546 double from, double to, double step) |
547 throws IllegalArgumentException | 547 throws IllegalArgumentException |
548 { | 548 { |
549 logger.debug("RangeState.validateRange"); | 549 log.debug("RangeState.validateRange"); |
550 | 550 |
551 if (from < fromValid) { | 551 if (from < fromValid) { |
552 logger.error( | 552 log.error( |
553 "Invalid 'from'. " + from + " is smaller than " + fromValid); | 553 "Invalid 'from'. " + from + " is smaller than " + fromValid); |
554 throw new IllegalArgumentException("error_feed_from_out_of_range"); | 554 throw new IllegalArgumentException("error_feed_from_out_of_range"); |
555 } | 555 } |
556 else if (to > toValid) { | 556 else if (to > toValid) { |
557 logger.error( | 557 log.error( |
558 "Invalid 'to'. " + to + " is bigger than " + toValid); | 558 "Invalid 'to'. " + to + " is bigger than " + toValid); |
559 throw new IllegalArgumentException("error_feed_to_out_of_range"); | 559 throw new IllegalArgumentException("error_feed_to_out_of_range"); |
560 } | 560 } |
561 | 561 |
562 return true; | 562 return true; |
564 | 564 |
565 | 565 |
566 protected boolean validateSingle(Artifact artifact) | 566 protected boolean validateSingle(Artifact artifact) |
567 throws IllegalArgumentException | 567 throws IllegalArgumentException |
568 { | 568 { |
569 logger.debug("WQSelect.validateSingle"); | 569 log.debug("WQSelect.validateSingle"); |
570 | 570 |
571 WINFOArtifact flys = (WINFOArtifact) artifact; | 571 WINFOArtifact flys = (WINFOArtifact) artifact; |
572 StateData data = getData(flys, WQ_SINGLE); | 572 StateData data = getData(flys, WQ_SINGLE); |
573 | 573 |
574 String tmp = data != null ? (String) data.getValue() : null; | 574 String tmp = data != null ? (String) data.getValue() : null; |
583 for (String strValue: strValues) { | 583 for (String strValue: strValues) { |
584 try { | 584 try { |
585 all.add(Double.parseDouble(strValue)); | 585 all.add(Double.parseDouble(strValue)); |
586 } | 586 } |
587 catch (NumberFormatException nfe) { | 587 catch (NumberFormatException nfe) { |
588 logger.warn(nfe, nfe); | 588 log.warn(nfe, nfe); |
589 } | 589 } |
590 } | 590 } |
591 | 591 |
592 all.sort(); | 592 all.sort(); |
593 | 593 |
594 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(flys); | 594 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(flys); |
595 | 595 |
596 logger.debug("WQ Mode: " + mode); | 596 log.debug("WQ Mode: " + mode); |
597 | 597 |
598 double[] minmax = null; | 598 double[] minmax = null; |
599 | 599 |
600 if (mode == RiverUtils.WQ_MODE.WGAUGE) { | 600 if (mode == RiverUtils.WQ_MODE.WGAUGE) { |
601 minmax = determineMinMaxW(artifact); | 601 minmax = determineMinMaxW(artifact); |
611 } | 611 } |
612 | 612 |
613 double min = all.get(0); | 613 double min = all.get(0); |
614 double max = all.get(all.size()-1); | 614 double max = all.get(all.size()-1); |
615 | 615 |
616 logger.debug("Inserted min value = " + min); | 616 log.debug("Inserted min value = " + min); |
617 logger.debug("Inserted max value = " + max); | 617 log.debug("Inserted max value = " + max); |
618 | 618 |
619 return validateBounds(minmax[0], minmax[1], min, max, 0d); | 619 return validateBounds(minmax[0], minmax[1], min, max, 0d); |
620 } | 620 } |
621 | 621 |
622 | 622 |
623 protected boolean validateRange(Artifact artifact) | 623 protected boolean validateRange(Artifact artifact) |
624 throws IllegalArgumentException | 624 throws IllegalArgumentException |
625 { | 625 { |
626 logger.debug("WQSelect.validateRange"); | 626 log.debug("WQSelect.validateRange"); |
627 | 627 |
628 WINFOArtifact flys = (WINFOArtifact) artifact; | 628 WINFOArtifact flys = (WINFOArtifact) artifact; |
629 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(flys); | 629 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(flys); |
630 | 630 |
631 if (mode == null) { | 631 if (mode == null) { |
687 double from, | 687 double from, |
688 double to, | 688 double to, |
689 double step) | 689 double step) |
690 throws IllegalArgumentException | 690 throws IllegalArgumentException |
691 { | 691 { |
692 logger.debug("WQSelect.validateGaugeW"); | 692 log.debug("WQSelect.validateGaugeW"); |
693 | 693 |
694 double[] minmaxW = determineMinMaxW(artifact); | 694 double[] minmaxW = determineMinMaxW(artifact); |
695 | 695 |
696 return validateBounds(minmaxW[0], minmaxW[1], from, to, step); | 696 return validateBounds(minmaxW[0], minmaxW[1], from, to, step); |
697 } | 697 } |
713 double from, | 713 double from, |
714 double to, | 714 double to, |
715 double step) | 715 double step) |
716 throws IllegalArgumentException | 716 throws IllegalArgumentException |
717 { | 717 { |
718 logger.debug("WQSelect.validateGaugeQ"); | 718 log.debug("WQSelect.validateGaugeQ"); |
719 | 719 |
720 double[] minmaxQ = determineMinMaxQAtGauge(artifact); | 720 double[] minmaxQ = determineMinMaxQAtGauge(artifact); |
721 | 721 |
722 return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); | 722 return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); |
723 } | 723 } |
739 double from, | 739 double from, |
740 double to, | 740 double to, |
741 double step) | 741 double step) |
742 throws IllegalArgumentException | 742 throws IllegalArgumentException |
743 { | 743 { |
744 logger.debug("WQSelect.validateFreeQ"); | 744 log.debug("WQSelect.validateFreeQ"); |
745 | 745 |
746 double[] minmaxQ = determineMinMaxQ(artifact); | 746 double[] minmaxQ = determineMinMaxQ(artifact); |
747 | 747 |
748 return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); | 748 return validateBounds(minmaxQ[0], minmaxQ[1], from, to, step); |
749 } | 749 } |
765 double from, | 765 double from, |
766 double to, | 766 double to, |
767 double step) | 767 double step) |
768 throws IllegalArgumentException | 768 throws IllegalArgumentException |
769 { | 769 { |
770 logger.debug("WQSelect.validateFreeW"); | 770 log.debug("WQSelect.validateFreeW"); |
771 | 771 |
772 double[] minmaxW = determineMinMaxWFree(artifact); | 772 double[] minmaxW = determineMinMaxWFree(artifact); |
773 | 773 |
774 return validateBounds(minmaxW[0], minmaxW[1], from, to, step); | 774 return validateBounds(minmaxW[0], minmaxW[1], from, to, step); |
775 } | 775 } |