changeset 3748:99f80469ba2b

Pegelinfo: Made generation of datum and aeo NPE proof. flys-artifacts/trunk@5434 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 11 Sep 2012 14:46:09 +0000
parents a33df17ac9bb
children 3dcc4feff243
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java
diffstat 2 files changed, 25 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue Sep 11 13:07:59 2012 +0000
+++ b/flys-artifacts/ChangeLog	Tue Sep 11 14:46:09 2012 +0000
@@ -1,3 +1,8 @@
+2012-09-11	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java:
+	  Made AEo and datum attributes NPE proof.
+
 2012-09-11	Björn Ricks	<bjoern.ricks@intevation.de>
 
 	* src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java	Tue Sep 11 13:07:59 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java	Tue Sep 11 14:46:09 2012 +0000
@@ -71,14 +71,29 @@
         Element egs = ec.create("gauges");
 
         List<Gauge> gauges = river.getGauges();
-        logger.debug("Loaded gauges: " + gauges);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Loaded gauges: " + gauges);
+        }
+
         for (Gauge gauge: river.getGauges()) {
             Element eg = ec.create("gauge");
+
             String name = gauge.getName();
             if (name != null) {
                 ec.addAttr(eg, "name", gauge.getName(), true);
             }
 
+            String aeo = getGaugeValue(gauge.getAeo());
+            if (aeo != null) {
+                ec.addAttr(eg, "aeo", aeo, true);
+            }
+
+            String datum = getGaugeValue(gauge.getDatum());
+            if (datum != null) {
+                ec.addAttr(eg, "datum", datum, true);
+            }
+
             Range range = gauge.getRange();
             if (range != null) {
                 double min = range.getA().doubleValue();
@@ -109,9 +124,6 @@
                 ec.addAttr(eg, "maxq", maxq, true);
             }
 
-            ec.addAttr(eg, "aeo", getGaugeValue(gauge.getAeo()), true);
-            ec.addAttr(eg, "datum", getGaugeValue(gauge.getDatum()), true);
-
             egs.appendChild(eg);
         }
 
@@ -125,11 +137,9 @@
     /**
      * Returns a Double from a BigDecimal value or null if value is null
      */
-    private String getGaugeValue(BigDecimal value) {
-        if (value == null) {
-            return null;
-        }
-        return Double.toString(value.doubleValue());
+    private static String getGaugeValue(BigDecimal value) {
+        return value != null
+            ? Double.toString(value.doubleValue())
+            : "";
     }
-
 }

http://dive4elements.wald.intevation.org