comparison backend/src/main/java/org/dive4elements/river/importer/parsers/FlowVelocityMeasurementParser.java @ 7730:e1b831fe435a slt-simplify-cross-sections

Merged default into slt-simplify-cross-sections branch and updated package and class names.
author Tom Gottfried <tom@intevation.de>
date Mon, 20 Jan 2014 14:04:20 +0100
parents 4c3ccf2b0304
children 2693bfaf503d 0a5239a1e46e
comparison
equal deleted inserted replaced
5084:ca45dd039b54 7730:e1b831fe435a
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.importer.parsers;
10
11 import org.dive4elements.river.importer.ImportFlowVelocityMeasurement;
12 import org.dive4elements.river.importer.ImportFlowVelocityMeasurementValue;
13
14 import java.math.BigDecimal;
15
16 import java.text.DateFormat;
17 import java.text.NumberFormat;
18 import java.text.ParseException;
19 import java.text.SimpleDateFormat;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24 import org.apache.log4j.Logger;
25 public class FlowVelocityMeasurementParser extends LineParser {
26
27 private static final Logger log =
28 Logger.getLogger(FlowVelocityMeasurementParser.class);
29
30 private static final NumberFormat nf =
31 NumberFormat.getInstance(DEFAULT_LOCALE);
32
33 private static final DateFormat df =
34 new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
35
36
37 private List<ImportFlowVelocityMeasurement> measurements;
38
39 private ImportFlowVelocityMeasurement current;
40
41
42 public FlowVelocityMeasurementParser() {
43 measurements = new ArrayList<ImportFlowVelocityMeasurement>();
44 }
45
46
47 public List<ImportFlowVelocityMeasurement> getMeasurements() {
48 return measurements;
49 }
50
51 @Override
52 protected void reset() {
53 current = new ImportFlowVelocityMeasurement();
54 }
55
56
57 @Override
58 protected void finish() {
59 current.setDescription(fileName);
60 measurements.add(current);
61 }
62
63
64 @Override
65 protected void handleLine(int lineNum, String line) {
66 if (line.startsWith(START_META_CHAR)) {
67 handleMetaLine(stripMetaLine(line));
68 }
69 else {
70 handleDataLine(line);
71 }
72 }
73
74
75 public void handleMetaLine(String line) {
76 }
77
78
79 public void handleDataLine(String line) {
80 String[] cols = line.split(SEPERATOR_CHAR);
81
82 if (cols.length < 8) {
83 log.warn("skip invalid data line: '" + line + "'");
84 return;
85 }
86
87 try {
88 double km = nf.parse(cols[1]).doubleValue();
89 double w = nf.parse(cols[5]).doubleValue();
90 double q = nf.parse(cols[6]).doubleValue();
91 double v = nf.parse(cols[7]).doubleValue();
92
93 String timestr = cols[3] + " " + cols[4];
94 String description = cols.length > 8 ? cols[8] : null;
95
96 current.addValue(new ImportFlowVelocityMeasurementValue(
97 df.parse(timestr),
98 new BigDecimal(km),
99 new BigDecimal(w),
100 new BigDecimal(q),
101 new BigDecimal(v),
102 description
103 ));
104 }
105 catch (ParseException pe) {
106 log.warn("Unparseable flow velocity values:", pe);
107 }
108 }
109 }
110 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org