Mercurial > dive4elements > river
comparison flys-backend/src/main/java/org/dive4elements/river/importer/parsers/FlowVelocityMeasurementParser.java @ 5828:dfb26b03b179
Moved directories to org.dive4elements.river
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 11:53:11 +0200 |
parents | flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java@91a2ddffea47 |
children | 18619c1e7c2a |
comparison
equal
deleted
inserted
replaced
5827:e308d4ecd35a | 5828:dfb26b03b179 |
---|---|
1 package de.intevation.flys.importer.parsers; | |
2 | |
3 import de.intevation.flys.importer.ImportFlowVelocityMeasurement; | |
4 import de.intevation.flys.importer.ImportFlowVelocityMeasurementValue; | |
5 | |
6 import java.math.BigDecimal; | |
7 | |
8 import java.text.DateFormat; | |
9 import java.text.NumberFormat; | |
10 import java.text.ParseException; | |
11 import java.text.SimpleDateFormat; | |
12 | |
13 import java.util.ArrayList; | |
14 import java.util.List; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 public class FlowVelocityMeasurementParser extends LineParser { | |
18 | |
19 private static final Logger log = | |
20 Logger.getLogger(FlowVelocityMeasurementParser.class); | |
21 | |
22 private static final NumberFormat nf = | |
23 NumberFormat.getInstance(DEFAULT_LOCALE); | |
24 | |
25 private static final DateFormat df = | |
26 new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); | |
27 | |
28 | |
29 private List<ImportFlowVelocityMeasurement> measurements; | |
30 | |
31 private ImportFlowVelocityMeasurement current; | |
32 | |
33 | |
34 public FlowVelocityMeasurementParser() { | |
35 measurements = new ArrayList<ImportFlowVelocityMeasurement>(); | |
36 } | |
37 | |
38 | |
39 public List<ImportFlowVelocityMeasurement> getMeasurements() { | |
40 return measurements; | |
41 } | |
42 | |
43 @Override | |
44 protected void reset() { | |
45 current = new ImportFlowVelocityMeasurement(); | |
46 } | |
47 | |
48 | |
49 @Override | |
50 protected void finish() { | |
51 current.setDescription(fileName); | |
52 measurements.add(current); | |
53 } | |
54 | |
55 | |
56 @Override | |
57 protected void handleLine(int lineNum, String line) { | |
58 if (line.startsWith(START_META_CHAR)) { | |
59 handleMetaLine(stripMetaLine(line)); | |
60 } | |
61 else { | |
62 handleDataLine(line); | |
63 } | |
64 } | |
65 | |
66 | |
67 public void handleMetaLine(String line) { | |
68 } | |
69 | |
70 | |
71 public void handleDataLine(String line) { | |
72 String[] cols = line.split(SEPERATOR_CHAR); | |
73 | |
74 if (cols.length < 8) { | |
75 log.warn("skip invalid data line: '" + line + "'"); | |
76 return; | |
77 } | |
78 | |
79 try { | |
80 double km = nf.parse(cols[1]).doubleValue(); | |
81 double w = nf.parse(cols[5]).doubleValue(); | |
82 double q = nf.parse(cols[6]).doubleValue(); | |
83 double v = nf.parse(cols[7]).doubleValue(); | |
84 | |
85 String timestr = cols[3] + " " + cols[4]; | |
86 String description = cols.length > 8 ? cols[8] : null; | |
87 | |
88 current.addValue(new ImportFlowVelocityMeasurementValue( | |
89 df.parse(timestr), | |
90 new BigDecimal(km), | |
91 new BigDecimal(w), | |
92 new BigDecimal(q), | |
93 new BigDecimal(v), | |
94 description | |
95 )); | |
96 } | |
97 catch (ParseException pe) { | |
98 log.warn("Unparseable flow velocity values:", pe); | |
99 } | |
100 } | |
101 } | |
102 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |