[PATCH] (issue1763) Fix filtering of lines when parsing bed heights
Wald Commits
scm-commit at wald.intevation.org
Fri Apr 10 17:47:12 CEST 2015
# HG changeset patch
# User Tom Gottfried <tom at intevation.de>
# Date 1428680820 -7200
# Node ID 1f878c82262f249d1400b2d1f14e88db023c652f
# Parent 19c38a47a27625d2814573bc03910c9304bdf2d8
(issue1763) Fix filtering of lines when parsing bed heights.
diff -r 19c38a47a276 -r 1f878c82262f backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java Fri Apr 10 17:42:10 2015 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java Fri Apr 10 17:47:00 2015 +0200
@@ -384,55 +384,40 @@
}
protected void handleDataLine(ImportBedHeight obj, String line) {
- String[] values = line.split(SEPERATOR_CHAR, -1);
+ String[] values = line.split(SEPERATOR_CHAR, 0);
- if (values == null) {
- log.warn("BSP: Error while parsing data line: '" + line + "'");
+ if (values.length < 2) {
+ // Do not import line without data or only km
return;
}
Double km;
-
try {
km = new Double(nf.parse(values[0]).doubleValue());
- Double key = Double.valueOf(km);
-
- if (kmExists.contains(key)) {
+ if (kmExists.contains(km)) {
log.warn("duplicate station '" + km + "': -> ignored");
return;
}
- kmExists.add(key);
+ kmExists.add(km);
}
catch (ParseException e) {
- // We expect a lot of ";;;;;;" lines.
+ log.error("Error parsing km '" + values[0] + "': " +
+ e.getMessage());
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;
+ try {
+ height = new Double(nf.parse(values[1]).doubleValue());
}
-
- 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]);
- }
+ catch (ParseException e) {
+ log.warn("BSP: unparseable height " + values[1]);
}
Double uncertainty = null;
- if (values[2].length() > 0) {
+ if (values.length > 2) {
try {
uncertainty = new Double(nf.parse(values[2]).doubleValue());
}
@@ -442,7 +427,7 @@
}
Double dataGap = null;
- if (values[3].length() > 0) {
+ if (values.length > 3) {
try {
dataGap = new Double(nf.parse(values[3]).doubleValue());
}
@@ -452,7 +437,7 @@
}
Double soundingWidth = null;
- if (values[4].length() > 0) {
+ if (values.length > 4) {
try {
soundingWidth = new Double(nf.parse(values[4]).doubleValue());
}
More information about the Dive4Elements-commits
mailing list