comparison flys-aft/src/main/java/de/intevation/aft/River.java @ 4079:42094f01afa6

Added model for DIPS gauges. flys-aft/trunk@3454 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 16 Dec 2011 17:34:11 +0000
parents 0944cdd2ee90
children 7a7b0f0cb653
comparison
equal deleted inserted replaced
4078:0944cdd2ee90 4079:42094f01afa6
8 8
9 import org.apache.log4j.Logger; 9 import org.apache.log4j.Logger;
10 10
11 import org.w3c.dom.Document; 11 import org.w3c.dom.Document;
12 import org.w3c.dom.NodeList; 12 import org.w3c.dom.NodeList;
13 import org.w3c.dom.Node;
14 import org.w3c.dom.Element; 13 import org.w3c.dom.Element;
15 14
16 import de.intevation.db.ConnectedStatements; 15 import de.intevation.db.ConnectedStatements;
16
17 import java.util.regex.Matcher;
18 import java.util.regex.Pattern;
17 19
18 public class River 20 public class River
19 extends IdPair 21 extends IdPair
20 { 22 {
21 private static Logger log = Logger.getLogger(River.class); 23 private static Logger log = Logger.getLogger(River.class);
24
25 public static final Pattern NUMBER = Pattern.compile("0*([0-9]+)");
22 26
23 protected String name; 27 protected String name;
24 28
25 public River() { 29 public River() {
26 } 30 }
32 36
33 public String getName() { 37 public String getName() {
34 return name; 38 return name;
35 } 39 }
36 40
37 protected static Map<Integer, Element> indexByNumber(Document document) { 41 public static Long numberToLong(String s) {
38 Map<Integer, Element> map = new HashMap<Integer, Element>(); 42 Matcher m = NUMBER.matcher(s);
43 if (!m.matches()) return null;
44 String ns = m.group(1);
45 return Long.valueOf(ns.length() == 0 ? "0": ns);
46 }
47
48 public static Map<Long, DIPSGauge> indexByNumber(Document document) {
49 Map<Long, DIPSGauge> map = new HashMap<Long, DIPSGauge>();
39 NodeList nodes = document.getElementsByTagName("PEGELSTATION"); 50 NodeList nodes = document.getElementsByTagName("PEGELSTATION");
40 for (int i = nodes.getLength()-1; i >= 0; --i) { 51 for (int i = nodes.getLength()-1; i >= 0; --i) {
41 Element element = (Element)nodes.item(i); 52 Element element = (Element)nodes.item(i);
42 String number = element.getAttribute("NUMMER"); 53 Long number = numberToLong(element.getAttribute("NUMMER"));
54 if (number != null) {
55 map.put(number, new DIPSGauge(element));
56 }
43 } 57 }
44 return map; 58 return map;
45 } 59 }
46 60
47 public void sync(SyncContext context) throws SQLException { 61 public void sync(SyncContext context) throws SQLException {
73 String name = gaugesRs.getString("name"); 87 String name = gaugesRs.getString("name");
74 System.err.println(name + ": " + gaugeId); 88 System.err.println(name + ": " + gaugeId);
75 } 89 }
76 90
77 gaugesRs.close(); 91 gaugesRs.close();
92
93 Map<Long, DIPSGauge> map = indexByNumber(context.getDips());
78 } 94 }
79 95
80 public String toString() { 96 public String toString() {
81 return "[River: name=" + name + ", " + super.toString() + "]"; 97 return "[River: name=" + name + ", " + super.toString() + "]";
82 } 98 }

http://dive4elements.wald.intevation.org