diff backend/src/main/java/org/dive4elements/river/importer/common/AbstractParser.java @ 9012:abe069eb180c

Import of vegetation zones added
author mschaefer
date Wed, 18 Apr 2018 07:43:55 +0200
parents c43d8c1a4455
children 4c5eeaff554c
line wrap: on
line diff
--- a/backend/src/main/java/org/dive4elements/river/importer/common/AbstractParser.java	Wed Apr 18 07:43:04 2018 +0200
+++ b/backend/src/main/java/org/dive4elements/river/importer/common/AbstractParser.java	Wed Apr 18 07:43:55 2018 +0200
@@ -82,6 +82,13 @@
     }
 
     /**
+     * How the km column and its content are expected
+     */
+    protected enum KmMode {
+        NONE, UNIQUE, DUPLICATES
+    }
+
+    /**
      * Path of the file or directory to import from
      */
     protected final File importPath;
@@ -382,25 +389,30 @@
         return false;
     }
 
-    private void handleDataLine() {
+    /**
+     * Parses a values line and adds the values record
+     */
+    protected void handleDataLine() {
         final String[] values = this.currentLine.split(SEPARATOR_CHAR, 0);
         // Skip import line without data or only km
         if (values.length < 2)
             return;
-        Double km;
-        try {
-            km = Double.valueOf(parseDouble(values[0]).doubleValue());
-            if (kmMustBeUnique()) {
-                if (this.kmExists.contains(km)) {
-                    logWarning("Ignoring duplicate station '" + values[0] + "' in line " + this.in.getLineNumber());
-                    return;
+        Double km = Double.NaN;
+        if (kmMode() != KmMode.NONE) {
+            try {
+                km = Double.valueOf(parseDouble(values[0]).doubleValue());
+                if (kmMode() == KmMode.UNIQUE) {
+                    if (this.kmExists.contains(km)) {
+                        logWarning("Ignoring duplicate station '" + values[0] + "' in line " + this.in.getLineNumber());
+                        return;
+                    }
+                    this.kmExists.add(km);
                 }
-                this.kmExists.add(km);
             }
-        }
-        catch (final Exception e) {
-            logError("Not parseable km in line " + this.in.getLineNumber() + ": " + e.getMessage());
-            return;
+            catch (final Exception e) {
+                logError("Not parseable km in line " + this.in.getLineNumber() + ": " + e.getMessage());
+                return;
+            }
         }
         final KMLINE value = createKmLineImport(km, values);
         if (value != null)
@@ -408,10 +420,10 @@
     }
 
     /**
-     * Whether {@link handleDataLine} shall check for and reject km duplicates
+     * How {@link handleDataLine} shall handle the km column (if any)
      */
-    protected boolean kmMustBeUnique() {
-        return true;
+    protected KmMode kmMode() {
+        return KmMode.UNIQUE;
     }
 
     /**

http://dive4elements.wald.intevation.org