Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java @ 3958:64b73dc1571c
fix issue863: Handle missing data points for epoch bed height data.
flys-backend/trunk@5617 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Thu, 27 Sep 2012 12:55:26 +0000 |
parents | 26685b846a29 |
children | b3dd14fc13a6 |
comparison
equal
deleted
inserted
replaced
3957:3825aad9fb41 | 3958:64b73dc1571c |
---|---|
1 package de.intevation.flys.importer.parsers; | 1 package de.intevation.flys.importer.parsers; |
2 | |
3 | 2 |
4 import java.math.BigDecimal; | 3 import java.math.BigDecimal; |
5 | 4 |
6 import java.text.ParseException; | 5 import java.text.ParseException; |
7 | |
8 | |
9 | 6 |
10 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
11 | 8 |
12 import de.intevation.flys.importer.ImportBedHeight; | 9 import de.intevation.flys.importer.ImportBedHeight; |
13 import de.intevation.flys.importer.ImportBedHeightEpoch; | 10 import de.intevation.flys.importer.ImportBedHeightEpoch; |
14 import de.intevation.flys.importer.ImportBedHeightEpochValue; | 11 import de.intevation.flys.importer.ImportBedHeightEpochValue; |
15 | 12 |
16 | 13 |
14 /** Parses BedHeightEpochs from csv file. */ | |
17 public class BedHeightEpochParser extends BedHeightParser { | 15 public class BedHeightEpochParser extends BedHeightParser { |
18 | 16 |
17 /** Our own logger. */ | |
19 private static final Logger log = | 18 private static final Logger log = |
20 Logger.getLogger(BedHeightEpochParser.class); | 19 Logger.getLogger(BedHeightEpochParser.class); |
21 | |
22 | 20 |
23 | 21 |
24 @Override | 22 @Override |
25 protected ImportBedHeight newImportBedHeight(String description) { | 23 protected ImportBedHeight newImportBedHeight(String description) { |
26 return new ImportBedHeightEpoch(description); | 24 return new ImportBedHeightEpoch(description); |
27 } | 25 } |
28 | 26 |
29 | 27 |
28 /** | |
29 * Handle a non-comment, none-Metadata line of csv file, adding | |
30 * ImportBedHeightEpochValues to the given ImportBedHeight object. | |
31 */ | |
30 @Override | 32 @Override |
31 protected void handleDataLine(ImportBedHeight obj, String line) { | 33 protected void handleDataLine(ImportBedHeight obj, String line) { |
32 // TODO issue863: find gaps in data, analogous to 'single' case. | |
33 String[] values = line.split(SEPERATOR_CHAR); | 34 String[] values = line.split(SEPERATOR_CHAR); |
34 | 35 |
35 if (values == null || values.length < 2 || values[0].length() == 0 || values[1].length() == 0) { | 36 if (values == null || values.length == 0 || values[0].length() == 0) { |
37 // There might be quite some ";" found. | |
36 //log.warn("Skip invalid data line: " + line); | 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("Error while parsing number from 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); | |
37 return; | 61 return; |
38 } | 62 } |
39 | 63 |
40 try { | 64 try { |
41 ImportBedHeightEpochValue value = new ImportBedHeightEpochValue( | 65 ImportBedHeightEpochValue value = new ImportBedHeightEpochValue( |
42 new BigDecimal(nf.parse(values[0]).doubleValue()), | 66 km, |
43 new BigDecimal(nf.parse(values[1]).doubleValue()) | 67 new BigDecimal(nf.parse(values[1]).doubleValue()) |
44 ); | 68 ); |
45 | 69 |
46 obj.addValue(value); | 70 obj.addValue(value); |
47 } | 71 } |