changeset 2701:c553d4fa3957

Moved the implementation of getDataAsDouble() from concrete Artifacts into FLYSArtifact. flys-artifacts/trunk@4417 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 16 May 2012 08:21:02 +0000
parents b3364af53ab3
children 4c00cf83fff1
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/WQKmsInterpolArtifact.java
diffstat 4 files changed, 49 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- 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 <ingo@intevation.de>
+
+	* 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 <raimund.renkert@intevation.de>
 
 	* doc/conf/artifacts/fixanalysis.xml:
--- 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 <i>name</i>.
+     *
+     * @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<Output> getOutputs(Object context) {
         logger.debug("##### Get Outputs for: " + identifier() + " #####");
 
+        dumpArtifact();
+
         List<String> stateIds  = getPreviousStateIds();
         List<Output> generated = new ArrayList<Output>();
 
--- 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;
+        }
     }
 
 
--- 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.

http://dive4elements.wald.intevation.org