[PATCH 27 of 45] Abstract parser for bed heights is obsolete
Wald Commits
scm-commit at wald.intevation.org
Tue Mar 10 17:05:55 CET 2015
# HG changeset patch
# User "Tom Gottfried <tom at intevation.de>"
# Date 1424076639 -3600
# Node ID 29ab66ce06aa811296e57e03418ddb5adc4b9fa4
# Parent d115d0ed6624b8daa7fbbd95426a78ab0c9c5014
Abstract parser for bed heights is obsolete.
diff -r d115d0ed6624 -r 29ab66ce06aa backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java
--- a/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java Mon Feb 16 09:35:06 2015 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/ImportRiver.java Mon Feb 16 09:50:39 2015 +0100
@@ -14,7 +14,7 @@
import org.dive4elements.river.importer.parsers.AnnotationClassifier;
import org.dive4elements.river.importer.parsers.AnnotationsParser;
-import org.dive4elements.river.importer.parsers.BedHeightSingleParser;
+import org.dive4elements.river.importer.parsers.BedHeightParser;
import org.dive4elements.river.importer.parsers.CrossSectionParser;
import org.dive4elements.river.importer.parsers.DA50Parser;
import org.dive4elements.river.importer.parsers.DA66Parser;
@@ -826,7 +826,7 @@
return;
}
- BedHeightSingleParser parser = new BedHeightSingleParser();
+ BedHeightParser parser = new BedHeightParser();
for (File file: files) {
parser.parse(file);
diff -r d115d0ed6624 -r 29ab66ce06aa backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java Mon Feb 16 09:35:06 2015 +0100
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java Mon Feb 16 09:50:39 2015 +0100
@@ -32,6 +32,7 @@
import org.apache.log4j.Logger;
import org.dive4elements.river.importer.ImportBedHeightSingle;
+import org.dive4elements.river.importer.ImportBedHeightSingleValue;
import org.dive4elements.river.importer.ImportBedHeightType;
import org.dive4elements.river.importer.ImportElevationModel;
import org.dive4elements.river.importer.ImportLocationSystem;
@@ -43,7 +44,7 @@
import org.dive4elements.river.backend.utils.EpsilonComparator;
import org.dive4elements.river.backend.utils.DateUtil;
-public abstract class BedHeightParser {
+public class BedHeightParser {
private static final Logger log =
Logger.getLogger(BedHeightParser.class);
@@ -92,13 +93,10 @@
protected List<ImportBedHeightSingle> bedHeights;
- protected abstract ImportBedHeightSingle newImportBedHeight(String description);
+ protected ImportBedHeightSingle newImportBedHeight(String description) {
+ return new ImportBedHeightSingle(description);
+ }
- /** Handle a line of file that contains data (in contrast to comments, meta). */
- protected abstract void handleDataLine(
- ImportBedHeightSingle importBedHeight,
- String line
- );
protected TreeSet<Double> kmExists;
@@ -414,5 +412,94 @@
return false;
}
+
+ protected void handleDataLine(ImportBedHeightSingle obj, String line) {
+ String[] values = line.split(SEPERATOR_CHAR, -1);
+
+ if (values == null) {
+ log.warn("BSP: Error while parsing data line: '" + line + "'");
+ return;
+ }
+
+ Double km;
+
+ try {
+ km = new Double(nf.parse(values[0]).doubleValue());
+
+ Double key = Double.valueOf(km);
+
+ if (kmExists.contains(key)) {
+ log.warn("duplicate station '" + km + "': -> ignored");
+ return;
+ }
+
+ kmExists.add(key);
+ }
+ catch (ParseException e) {
+ // We expect a lot of ";;;;;;" lines.
+ return;
+ }
+
+ // Handle gaps like "10,0;;;;;".
+ if (values.length <= 2) {
+ // Do not import line without useful data
+ if (values.length < 2) {
+ return;
+ }
+ if (values[1].length() == 0) {
+ return;
+ }
+ }
+
+ Double height = null;
+ if (values[1].length() > 0) {
+ try {
+ height = new Double(nf.parse(values[1]).doubleValue());
+ }
+ catch (ParseException e) {
+ log.warn("BSP: unparseable height " + values[1]);
+ }
+ }
+
+ Double uncertainty = null;
+ if (values[2].length() > 0) {
+ try {
+ uncertainty = new Double(nf.parse(values[2]).doubleValue());
+ }
+ catch (ParseException e) {
+ log.warn("BSP: unparseable uncertainty value " + values[2]);
+ }
+ }
+
+ Double dataGap = null;
+ if (values[3].length() > 0) {
+ try {
+ dataGap = new Double(nf.parse(values[3]).doubleValue());
+ }
+ catch (ParseException e) {
+ log.warn("BSP: unparseable data gap " + values[3]);
+ }
+ }
+
+ Double soundingWidth = null;
+ if (values[4].length() > 0) {
+ try {
+ soundingWidth = new Double(nf.parse(values[4]).doubleValue());
+ }
+ catch (ParseException e) {
+ log.warn("BSP: unparseable sounding width " + values[4]);
+ }
+ }
+
+ ImportBedHeightSingleValue value = new ImportBedHeightSingleValue(
+ (ImportBedHeightSingle) obj,
+ km,
+ height,
+ uncertainty,
+ dataGap,
+ soundingWidth);
+
+ obj.addValue(value);
+ }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
diff -r d115d0ed6624 -r 29ab66ce06aa backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java Mon Feb 16 09:35:06 2015 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
- * Software engineering by Intevation GmbH
- *
- * This file is Free Software under the GNU AGPL (>=v3)
- * and comes with ABSOLUTELY NO WARRANTY! Check out the
- * documentation coming with Dive4Elements River for details.
- */
-
-package org.dive4elements.river.importer.parsers;
-
-import java.text.ParseException;
-
-import org.apache.log4j.Logger;
-
-import org.dive4elements.river.importer.ImportBedHeightSingle;
-import org.dive4elements.river.importer.ImportBedHeightSingleValue;
-
-
-public class BedHeightSingleParser extends BedHeightParser {
-
- private static final Logger log =
- Logger.getLogger(BedHeightSingleParser.class);
-
-
- @Override
- protected ImportBedHeightSingle newImportBedHeight(String description) {
- return new ImportBedHeightSingle(description);
- }
-
-
- /**
- * Create ImportBedHeightSingleValue from a line of csv file, add
- * it to the ImportBedHeight.
- */
- @Override
- protected void handleDataLine(ImportBedHeightSingle obj, String line) {
- String[] values = line.split(SEPERATOR_CHAR, -1);
-
- if (values == null) {
- log.warn("BSP: Error while parsing data line: '" + line + "'");
- return;
- }
-
- Double km;
-
- try {
- km = new Double(nf.parse(values[0]).doubleValue());
-
- Double key = Double.valueOf(km);
-
- if (kmExists.contains(key)) {
- log.warn("duplicate station '" + km + "': -> ignored");
- return;
- }
-
- kmExists.add(key);
- }
- catch (ParseException e) {
- // We expect a lot of ";;;;;;" lines.
- return;
- }
-
- // Handle gaps like "10,0;;;;;".
- if (values.length <= 2) {
- // Do not import line without useful data
- if (values.length < 2) {
- return;
- }
- if (values[1].length() == 0) {
- return;
- }
- }
-
- Double height = null;
- if (values[1].length() > 0) {
- try {
- height = new Double(nf.parse(values[1]).doubleValue());
- }
- catch (ParseException e) {
- log.warn("BSP: unparseable height " + values[1]);
- }
- }
-
- Double uncertainty = null;
- if (values[2].length() > 0) {
- try {
- uncertainty = new Double(nf.parse(values[2]).doubleValue());
- }
- catch (ParseException e) {
- log.warn("BSP: unparseable uncertainty value " + values[2]);
- }
- }
-
- Double dataGap = null;
- if (values[3].length() > 0) {
- try {
- dataGap = new Double(nf.parse(values[3]).doubleValue());
- }
- catch (ParseException e) {
- log.warn("BSP: unparseable data gap " + values[3]);
- }
- }
-
- Double soundingWidth = null;
- if (values[4].length() > 0) {
- try {
- soundingWidth = new Double(nf.parse(values[4]).doubleValue());
- }
- catch (ParseException e) {
- log.warn("BSP: unparseable sounding width " + values[4]);
- }
- }
-
- ImportBedHeightSingleValue value = new ImportBedHeightSingleValue(
- (ImportBedHeightSingle) obj,
- km,
- height,
- uncertainty,
- dataGap,
- soundingWidth);
-
- obj.addValue(value);
- }
-}
-// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
More information about the Dive4Elements-commits
mailing list