Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WQSelect.java @ 8760:9483a5bf4219
Remove indirection via RiverUtils to obtain reference gauge and reduce casts.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 26 Jun 2015 19:33:17 +0200 |
parents | bd17bd07db69 |
children | e3519c3e7a0a 0a5239a1e46e |
comparison
equal
deleted
inserted
replaced
8759:2faf6cef6f5f | 8760:9483a5bf4219 |
---|---|
178 } | 178 } |
179 | 179 |
180 NumberFormat nf = NumberFormat.getInstance( | 180 NumberFormat nf = NumberFormat.getInstance( |
181 Resources.getLocale(cc.getMeta())); | 181 Resources.getLocale(cc.getMeta())); |
182 | 182 |
183 Gauge gauge = RiverUtils.getGauge(winfo); | 183 RangeAccess rangeAccess = new RangeAccess(winfo); |
184 | 184 Gauge gauge = rangeAccess.getRiver().determineRefGauge( |
185 boolean debug = log.isDebugEnabled(); | 185 rangeAccess.getKmRange(), rangeAccess.isRange()); |
186 | 186 |
187 StringBuilder label = new StringBuilder(); | 187 StringBuilder label = new StringBuilder(); |
188 | 188 |
189 for (String value: values) { | 189 for (String value: values) { |
190 try { | 190 try { |
193 String tmp = nf.format(v); | 193 String tmp = nf.format(v); |
194 String mv = RiverUtils.getNamedMainValue(gauge, v); | 194 String mv = RiverUtils.getNamedMainValue(gauge, v); |
195 | 195 |
196 if (mv != null && mv.length() > 0) { | 196 if (mv != null && mv.length() > 0) { |
197 tmp = mv + ": " + tmp; | 197 tmp = mv + ": " + tmp; |
198 if (debug) { | 198 log.debug("Add main value: '" + mv + "'"); |
199 log.debug("Add main value: '" + mv + "'"); | |
200 } | |
201 } | 199 } |
202 if (label.length() > 0) { | 200 if (label.length() > 0) { |
203 label.append(';'); | 201 label.append(';'); |
204 } | 202 } |
205 label.append(tmp); | 203 label.append(tmp); |
248 @Override | 246 @Override |
249 protected Element[] createItems( | 247 protected Element[] createItems( |
250 XMLUtils.ElementCreator cr, | 248 XMLUtils.ElementCreator cr, |
251 Artifact artifact, | 249 Artifact artifact, |
252 String name, | 250 String name, |
253 CallContext context) | 251 CallContext context |
254 { | 252 ){ |
255 double[] minmaxW = determineMinMaxW(artifact); | 253 WINFOArtifact winfo = (WINFOArtifact) artifact; |
256 double[] minmaxWFree = determineMinMaxWFree(artifact); | 254 |
257 double[] minmaxQ = determineMinMaxQAtGauge(artifact); | 255 double[] minmaxW = determineMinMaxW(winfo); |
258 double[] minmaxQFree = determineMinMaxQ(artifact); | 256 double[] minmaxWFree = determineMinMaxWFree(winfo); |
257 double[] minmaxQ = determineMinMaxQAtGauge(winfo); | |
258 double[] minmaxQFree = determineMinMaxQ(winfo); | |
259 | 259 |
260 if (name.equals("wq_from")) { | 260 if (name.equals("wq_from")) { |
261 Element minW = createItem(cr, new String[] { | 261 Element minW = createItem(cr, new String[] { |
262 "minW", | 262 "minW", |
263 String.valueOf(minmaxW[0])}); | 263 String.valueOf(minmaxW[0])}); |
398 * | 398 * |
399 * @param artifact The D4EArtifact. | 399 * @param artifact The D4EArtifact. |
400 * | 400 * |
401 * @return the min and max W values for the current gauge. | 401 * @return the min and max W values for the current gauge. |
402 */ | 402 */ |
403 protected double[] determineMinMaxW(Artifact artifact) { | 403 protected double[] determineMinMaxW(WINFOArtifact winfo) { |
404 log.debug("WQSelect.determineCurrentGauge"); | 404 log.debug("WQSelect.determineCurrentGauge"); |
405 | 405 |
406 Gauge gauge = RiverUtils.getGauge((WINFOArtifact) artifact); | 406 RangeAccess rangeAccess = new RangeAccess(winfo); |
407 Gauge gauge = rangeAccess.getRiver().determineRefGauge( | |
408 rangeAccess.getKmRange(), rangeAccess.isRange()); | |
409 | |
407 double[] minmaxW = gauge != null ? gauge.determineMinMaxW() : null; | 410 double[] minmaxW = gauge != null ? gauge.determineMinMaxW() : null; |
408 | 411 |
409 double minW = minmaxW != null ? minmaxW[0] : Double.MIN_VALUE; | 412 double minW = minmaxW != null ? minmaxW[0] : Double.MIN_VALUE; |
410 double maxW = minmaxW != null ? minmaxW[1] : Double.MAX_VALUE; | 413 double maxW = minmaxW != null ? minmaxW[1] : Double.MAX_VALUE; |
411 | 414 |
420 * | 423 * |
421 * @param artifact The D4EArtifact. | 424 * @param artifact The D4EArtifact. |
422 * | 425 * |
423 * @return the min and max W values. | 426 * @return the min and max W values. |
424 */ | 427 */ |
425 protected double[] determineMinMaxWFree(Artifact artifact) { | 428 protected double[] determineMinMaxWFree(WINFOArtifact winfo) { |
426 log.debug("WQSelect.determineMinMaxWFree"); | 429 log.debug("WQSelect.determineMinMaxWFree"); |
427 | 430 |
428 WINFOArtifact winfo = (WINFOArtifact) artifact; | |
429 WstValueTable valueTable = WstValueTableFactory.getTable( | 431 WstValueTable valueTable = WstValueTableFactory.getTable( |
430 RiverUtils.getRiver(winfo)); | 432 RiverUtils.getRiver(winfo)); |
431 | 433 |
432 double[] minmaxW = null; | 434 double[] minmaxW = null; |
433 if(valueTable != null) { | 435 if(valueTable != null) { |
455 * | 457 * |
456 * @param artifact The D4EArtifact. | 458 * @param artifact The D4EArtifact. |
457 * | 459 * |
458 * @return the min and max Q values for the current gauge. | 460 * @return the min and max Q values for the current gauge. |
459 */ | 461 */ |
460 protected double[] determineMinMaxQAtGauge(Artifact artifact) { | 462 protected double[] determineMinMaxQAtGauge(WINFOArtifact winfo) { |
461 log.debug("WQSelect.determineMinMaxQAtGauge"); | 463 log.debug("WQSelect.determineMinMaxQAtGauge"); |
462 | 464 |
463 WINFOArtifact flysArtifact = (WINFOArtifact) artifact; | 465 RangeAccess rangeAccess = new RangeAccess(winfo); |
464 | 466 River river = rangeAccess.getRiver(); |
465 River river = RiverUtils.getRiver(flysArtifact); | 467 Gauge gauge = river.determineRefGauge( |
466 Gauge gauge = RiverUtils.getGauge(flysArtifact); | 468 rangeAccess.getKmRange(), rangeAccess.isRange()); |
469 | |
467 Wst wst = WstFactory.getWst(river); | 470 Wst wst = WstFactory.getWst(river); |
468 | 471 |
469 double[] minmaxQ = gauge != null | 472 double[] minmaxQ = gauge != null |
470 ? wst.determineMinMaxQ(gauge.getRange()) | 473 ? wst.determineMinMaxQ(gauge.getRange()) |
471 : null; | 474 : null; |
483 * | 486 * |
484 * @param artifact The D4EArtifact. | 487 * @param artifact The D4EArtifact. |
485 * | 488 * |
486 * @return the min and max Q values for the current kilometer range. | 489 * @return the min and max Q values for the current kilometer range. |
487 */ | 490 */ |
488 protected double[] determineMinMaxQ(Artifact artifact) { | 491 protected double[] determineMinMaxQ(WINFOArtifact winfo) { |
489 log.debug("WQSelect.determineMinMaxQ"); | 492 log.debug("WQSelect.determineMinMaxQ"); |
490 | 493 |
491 WINFOArtifact winfo = (WINFOArtifact) artifact; | |
492 WstValueTable valueTable = WstValueTableFactory.getTable( | 494 WstValueTable valueTable = WstValueTableFactory.getTable( |
493 RiverUtils.getRiver(winfo)); | 495 RiverUtils.getRiver(winfo)); |
494 | 496 |
495 double[] minmaxQ = null; | 497 double[] minmaxQ = null; |
496 if(valueTable != null) { | 498 if(valueTable != null) { |
533 : false; | 535 : false; |
534 | 536 |
535 | 537 |
536 | 538 |
537 if (!isRange) { | 539 if (!isRange) { |
538 return validateSingle(artifact); | 540 return validateSingle(flys); |
539 } | 541 } |
540 else { | 542 else { |
541 return validateRange(artifact); | 543 return validateRange(flys); |
542 } | 544 } |
543 } | 545 } |
544 | 546 |
545 | 547 |
546 protected boolean validateBounds( | 548 protected boolean validateBounds( |
563 | 565 |
564 return true; | 566 return true; |
565 } | 567 } |
566 | 568 |
567 | 569 |
568 protected boolean validateSingle(Artifact artifact) | 570 protected boolean validateSingle(WINFOArtifact artifact) |
569 throws IllegalArgumentException | 571 throws IllegalArgumentException |
570 { | 572 { |
571 log.debug("WQSelect.validateSingle"); | 573 log.debug("WQSelect.validateSingle"); |
572 | 574 |
573 WINFOArtifact flys = (WINFOArtifact) artifact; | 575 StateData data = getData(artifact, WQ_SINGLE); |
574 StateData data = getData(flys, WQ_SINGLE); | |
575 | 576 |
576 String tmp = data != null ? (String) data.getValue() : null; | 577 String tmp = data != null ? (String) data.getValue() : null; |
577 | 578 |
578 if (tmp == null || tmp.length() == 0) { | 579 if (tmp == null || tmp.length() == 0) { |
579 throw new IllegalArgumentException("error_empty_state"); | 580 throw new IllegalArgumentException("error_empty_state"); |
591 } | 592 } |
592 } | 593 } |
593 | 594 |
594 all.sort(); | 595 all.sort(); |
595 | 596 |
596 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(flys); | 597 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(artifact); |
597 | 598 |
598 log.debug("WQ Mode: " + mode); | 599 log.debug("WQ Mode: " + mode); |
599 | 600 |
600 double[] minmax = null; | 601 double[] minmax = null; |
601 | 602 |
620 | 621 |
621 return validateBounds(minmax[0], minmax[1], min, max, 0d); | 622 return validateBounds(minmax[0], minmax[1], min, max, 0d); |
622 } | 623 } |
623 | 624 |
624 | 625 |
625 protected boolean validateRange(Artifact artifact) | 626 protected boolean validateRange(WINFOArtifact artifact) |
626 throws IllegalArgumentException | 627 throws IllegalArgumentException |
627 { | 628 { |
628 log.debug("WQSelect.validateRange"); | 629 log.debug("WQSelect.validateRange"); |
629 | 630 |
630 WINFOArtifact flys = (WINFOArtifact) artifact; | 631 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(artifact); |
631 RiverUtils.WQ_MODE mode = RiverUtils.getWQMode(flys); | |
632 | 632 |
633 if (mode == null) { | 633 if (mode == null) { |
634 throw new IllegalArgumentException("error_feed_invalid_wq_mode"); | 634 throw new IllegalArgumentException("error_feed_invalid_wq_mode"); |
635 } | 635 } |
636 | 636 |
637 StateData dFrom = flys.getData(WQ_FROM); | 637 StateData dFrom = artifact.getData(WQ_FROM); |
638 StateData dTo = flys.getData(WQ_TO); | 638 StateData dTo = artifact.getData(WQ_TO); |
639 StateData dStep = flys.getData(WQ_STEP); | 639 StateData dStep = artifact.getData(WQ_STEP); |
640 | 640 |
641 String fromStr = dFrom != null ? (String) dFrom.getValue() : null; | 641 String fromStr = dFrom != null ? (String) dFrom.getValue() : null; |
642 String toStr = dTo != null ? (String) dTo.getValue() : null; | 642 String toStr = dTo != null ? (String) dTo.getValue() : null; |
643 String stepStr = dStep != null ? (String) dStep.getValue() : null; | 643 String stepStr = dStep != null ? (String) dStep.getValue() : null; |
644 | 644 |
683 * @param step The step width. | 683 * @param step The step width. |
684 * | 684 * |
685 * @return true, if everything was fine, otherwise an exception is thrown. | 685 * @return true, if everything was fine, otherwise an exception is thrown. |
686 */ | 686 */ |
687 protected boolean validateGaugeW( | 687 protected boolean validateGaugeW( |
688 Artifact artifact, | 688 WINFOArtifact artifact, |
689 double from, | 689 double from, |
690 double to, | 690 double to, |
691 double step) | 691 double step) |
692 throws IllegalArgumentException | 692 throws IllegalArgumentException |
693 { | 693 { |
709 * @param step The step width. | 709 * @param step The step width. |
710 * | 710 * |
711 * @return true, if everything was fine, otherwise an exception is thrown. | 711 * @return true, if everything was fine, otherwise an exception is thrown. |
712 */ | 712 */ |
713 protected boolean validateGaugeQ( | 713 protected boolean validateGaugeQ( |
714 Artifact artifact, | 714 WINFOArtifact artifact, |
715 double from, | 715 double from, |
716 double to, | 716 double to, |
717 double step) | 717 double step) |
718 throws IllegalArgumentException | 718 throws IllegalArgumentException |
719 { | 719 { |
735 * @param step The step width. | 735 * @param step The step width. |
736 * | 736 * |
737 * @return true, if everything was fine, otherwise an exception is thrown. | 737 * @return true, if everything was fine, otherwise an exception is thrown. |
738 */ | 738 */ |
739 protected boolean validateFreeQ( | 739 protected boolean validateFreeQ( |
740 Artifact artifact, | 740 WINFOArtifact artifact, |
741 double from, | 741 double from, |
742 double to, | 742 double to, |
743 double step) | 743 double step) |
744 throws IllegalArgumentException | 744 throws IllegalArgumentException |
745 { | 745 { |
761 * @param step The step width. | 761 * @param step The step width. |
762 * | 762 * |
763 * @return true, if everything was fine, otherwise an exception is thrown. | 763 * @return true, if everything was fine, otherwise an exception is thrown. |
764 */ | 764 */ |
765 protected boolean validateFreeW( | 765 protected boolean validateFreeW( |
766 Artifact artifact, | 766 WINFOArtifact artifact, |
767 double from, | 767 double from, |
768 double to, | 768 double to, |
769 double step) | 769 double step) |
770 throws IllegalArgumentException | 770 throws IllegalArgumentException |
771 { | 771 { |