diff flys-aft/src/main/java/de/intevation/aft/River.java @ 4082:d13011e53022

Make DIPS check more verbose flys-aft/trunk@3496 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 20 Dec 2011 14:36:36 +0000
parents 7a7b0f0cb653
children 44dc38ca8492
line wrap: on
line diff
--- a/flys-aft/src/main/java/de/intevation/aft/River.java	Fri Dec 16 19:25:31 2011 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/River.java	Tue Dec 20 14:36:36 2011 +0000
@@ -14,16 +14,11 @@
 
 import de.intevation.db.ConnectedStatements;
 
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
 public class River
 extends      IdPair
 {
     private static Logger log = Logger.getLogger(River.class);
 
-    public static final Pattern NUMBER = Pattern.compile("0*([0-9]+)");
-
     protected String name;
 
     public River() {
@@ -39,10 +34,12 @@
     }
 
     public static Long numberToLong(String s) {
-        Matcher m = NUMBER.matcher(s);
-        if (!m.matches()) return null;
-        String ns = m.group(1);
-        return Long.valueOf(ns.length() == 0 ? "0": ns);
+        try {
+            return Long.valueOf(s.trim());
+        }
+        catch (NumberFormatException nfe) {
+        }
+        return null;
     }
 
     public static Map<Long, DIPSGauge> indexByNumber(Document document) {
@@ -50,9 +47,20 @@
         NodeList nodes = document.getElementsByTagName("PEGELSTATION");
         for (int i = nodes.getLength()-1; i >= 0; --i) {
             Element element = (Element)nodes.item(i);
-            Long number = numberToLong(element.getAttribute("NUMMER"));
+            String numberString = element.getAttribute("NUMMER");
+            Long number = numberToLong(numberString);
             if (number != null) {
-                map.put(number, new DIPSGauge(element));
+                DIPSGauge newG = new DIPSGauge(element);
+                DIPSGauge oldG = map.put(number, newG);
+                if (oldG != null) {
+                    log.warn("DIPS: '" + newG.getName() +
+                        "' collides with '" + oldG.getName() + 
+                        "' on gauge number " + number + ".");
+                }
+            }
+            else {
+                log.warn("DIPS: gauge '" + element.getAttribute("NAME") +
+                    "' has invalid gauge number '" + numberString + "'");
             }
         }
         return map;

http://dive4elements.wald.intevation.org