comparison flys-backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightEpochParser.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/BedHeightEpochParser.java@b3dd14fc13a6
children 18619c1e7c2a
comparison
equal deleted inserted replaced
5827:e308d4ecd35a 5828:dfb26b03b179
1 package de.intevation.flys.importer.parsers;
2
3 import java.math.BigDecimal;
4
5 import java.text.ParseException;
6
7 import org.apache.log4j.Logger;
8
9 import de.intevation.flys.importer.ImportBedHeight;
10 import de.intevation.flys.importer.ImportBedHeightEpoch;
11 import de.intevation.flys.importer.ImportBedHeightEpochValue;
12
13
14 /** Parses BedHeightEpochs from csv file. */
15 public class BedHeightEpochParser extends BedHeightParser {
16
17 /** Our own logger. */
18 private static final Logger log =
19 Logger.getLogger(BedHeightEpochParser.class);
20
21
22 @Override
23 protected ImportBedHeight newImportBedHeight(String description) {
24 return new ImportBedHeightEpoch(description);
25 }
26
27
28 /**
29 * Handle a non-comment, none-Metadata line of csv file, adding
30 * ImportBedHeightEpochValues to the given ImportBedHeight object.
31 */
32 @Override
33 protected void handleDataLine(ImportBedHeight obj, String line) {
34 String[] values = line.split(SEPERATOR_CHAR);
35
36 if (values == null || values.length == 0 || values[0].length() == 0) {
37 // There might be quite some ";" found.
38 //log.warn("Skip invalid data line: " + line);
39 return;
40 }
41
42 BigDecimal km;
43
44 try {
45 km = new BigDecimal(nf.parse(values[0]).doubleValue());
46 }
47 catch (ParseException e) {
48 log.warn("Unparseable number in data row: " + line);
49 return;
50 }
51
52
53 // Handle "gap" lines like '255,0;'
54 if (values.length < 2) {
55 ImportBedHeightEpochValue value = new ImportBedHeightEpochValue(
56 km,
57 null
58 );
59
60 obj.addValue(value);
61 return;
62 }
63
64 try {
65 ImportBedHeightEpochValue value = new ImportBedHeightEpochValue(
66 km,
67 new BigDecimal(nf.parse(values[1]).doubleValue())
68 );
69
70 obj.addValue(value);
71 }
72 catch (ParseException e) {
73 log.warn("Unparseable number in data row: " + line);
74 }
75 }
76 }
77 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org