changeset 6273:e7526a074c0d double-precision

Bed height parser: check for duplicate stations
author Tom Gottfried <tom.gottfried@intevation.de>
date Tue, 11 Jun 2013 13:03:50 +0200
parents e8f152163a1e
children 3d8f9e3bbf2e
files backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java
diffstat 2 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java	Tue Jun 11 09:40:56 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java	Tue Jun 11 13:03:50 2013 +0200
@@ -19,6 +19,7 @@
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import java.util.TreeSet;
 import java.util.Locale;
 
 import java.util.regex.Matcher;
@@ -40,6 +41,7 @@
 import org.dive4elements.river.importer.ImportUnit;
 import org.dive4elements.river.model.BedHeightType;
 import org.dive4elements.river.importer.ImporterSession;
+import org.dive4elements.river.utils.EpsilonComparator;
 
 public abstract class BedHeightParser {
 
@@ -98,10 +100,12 @@
         String          line
     );
 
+    protected TreeSet<Double> kmExists;
 
 
     public BedHeightParser() {
-        this.bedHeights = new ArrayList<ImportBedHeight>();
+        bedHeights = new ArrayList<ImportBedHeight>();
+        kmExists = new TreeSet<Double>(EpsilonComparator.CMP);
     }
 
 
@@ -115,6 +119,8 @@
 
         ImportBedHeight obj = newImportBedHeight(file.getName().replaceAll("\\.csv", ""));
 
+        kmExists.clear();
+
         LineNumberReader in = null;
         try {
             in =
--- a/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java	Tue Jun 11 09:40:56 2013 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java	Tue Jun 11 13:03:50 2013 +0200
@@ -50,7 +50,17 @@
 
         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.
             //log.warn("BSP: Error while parsing km of data row.", e);

http://dive4elements.wald.intevation.org