changeset 8681:1f878c82262f

(issue1763) Fix filtering of lines when parsing bed heights.
author Tom Gottfried <tom@intevation.de>
date Fri, 10 Apr 2015 17:47:00 +0200
parents 19c38a47a276
children 5102733c4567
files backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java
diffstat 1 files changed, 15 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- 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());
             }

http://dive4elements.wald.intevation.org