Mercurial > dive4elements > river
comparison flys-aft/src/main/java/org/dive4elements/river/etl/aft/DIPSGauge.java @ 5825:f529495f901d
moved directories to org.dive4elements.river.etl
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 11:42:54 +0200 |
parents | flys-aft/src/main/java/org/dive4elements/etl/aft/DIPSGauge.java@06643e440d1e |
children | 9438e9259213 |
comparison
equal
deleted
inserted
replaced
5824:06643e440d1e | 5825:f529495f901d |
---|---|
1 package de.intevation.aft; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.Calendar; | |
5 import java.util.Collections; | |
6 import java.util.Comparator; | |
7 import java.util.Date; | |
8 import java.util.List; | |
9 | |
10 import java.util.regex.Matcher; | |
11 import java.util.regex.Pattern; | |
12 | |
13 import org.apache.log4j.Logger; | |
14 | |
15 import org.w3c.dom.Element; | |
16 import org.w3c.dom.NodeList; | |
17 | |
18 public class DIPSGauge | |
19 { | |
20 private static Logger log = Logger.getLogger(DIPSGauge.class); | |
21 | |
22 public static final Pattern DATE_PATTERN = Pattern.compile( | |
23 "(\\d{4})-(\\d{2})-(\\d{2})\\s+(\\d{2}):(\\d{2}):(\\d{2})"); | |
24 | |
25 public static final Comparator<Datum> DATE_CMP = new Comparator<Datum>() { | |
26 public int compare(Datum a, Datum b) { | |
27 return a.date.compareTo(b.date); | |
28 } | |
29 }; | |
30 | |
31 public static class Datum { | |
32 | |
33 protected double value; | |
34 protected Date date; | |
35 | |
36 public Datum() { | |
37 } | |
38 | |
39 public Datum(Element element) { | |
40 value = Double.parseDouble(element.getAttribute("WERT")); | |
41 String dateString = element.getAttribute("GUELTIGAB"); | |
42 if (dateString.length() == 0) { | |
43 throw | |
44 new IllegalArgumentException("missing GUELTIGAB attribute"); | |
45 } | |
46 Matcher m = DATE_PATTERN.matcher(dateString); | |
47 if (!m.matches()) { | |
48 throw | |
49 new IllegalArgumentException("GUELTIGAB does not match"); | |
50 } | |
51 | |
52 int year = Integer.parseInt(m.group(1)); | |
53 int month = Integer.parseInt(m.group(2)); | |
54 int day = Integer.parseInt(m.group(3)); | |
55 int hours = Integer.parseInt(m.group(4)); | |
56 int mins = Integer.parseInt(m.group(5)); | |
57 int secs = Integer.parseInt(m.group(6)); | |
58 | |
59 Calendar cal = Calendar.getInstance(); | |
60 cal.set(year, month, day, hours, mins, secs); | |
61 | |
62 date = cal.getTime(); | |
63 } | |
64 | |
65 public double getValue() { | |
66 return value; | |
67 } | |
68 | |
69 public void setValue(double value) { | |
70 this.value = value; | |
71 } | |
72 | |
73 public Date getDate() { | |
74 return date; | |
75 } | |
76 | |
77 public void setDate(Date date) { | |
78 this.date = date; | |
79 } | |
80 } // class datum | |
81 | |
82 protected double aeo; | |
83 | |
84 protected double station; | |
85 | |
86 protected String name; | |
87 | |
88 protected String riverName; | |
89 | |
90 protected List<Datum> datums; | |
91 | |
92 protected int flysId; | |
93 | |
94 protected String aftName; | |
95 | |
96 protected Long officialNumber; | |
97 | |
98 public DIPSGauge() { | |
99 } | |
100 | |
101 public DIPSGauge(Element element) { | |
102 | |
103 name = element.getAttribute("NAME"); | |
104 riverName = element.getAttribute("GEWAESSER"); | |
105 | |
106 String aeoString = element.getAttribute("EINZUGSGEBIET_AEO"); | |
107 if (aeoString.length() == 0) { | |
108 log.warn("DIPS: Setting AEO of gauge '" + name + "' to zero."); | |
109 aeoString = "0"; | |
110 } | |
111 aeo = Double.parseDouble(aeoString); | |
112 | |
113 String stationString = element.getAttribute("STATIONIERUNG"); | |
114 if (stationString.length() == 0) { | |
115 log.warn("DIPS: Setting station of gauge '" + name + "' to zero."); | |
116 stationString = "-99999"; | |
117 } | |
118 station = Double.parseDouble(stationString); | |
119 if (station == 0d) { | |
120 log.warn("DIPS: Station of gauge '" + name + "' is zero."); | |
121 } | |
122 | |
123 datums = new ArrayList<Datum>(); | |
124 NodeList nodes = element.getElementsByTagName("PNP"); | |
125 for (int i = 0, N = nodes.getLength(); i < N; ++i) { | |
126 Element e = (Element)nodes.item(i); | |
127 Datum datum = new Datum(e); | |
128 datums.add(datum); | |
129 } | |
130 Collections.sort(datums, DATE_CMP); | |
131 } | |
132 | |
133 public List<Datum> getDatums() { | |
134 return datums; | |
135 } | |
136 | |
137 public String getName() { | |
138 return name; | |
139 } | |
140 | |
141 public String getRiverName() { | |
142 return riverName; | |
143 } | |
144 | |
145 public int getFlysId() { | |
146 return flysId; | |
147 } | |
148 | |
149 public void setFlysId(int flysId) { | |
150 this.flysId = flysId; | |
151 } | |
152 | |
153 public String getAftName() { | |
154 return aftName != null ? aftName : name; | |
155 } | |
156 | |
157 public void setAftName(String aftName) { | |
158 this.aftName = aftName; | |
159 } | |
160 | |
161 public double getStation() { | |
162 return station; | |
163 } | |
164 | |
165 public double getAeo() { | |
166 return aeo; | |
167 } | |
168 | |
169 public void setAeo(double aeo) { | |
170 this.aeo = aeo; | |
171 } | |
172 | |
173 public void setStation(double station) { | |
174 this.station = station; | |
175 } | |
176 | |
177 public boolean hasDatums() { | |
178 return !datums.isEmpty(); | |
179 } | |
180 | |
181 public Datum getLatestDatum() { | |
182 return datums.get(datums.size()-1); | |
183 } | |
184 | |
185 public Long getOfficialNumber() { | |
186 return officialNumber; | |
187 } | |
188 | |
189 public void setOfficialNumber(Long officialNumber) { | |
190 this.officialNumber = officialNumber; | |
191 } | |
192 } | |
193 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |