changeset 2128:bf67eb014443

Added convinience functions to FLYSArtifact and FLYSUtils. flys-artifacts/trunk@3703 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 18 Jan 2012 09:29:12 +0000
parents 0c7847b8e85e
children 4bd84e66909e
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java
diffstat 3 files changed, 44 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Jan 17 18:26:45 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed Jan 18 09:29:12 2012 +0000
@@ -1,3 +1,13 @@
+2012-01-18  Ingo Weinzierl <ingo@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Added a
+	  method getDataAsLong that returns a Long representation of a data item or
+	  null if no such data item is existing or it cannot be parsed as Long.
+
+	* src/main/java/de/intevation/flys/utils/FLYSUtils.java: Added a function
+	  that returns the selected reference gauge (specified by 'reference_gauge'
+	  parameter) of a FLYSArtifact.
+
 2012-01-17	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/model/LocationProvider.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Tue Jan 17 18:26:45 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Wed Jan 18 09:29:12 2012 +0000
@@ -589,6 +589,31 @@
 
     /**
      * 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.
+     *
+     * @return a Long 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 Long.
+     */
+    public Long getDataAsLong(String name)
+    throws NumberFormatException
+    {
+        String value = getDataAsString(name);
+
+        if (value != null && value.length() > 0) {
+            return Long.parseLong(value);
+        }
+
+        return null;
+    }
+
+
+    /**
+     * This method returns the value of a StateData object stored in the data
      * pool of this Artifact is Boolean using Boolean.valueOf().
      *
      * @param name The name of the StateData object.
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Tue Jan 17 18:26:45 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java	Wed Jan 18 09:29:12 2012 +0000
@@ -415,6 +415,15 @@
     }
 
 
+    public static Gauge getReferenceGauge(FLYSArtifact flys) {
+        Long officialNumber = flys.getDataAsLong("reference_gauge");
+
+        return officialNumber != null
+            ? Gauge.getGaugeByOfficialNumber(officialNumber)
+            : null;
+    }
+
+
     public static Double getValueFromWQ(WQ wq) {
         if (wq == null) {
             return null;

http://dive4elements.wald.intevation.org