ingo@2806: package de.intevation.flys.importer.parsers; ingo@2806: ingo@2811: import java.math.BigDecimal; ingo@2806: ingo@2811: import java.text.ParseException; ingo@2811: ingo@2806: import org.apache.log4j.Logger; ingo@2806: ingo@2811: import de.intevation.flys.importer.ImportBedHeight; ingo@2806: import de.intevation.flys.importer.ImportBedHeightEpoch; ingo@2811: import de.intevation.flys.importer.ImportBedHeightEpochValue; ingo@2806: ingo@2806: felix@3958: /** Parses BedHeightEpochs from csv file. */ ingo@2811: public class BedHeightEpochParser extends BedHeightParser { ingo@2806: felix@3958: /** Our own logger. */ ingo@2806: private static final Logger log = ingo@2806: Logger.getLogger(BedHeightEpochParser.class); ingo@2806: ingo@2806: ingo@2811: @Override ingo@2811: protected ImportBedHeight newImportBedHeight(String description) { ingo@2811: return new ImportBedHeightEpoch(description); ingo@2806: } ingo@2806: ingo@2806: felix@3958: /** felix@3958: * Handle a non-comment, none-Metadata line of csv file, adding felix@3958: * ImportBedHeightEpochValues to the given ImportBedHeight object. felix@3958: */ ingo@2811: @Override ingo@2811: protected void handleDataLine(ImportBedHeight obj, String line) { ingo@2811: String[] values = line.split(SEPERATOR_CHAR); ingo@2806: felix@3958: if (values == null || values.length == 0 || values[0].length() == 0) { felix@3958: // There might be quite some ";" found. ingo@2811: //log.warn("Skip invalid data line: " + line); ingo@2811: return; ingo@2806: } ingo@2811: felix@3958: BigDecimal km; felix@3958: felix@3958: try { felix@3958: km = new BigDecimal(nf.parse(values[0]).doubleValue()); felix@3958: } felix@3958: catch (ParseException e) { tom@5490: log.warn("Unparseable number in data row: " + line); felix@3958: return; felix@3958: } felix@3958: felix@3958: felix@3958: // Handle "gap" lines like '255,0;' felix@3958: if (values.length < 2) { felix@3958: ImportBedHeightEpochValue value = new ImportBedHeightEpochValue( felix@3958: km, felix@3958: null felix@3958: ); felix@3958: felix@3958: obj.addValue(value); felix@3958: return; felix@3958: } felix@3958: ingo@2811: try { ingo@2811: ImportBedHeightEpochValue value = new ImportBedHeightEpochValue( felix@3958: km, ingo@2811: new BigDecimal(nf.parse(values[1]).doubleValue()) ingo@2811: ); ingo@2811: ingo@2811: obj.addValue(value); ingo@2811: } ingo@2811: catch (ParseException e) { tom@5490: log.warn("Unparseable number in data row: " + line); ingo@2806: } ingo@2806: } ingo@2806: } ingo@2806: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :