# HG changeset patch # User Ingo Weinzierl # Date 1337156462 0 # Node ID c553d4fa3957d7fa8989ac1f8f0a14dea717855c # Parent b3364af53ab36134f7d2b836832d8bbf10d899db Moved the implementation of getDataAsDouble() from concrete Artifacts into FLYSArtifact. flys-artifacts/trunk@4417 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r b3364af53ab3 -r c553d4fa3957 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue May 15 15:31:39 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed May 16 08:21:02 2012 +0000 @@ -1,3 +1,13 @@ +2012-05-16 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/HYKArtifact.java, + src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java: + Removed getDataAsDouble() which is now implemented in FLYSArtifact. + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: + Implemented getDataAsDouble(). This method will return a Double based on + a given parameter name. + 2012-05-15 Raimund Renkert * doc/conf/artifacts/fixanalysis.xml: diff -r b3364af53ab3 -r c553d4fa3957 flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Tue May 15 15:31:39 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Wed May 16 08:21:02 2012 +0000 @@ -604,6 +604,31 @@ /** * This method returns the value of a StateData object stored in the data + * pool of this Artifact as Double. + * + * @param name The name of the StateData object. + * + * @return an Double representing the value of the data object or null if + * no object was found for name. + * + * @throws NumberFormatException if the value of the data object could not + * be transformed into a Double. + */ + public Double getDataAsDouble(String name) + throws NumberFormatException + { + String value = getDataAsString(name); + + if (value != null && value.length() > 0) { + return Double.parseDouble(value); + } + + return null; + } + + + /** + * This method returns the value of a StateData object stored in the data * pool of this Artifact as Long. * * @param name The name of the StateData object. @@ -904,6 +929,8 @@ public List getOutputs(Object context) { logger.debug("##### Get Outputs for: " + identifier() + " #####"); + dumpArtifact(); + List stateIds = getPreviousStateIds(); List generated = new ArrayList(); diff -r b3364af53ab3 -r c553d4fa3957 flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.java Tue May 15 15:31:39 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.java Wed May 16 08:21:02 2012 +0000 @@ -76,29 +76,18 @@ } - /** - * Get a DataItem casted to double (0 if fails). - * TODO move to FlysArtifact. - */ - public double getDataAsDouble(String dataName) { - String val = getDataAsString(dataName); - if (val == null) { - logger.warn("Data not available."); - return 0d; - } - try { - return Double.valueOf(val); - } - catch (NumberFormatException e) { - logger.warn("Could not get data " + dataName + " as double", e); + /** Get km from state data. */ + public double getKm() { + Double km = getDataAsDouble(HYK_KM); + if (km == null) { + // XXX returning 0 is to be compatible to older versions that had an + // own method getDataAsDouble that returned 0 if parsing the + // parameter failed. return 0; } - } - - - /** Get km from state data. */ - public double getKm() { - return getDataAsDouble(HYK_KM); + else { + return km; + } } diff -r b3364af53ab3 -r c553d4fa3957 flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java Tue May 15 15:31:39 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java Wed May 16 08:21:02 2012 +0000 @@ -196,8 +196,9 @@ getDataAsInt("wst_id")); } + Double tmp = getDataAsDouble("ld_locations"); double [][] vs = interpolator.interpolateWQColumnwise( - getDataAsDouble("ld_locations")); + tmp != null ? tmp : 0); for (int x = 0; x < vs[1].length; x++) { logger.debug("getWQAtKm: Q/W " + vs[0][x] + " / " + vs[1][x]); @@ -223,21 +224,6 @@ /** - * Get a DataItem casted to double (0 if fails). - */ - public double getDataAsDouble(String dataName) { - String val = getDataAsString(dataName); - try { - return Double.valueOf(val); - } - catch (NumberFormatException e) { - logger.warn("Could not get data " + dataName + " as double", e); - return 0; - } - } - - - /** * Get the "current" state (there is but one). * @param cc ignored. * @return the "current" (only possible) state.