Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 02 13:42:02 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Mon May 02 15:17:04 2011 +0000 @@ -8,6 +8,8 @@ import javax.xml.xpath.XPathConstants; +import gnu.trove.TDoubleArrayList; + import org.apache.log4j.Logger; import org.w3c.dom.Document; @@ -534,12 +536,18 @@ * @return the selected Q values or null, if no Q values are selected. */ public double[] getQs() { - StateData dMode = getData("wq_mode"); + StateData dMode = getData("wq_mode"); + StateData dSingle = getData("wq_single"); String mode = dMode != null ? (String) dMode.getValue() : ""; if (mode.equals("Q")) { - return getWQTriple(); + if (dSingle != null) { + return getSingleWQValues(); + } + else { + return getWQTriple(); + } } else { logger.warn("You try to get Qs, but W has been inserted."); @@ -554,12 +562,18 @@ * @return the selected W values or null, if no W values are selected. */ public double[] getWs() { - StateData dMode = getData("wq_mode"); + StateData dMode = getData("wq_mode"); + StateData dSingle = getData("wq_single"); String mode = dMode != null ? (String) dMode.getValue() : ""; if (mode.equals("W")) { - return getWQTriple(); + if (dSingle != null) { + return getSingleWQValues(); + } + else { + return getWQTriple(); + } } else { logger.warn("You try to get Qs, but W has been inserted."); @@ -608,7 +622,7 @@ StateData dTo = getData("wq_to"); if (dFrom == null || dTo == null) { - logger.warn("Missing start or end value for Q range."); + logger.warn("Missing start or end value for range."); return null; } @@ -636,6 +650,40 @@ /** + * Returns an array of inserted WQ double values stored as whitespace + * separated list. + * + * @return an array of W or Q values. + */ + protected double[] getSingleWQValues() { + StateData dSingle = getData("wq_single"); + + if (dSingle == null) { + logger.warn("Cannot determine single WQ values. No data given."); + return null; + } + + String tmp = (String) dSingle.getValue(); + String[] strValues = tmp.split(" "); + + TDoubleArrayList values = new TDoubleArrayList(); + + for (String strValue: strValues) { + try { + values.add(Double.parseDouble(strValue)); + } + catch (NumberFormatException nfe) { + logger.warn(nfe, nfe); + } + } + + values.sort(); + + return values.toNativeArray(); + } + + + /** * Returns an array of double values. The values contained in this array * begin with the value <i>from</i> and end with the value <i>to</i>. The * number of values in the result array depends on the <i>step</i> width.