Mercurial > dive4elements > river
changeset 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 | fd6d0bc84117 |
files | flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java flys-aft/src/main/java/de/intevation/aft/River.java |
diffstat | 2 files changed, 36 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java Fri Dec 16 17:34:11 2011 +0000 @@ -0,0 +1,16 @@ +package de.intevation.aft; + +import org.w3c.dom.Element; + +public class DIPSGauge +{ + protected double aeo; + + public DIPSGauge() { + } + + public DIPSGauge(Element element) { + aeo = Double.parseDouble(element.getAttribute("EINZUGSGEBIET_AEO")); + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-aft/src/main/java/de/intevation/aft/River.java Fri Dec 16 17:10:14 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/River.java Fri Dec 16 17:34:11 2011 +0000 @@ -10,16 +10,20 @@ import org.w3c.dom.Document; import org.w3c.dom.NodeList; -import org.w3c.dom.Node; import org.w3c.dom.Element; 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() { @@ -34,12 +38,22 @@ return name; } - protected static Map<Integer, Element> indexByNumber(Document document) { - Map<Integer, Element> map = new HashMap<Integer, Element>(); + 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); + } + + 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 number = element.getAttribute("NUMMER"); + Long number = numberToLong(element.getAttribute("NUMMER")); + if (number != null) { + map.put(number, new DIPSGauge(element)); + } } return map; } @@ -75,6 +89,8 @@ } gaugesRs.close(); + + Map<Long, DIPSGauge> map = indexByNumber(context.getDips()); } public String toString() {