# HG changeset patch # User Sascha L. Teichmann # Date 1347374769 0 # Node ID 99f80469ba2ba2e2f583f996cf3eb3302925d0f6 # Parent a33df17ac9bb09035adb71c5aebf1c0ec8d782c3 Pegelinfo: Made generation of datum and aeo NPE proof. flys-artifacts/trunk@5434 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r a33df17ac9bb -r 99f80469ba2b flys-artifacts/ChangeLog --- 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 + + * src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java: + Made AEo and datum attributes NPE proof. + 2012-09-11 Björn Ricks * src/main/java/de/intevation/flys/artifacts/services/GaugeOverviewInfoService.java: diff -r a33df17ac9bb -r 99f80469ba2b flys-artifacts/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 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()) + : ""; } - }