[Dive4elements-commits] [PATCH] Bed height parser: check for duplicate stations

Wald Commits scm-commit at wald.intevation.org
Tue Jun 11 13:03:53 CEST 2013


# HG changeset patch
# User Tom Gottfried <tom.gottfried at intevation.de>
# Date 1370948630 -7200
# Branch double-precision
# Node ID e7526a074c0d5c692186c30444826e3d34730645
# Parent  e8f152163a1e2269aa61a505d8e7701073077ffd
Bed height parser: check for duplicate stations

diff -r e8f152163a1e -r e7526a074c0d backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightParser.java
--- 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 =
diff -r e8f152163a1e -r e7526a074c0d backend/src/main/java/org/dive4elements/river/importer/parsers/BedHeightSingleParser.java
--- 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);


More information about the Dive4elements-commits mailing list