Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.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 | 0ccf7200fc51 |
children | dcc3cd962c0e |
comparison
equal
deleted
inserted
replaced
378:20c3a5b36434 | 379:c21fb8de54f8 |
---|---|
5 import java.util.Map; | 5 import java.util.Map; |
6 import java.util.Set; | 6 import java.util.Set; |
7 import java.util.Vector; | 7 import java.util.Vector; |
8 | 8 |
9 import javax.xml.xpath.XPathConstants; | 9 import javax.xml.xpath.XPathConstants; |
10 | |
11 import gnu.trove.TDoubleArrayList; | |
10 | 12 |
11 import org.apache.log4j.Logger; | 13 import org.apache.log4j.Logger; |
12 | 14 |
13 import org.w3c.dom.Document; | 15 import org.w3c.dom.Document; |
14 import org.w3c.dom.Element; | 16 import org.w3c.dom.Element; |
532 * This method returns the Q values. | 534 * This method returns the Q values. |
533 * | 535 * |
534 * @return the selected Q values or null, if no Q values are selected. | 536 * @return the selected Q values or null, if no Q values are selected. |
535 */ | 537 */ |
536 public double[] getQs() { | 538 public double[] getQs() { |
537 StateData dMode = getData("wq_mode"); | 539 StateData dMode = getData("wq_mode"); |
540 StateData dSingle = getData("wq_single"); | |
538 | 541 |
539 String mode = dMode != null ? (String) dMode.getValue() : ""; | 542 String mode = dMode != null ? (String) dMode.getValue() : ""; |
540 | 543 |
541 if (mode.equals("Q")) { | 544 if (mode.equals("Q")) { |
542 return getWQTriple(); | 545 if (dSingle != null) { |
546 return getSingleWQValues(); | |
547 } | |
548 else { | |
549 return getWQTriple(); | |
550 } | |
543 } | 551 } |
544 else { | 552 else { |
545 logger.warn("You try to get Qs, but W has been inserted."); | 553 logger.warn("You try to get Qs, but W has been inserted."); |
546 return null; | 554 return null; |
547 } | 555 } |
552 * This method returns the W values. | 560 * This method returns the W values. |
553 * | 561 * |
554 * @return the selected W values or null, if no W values are selected. | 562 * @return the selected W values or null, if no W values are selected. |
555 */ | 563 */ |
556 public double[] getWs() { | 564 public double[] getWs() { |
557 StateData dMode = getData("wq_mode"); | 565 StateData dMode = getData("wq_mode"); |
566 StateData dSingle = getData("wq_single"); | |
558 | 567 |
559 String mode = dMode != null ? (String) dMode.getValue() : ""; | 568 String mode = dMode != null ? (String) dMode.getValue() : ""; |
560 | 569 |
561 if (mode.equals("W")) { | 570 if (mode.equals("W")) { |
562 return getWQTriple(); | 571 if (dSingle != null) { |
572 return getSingleWQValues(); | |
573 } | |
574 else { | |
575 return getWQTriple(); | |
576 } | |
563 } | 577 } |
564 else { | 578 else { |
565 logger.warn("You try to get Qs, but W has been inserted."); | 579 logger.warn("You try to get Qs, but W has been inserted."); |
566 return null; | 580 return null; |
567 } | 581 } |
606 protected double[] getWQTriple() { | 620 protected double[] getWQTriple() { |
607 StateData dFrom = getData("wq_from"); | 621 StateData dFrom = getData("wq_from"); |
608 StateData dTo = getData("wq_to"); | 622 StateData dTo = getData("wq_to"); |
609 | 623 |
610 if (dFrom == null || dTo == null) { | 624 if (dFrom == null || dTo == null) { |
611 logger.warn("Missing start or end value for Q range."); | 625 logger.warn("Missing start or end value for range."); |
612 return null; | 626 return null; |
613 } | 627 } |
614 | 628 |
615 double from = Double.parseDouble((String) dFrom.getValue()); | 629 double from = Double.parseDouble((String) dFrom.getValue()); |
616 double to = Double.parseDouble((String) dTo.getValue()); | 630 double to = Double.parseDouble((String) dTo.getValue()); |
634 return getExplodedValues(from, to, step); | 648 return getExplodedValues(from, to, step); |
635 } | 649 } |
636 | 650 |
637 | 651 |
638 /** | 652 /** |
653 * Returns an array of inserted WQ double values stored as whitespace | |
654 * separated list. | |
655 * | |
656 * @return an array of W or Q values. | |
657 */ | |
658 protected double[] getSingleWQValues() { | |
659 StateData dSingle = getData("wq_single"); | |
660 | |
661 if (dSingle == null) { | |
662 logger.warn("Cannot determine single WQ values. No data given."); | |
663 return null; | |
664 } | |
665 | |
666 String tmp = (String) dSingle.getValue(); | |
667 String[] strValues = tmp.split(" "); | |
668 | |
669 TDoubleArrayList values = new TDoubleArrayList(); | |
670 | |
671 for (String strValue: strValues) { | |
672 try { | |
673 values.add(Double.parseDouble(strValue)); | |
674 } | |
675 catch (NumberFormatException nfe) { | |
676 logger.warn(nfe, nfe); | |
677 } | |
678 } | |
679 | |
680 values.sort(); | |
681 | |
682 return values.toNativeArray(); | |
683 } | |
684 | |
685 | |
686 /** | |
639 * Returns an array of double values. The values contained in this array | 687 * Returns an array of double values. The values contained in this array |
640 * begin with the value <i>from</i> and end with the value <i>to</i>. The | 688 * begin with the value <i>from</i> and end with the value <i>to</i>. The |
641 * number of values in the result array depends on the <i>step</i> width. | 689 * number of values in the result array depends on the <i>step</i> width. |
642 * | 690 * |
643 * @param from The lower value. | 691 * @param from The lower value. |