[Dive4elements-commits] [PATCH 02 of 10] ImportRiver: Use callback (refactoring), resolving TODOs

Wald Commits scm-commit at wald.intevation.org
Tue Jan 8 16:53:56 CET 2013


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1357642741 -3600
# Node ID 18908a3cbb3a6b2ca6386f591ffba14d936a3354
# Parent  a70de52982481262bce0ef0a0dd288daa217a5f9
ImportRiver: Use callback (refactoring), resolving TODOs.

diff -r a70de5298248 -r 18908a3cbb3a flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Tue Jan 08 11:57:03 2013 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportRiver.java	Tue Jan 08 11:59:01 2013 +0100
@@ -961,28 +961,9 @@
             .getParentFile()  // Hydrologie
             .getParentFile(); // <river>
 
-        // TODO this can probably be further merged with implementation for PRF parser.
-        parser.parseW80s(riverDir, new CrossSectionParser.Callback() {
-
-            Set<HashedFile> w80s = new HashSet<HashedFile>();
-
-            @Override
-            public boolean accept(File file) {
-                HashedFile hf = new HashedFile(file);
-                boolean success = w80s.add(hf);
-                if (!success) {
-                    log.warn("W80 file '" + file + "' seems to be a duplicate.");
-                }
-                return success;
-            }
-
-            @Override
-            public void parsed(CrossSectionParser parser) {
-                log.debug("callback from W80 parser");
-
-                addCrossSections(parser);
-            }
-        });
+        ImportRiverCrossSectionParserCallback w80Callback =
+            new ImportRiverCrossSectionParserCallback("w80");
+        parser.parseW80s(riverDir, w80Callback);
     }
 
     public void parseDA50s() {
@@ -1008,28 +989,9 @@
             .getParentFile()  // Hydrologie
             .getParentFile(); // <river>
 
-        // TODO this can probably be further merged with implementation for PRF parser.
-        parser.parseDA66s(riverDir, new CrossSectionParser.Callback() {
-
-            Set<HashedFile> da66s = new HashSet<HashedFile>();
-
-            @Override
-            public boolean accept(File file) {
-                HashedFile hf = new HashedFile(file);
-                boolean success = da66s.add(hf);
-                if (!success) {
-                    log.warn("DA66 file '" + file + "' seems to be a duplicate.");
-                }
-                return success;
-            }
-
-            @Override
-            public void parsed(CrossSectionParser parser) {
-                log.debug("callback from DA66 parser");
-
-                addCrossSections(parser);
-            }
-        });
+        ImportRiverCrossSectionParserCallback da66Callback =
+            new ImportRiverCrossSectionParserCallback("da66");
+        parser.parseDA66s(riverDir, da66Callback);
     }
 
     /** Create a PRFParser and let it parse the prf files found. */
@@ -1046,28 +1008,9 @@
             .getParentFile()  // Hydrologie
             .getParentFile(); // <river>
 
-        parser.parsePRFs(riverDir, new PRFParser.Callback() {
-
-            Set<HashedFile> prfs = new HashSet<HashedFile>();
-
-            // TODO merge Callback implementation with DA66 one.
-            @Override
-            public boolean accept(File file) {
-                HashedFile hf = new HashedFile(file);
-                boolean success = prfs.add(hf);
-                if (!success) {
-                    log.warn("PRF file '" + file + "' seems to be a duplicate.");
-                }
-                return success;
-            }
-
-            @Override
-            public void parsed(CrossSectionParser parser) {
-                log.debug("callback from PRF parser");
-
-                addCrossSections(parser);
-            }
-        });
+        ImportRiverCrossSectionParserCallback prfCallback =
+            new ImportRiverCrossSectionParserCallback("prf");
+        parser.parsePRFs(riverDir, prfCallback);
     }
 
     public static Date yearToDate(int year) {


More information about the Dive4elements-commits mailing list