# HG changeset patch # User Felix Wolfsteller # Date 1348750526 0 # Node ID 64b73dc1571c21e6b5a0ebf0033acf7b4c9aa3a7 # Parent 3825aad9fb41baf145f9c00dcb6389409ec75e11 fix issue863: Handle missing data points for epoch bed height data. flys-backend/trunk@5617 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 3825aad9fb41 -r 64b73dc1571c flys-backend/ChangeLog --- a/flys-backend/ChangeLog Thu Sep 27 12:53:09 2012 +0000 +++ b/flys-backend/ChangeLog Thu Sep 27 12:55:26 2012 +0000 @@ -1,3 +1,10 @@ +2012-09-27 Felix Wolfsteller + + Backend-part for fix of issue863. + + * src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java: + Handle missing data points. + 2012-09-27 Felix Wolfsteller * src/main/java/de/intevation/flys/importer/ImportBedHeightEpoch.java: diff -r 3825aad9fb41 -r 64b73dc1571c flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java --- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java Thu Sep 27 12:53:09 2012 +0000 +++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/BedHeightEpochParser.java Thu Sep 27 12:55:26 2012 +0000 @@ -1,12 +1,9 @@ package de.intevation.flys.importer.parsers; - import java.math.BigDecimal; import java.text.ParseException; - - import org.apache.log4j.Logger; import de.intevation.flys.importer.ImportBedHeight; @@ -14,32 +11,59 @@ import de.intevation.flys.importer.ImportBedHeightEpochValue; +/** Parses BedHeightEpochs from csv file. */ public class BedHeightEpochParser extends BedHeightParser { + /** Our own logger. */ private static final Logger log = Logger.getLogger(BedHeightEpochParser.class); - @Override protected ImportBedHeight newImportBedHeight(String description) { return new ImportBedHeightEpoch(description); } + /** + * Handle a non-comment, none-Metadata line of csv file, adding + * ImportBedHeightEpochValues to the given ImportBedHeight object. + */ @Override protected void handleDataLine(ImportBedHeight obj, String line) { - // TODO issue863: find gaps in data, analogous to 'single' case. String[] values = line.split(SEPERATOR_CHAR); - if (values == null || values.length < 2 || values[0].length() == 0 || values[1].length() == 0) { + if (values == null || values.length == 0 || values[0].length() == 0) { + // There might be quite some ";" found. //log.warn("Skip invalid data line: " + line); return; } + BigDecimal km; + + try { + km = new BigDecimal(nf.parse(values[0]).doubleValue()); + } + catch (ParseException e) { + log.warn("Error while parsing number from data row: " + line); + return; + } + + + // Handle "gap" lines like '255,0;' + if (values.length < 2) { + ImportBedHeightEpochValue value = new ImportBedHeightEpochValue( + km, + null + ); + + obj.addValue(value); + return; + } + try { ImportBedHeightEpochValue value = new ImportBedHeightEpochValue( - new BigDecimal(nf.parse(values[0]).doubleValue()), + km, new BigDecimal(nf.parse(values[1]).doubleValue()) );