Mercurial > dive4elements > river
view flys-backend/src/main/java/de/intevation/flys/importer/parsers/FlowVelocityMeasurementParser.java @ 4768:99f9e371371b
Move distance calculation to Coordinate class. Use inheritance instead of composition in Anchor class. Made Anchor class static. Use epsilon equal comparision when checking for same station: Boy, do you ever learn that sharp equal comparison of doubles is not a clever idea!?
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 04 Jan 2013 15:35:51 +0100 |
parents | f63b39799d2d |
children | b3dd14fc13a6 |
line wrap: on
line source
package de.intevation.flys.importer.parsers; import de.intevation.flys.importer.ImportFlowVelocityMeasurement; import de.intevation.flys.importer.ImportFlowVelocityMeasurementValue; import java.math.BigDecimal; import java.text.DateFormat; import java.text.NumberFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; public class FlowVelocityMeasurementParser extends LineParser { private static final Logger log = Logger.getLogger(FlowVelocityMeasurementParser.class); private static final NumberFormat nf = NumberFormat.getInstance(DEFAULT_LOCALE); private static final DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); private List<ImportFlowVelocityMeasurement> measurements; private ImportFlowVelocityMeasurement current; public FlowVelocityMeasurementParser() { measurements = new ArrayList<ImportFlowVelocityMeasurement>(); } public List<ImportFlowVelocityMeasurement> getMeasurements() { return measurements; } @Override protected void reset() { current = new ImportFlowVelocityMeasurement(); } @Override protected void finish() { measurements.add(current); } @Override protected void handleLine(int lineNum, String line) { if (line.startsWith(START_META_CHAR)) { handleMetaLine(stripMetaLine(line)); } else { handleDataLine(line); } } public void handleMetaLine(String line) { line = line.replace(";", ""); current.setDescription(line); } public void handleDataLine(String line) { String[] cols = line.split(SEPERATOR_CHAR); if (cols.length < 8) { log.warn("skip invalid data line: '" + line + "'"); return; } try { double km = nf.parse(cols[1]).doubleValue(); double w = nf.parse(cols[5]).doubleValue(); double q = nf.parse(cols[6]).doubleValue(); double v = nf.parse(cols[7]).doubleValue(); String timestr = cols[3] + " " + cols[4]; String description = cols.length > 8 ? cols[8] : null; current.addValue(new ImportFlowVelocityMeasurementValue( df.parse(timestr), new BigDecimal(km), new BigDecimal(w), new BigDecimal(q), new BigDecimal(v), description )); } catch (ParseException pe) { log.warn("Error while parsing flow velocity values.", pe); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :