changeset 4084:9178beeb7b05

Moved DIPS gauge number -> DIPS gauge index. flys-aft/trunk@3514 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 21 Dec 2011 15:16:58 +0000
parents 44dc38ca8492
children 067341e86375
files flys-aft/ChangeLog flys-aft/src/main/java/de/intevation/aft/River.java flys-aft/src/main/java/de/intevation/aft/SyncContext.java
diffstat 3 files changed, 64 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/flys-aft/ChangeLog	Wed Dec 21 14:56:29 2011 +0000
+++ b/flys-aft/ChangeLog	Wed Dec 21 15:16:58 2011 +0000
@@ -1,3 +1,11 @@
+2011-12-20	Sascha L. Teichmann	<sascha.teichmann@inteavtion.de>
+
+	* src/main/java/de/intevation/aft/River.java: Removed
+	  index DIPS gauge number -> DIPS gauge.
+
+	* src/main/java/de/intevation/aft/SyncContext.java: Readded
+	  here, because the index can be shared by all rivers.
+
 2011-12-20	Sascha L. Teichmann	<sascha.teichmann@inteavtion.de>
 
 	* doc/repair.xsl: Repair XSL transform which brings the 
--- a/flys-aft/src/main/java/de/intevation/aft/River.java	Wed Dec 21 14:56:29 2011 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/River.java	Wed Dec 21 15:16:58 2011 +0000
@@ -1,17 +1,12 @@
 package de.intevation.aft;
 
 import java.util.Map;
-import java.util.HashMap;
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
 import org.apache.log4j.Logger;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Element;
-
 import de.intevation.db.ConnectedStatements;
 
 public class River
@@ -33,43 +28,11 @@
         return name;
     }
 
-    public static Long numberToLong(String s) {
-        try {
-            return Long.valueOf(s.trim());
-        }
-        catch (NumberFormatException nfe) {
-        }
-        return null;
-    }
-
-    public static Map<Long, DIPSGauge> indexByNumber(Document document) {
-        Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>();
-        NodeList nodes = document.getElementsByTagName("PEGELSTATION");
-        for (int i = nodes.getLength()-1; i >= 0; --i) {
-            Element element = (Element)nodes.item(i);
-            String numberString = element.getAttribute("NUMMER");
-            Long number = numberToLong(numberString);
-            if (number != null) {
-                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;
-    }
 
     public void sync(SyncContext context) throws SQLException {
         log.info("sync river: " + this);
 
-        Map<Long, DIPSGauge> dipsGauges = indexByNumber(context.getDips());
+        Map<Long, DIPSGauge> dipsGauges = context.getDIPSGauges();
 
         ConnectedStatements flysStatements = context.getFlysStatements();
         ConnectedStatements aftStatements  = context.getAftStatements();
@@ -82,7 +45,7 @@
         while (messstellenRs.next()) {
             String name = messstellenRs.getString("NAME");
             String num  = messstellenRs.getString("MESSSTELLE_NR");
-            Long number = numberToLong(num);
+            Long number = SyncContext.numberToLong(num);
             if (number == null) {
                 log.warn("Invalid MESSSTELLE_NR for MESSSTELLE '"+name+"'");
                 continue;
--- a/flys-aft/src/main/java/de/intevation/aft/SyncContext.java	Wed Dec 21 14:56:29 2011 +0000
+++ b/flys-aft/src/main/java/de/intevation/aft/SyncContext.java	Wed Dec 21 15:16:58 2011 +0000
@@ -1,14 +1,25 @@
 package de.intevation.aft;
 
+import java.util.Map;
+import java.util.HashMap;
+
+import org.w3c.dom.Document;
+
 import de.intevation.db.ConnectedStatements;
 
-import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Element;
+
+import org.apache.log4j.Logger;
 
 public class SyncContext
 {
-    protected ConnectedStatements aftStatements;
-    protected ConnectedStatements flysStatements;
-    protected Document            dips;
+    private static Logger log = Logger.getLogger(SyncContext.class);
+
+    protected ConnectedStatements  aftStatements;
+    protected ConnectedStatements  flysStatements;
+    protected Document             dips;
+    protected Map<Long, DIPSGauge> numberToGauge;
 
     public SyncContext() {
     }
@@ -21,6 +32,7 @@
         this.aftStatements  = aftStatements;
         this.flysStatements = flysStatements;
         this.dips           = dips;
+        numberToGauge       = indexByNumber(dips);
     }
 
     public ConnectedStatements getAftStatements() {
@@ -51,6 +63,44 @@
         aftStatements.close();
         flysStatements.close();
     }
+
+    public static Long numberToLong(String s) {
+        try {
+            return Long.valueOf(s.trim());
+        }
+        catch (NumberFormatException nfe) {
+        }
+        return null;
+    }
+
+    public Map<Long, DIPSGauge> getDIPSGauges() {
+        return numberToGauge;
+    }
+
+    protected static Map<Long, DIPSGauge> indexByNumber(Document document) {
+        Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>();
+        NodeList nodes = document.getElementsByTagName("PEGELSTATION");
+        for (int i = nodes.getLength()-1; i >= 0; --i) {
+            Element element = (Element)nodes.item(i);
+            String numberString = element.getAttribute("NUMMER");
+            Long number = numberToLong(numberString);
+            if (number != null) {
+                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;
+    }
+
 }
 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
 

http://dive4elements.wald.intevation.org