# HG changeset patch # User Sascha L. Teichmann # Date 1324061486 0 # Node ID fd6d0bc84117bcc3bb54e7620662c24a9da15c40 # Parent 42094f01afa6ef0a866398c50470f8c0a590c004 Parse PNP from DIPS, too. flys-aft/trunk@3455 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 42094f01afa6 -r fd6d0bc84117 flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java --- a/flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java Fri Dec 16 17:34:11 2011 +0000 +++ b/flys-aft/src/main/java/de/intevation/aft/DIPSGauge.java Fri Dec 16 18:51:26 2011 +0000 @@ -1,16 +1,95 @@ package de.intevation.aft; import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import java.util.ArrayList; +import java.util.List; +import java.util.Date; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; + +import java.util.regex.Pattern; +import java.util.regex.Matcher; + +import org.apache.log4j.Logger; public class DIPSGauge { + private static Logger log = Logger.getLogger(DIPSGauge.class); + + public static final Pattern DATE_PATTERN = Pattern.compile( + "(\\d{4})-(\\d{2})-(\\d{2})\\s+(\\d{2}):(\\d{2}):(\\d{2})"); + + public static final Comparator DATE_CMP = new Comparator() { + public int compare(Datum a, Datum b) { + return a.date.compareTo(b.date); + } + }; + + public static class Datum { + + protected double value; + protected Date date; + + public Datum() { + } + + public Datum(Element element) { + value = Double.parseDouble(element.getAttribute("WERT")); + String dateString = element.getAttribute("GUELTIGAB"); + if (dateString.length() == 0) { + throw + new IllegalArgumentException("missing GUELTIGAB attribute"); + } + Matcher m = DATE_PATTERN.matcher(dateString); + if (!m.matches()) { + throw + new IllegalArgumentException("GUELTIGAB does not match"); + } + + int year = Integer.parseInt(m.group(1)); + int month = Integer.parseInt(m.group(2)); + int day = Integer.parseInt(m.group(3)); + int hours = Integer.parseInt(m.group(4)); + int mins = Integer.parseInt(m.group(5)); + int secs = Integer.parseInt(m.group(6)); + + Calendar cal = Calendar.getInstance(); + cal.set(year, month, day, hours, mins, secs); + + date = cal.getTime(); + } + } // class datum + protected double aeo; + protected List datums; + public DIPSGauge() { } public DIPSGauge(Element element) { - aeo = Double.parseDouble(element.getAttribute("EINZUGSGEBIET_AEO")); + String aeoString = element.getAttribute("EINZUGSGEBIET_AEO"); + if (aeoString.length() == 0) { + log.warn("WARN: setting AEO to zero"); + aeoString = "0"; + } + aeo = Double.parseDouble(aeoString); + + datums = new ArrayList(); + NodeList nodes = element.getElementsByTagName("PNP"); + for (int i = 0, N = nodes.getLength(); i < N; ++i) { + Element e = (Element)nodes.item(i); + Datum datum = new Datum(e); + datums.add(datum); + } + Collections.sort(datums, DATE_CMP); + } + + public List getDatums() { + return datums; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :