[Dive4elements-commits] [PATCH 3 of 4] Implement new CrossSectionParser interface

Wald Commits scm-commit at wald.intevation.org
Wed Dec 19 14:54:21 CET 2012


# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1355925554 -3600
# Node ID 2f7a509f5acff725e918041d17d50d05dc3d75f3
# Parent  47c1d656a1520fd9ad7b524c1df6699e65ee0ab3
Implement new CrossSectionParser interface.

diff -r 47c1d656a152 -r 2f7a509f5acf flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA66Parser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA66Parser.java	Wed Dec 19 14:58:34 2012 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA66Parser.java	Wed Dec 19 14:59:14 2012 +0100
@@ -23,7 +23,7 @@
  * To create cross-sections, generate: Map<double,list<xy>> from files
  * in da66 format.
  */
-public class DA66Parser extends LineParser
+public class DA66Parser extends LineParser implements CrossSectionParser
 {
     /** Private logger. */
     private static Logger logger = Logger.getLogger(DA66Parser.class);
@@ -160,13 +160,6 @@
     private List<XY> currentLine;
 
 
-    // TODO refactor, its shared with PRFParser.
-    public interface Callback {
-        boolean da66Accept(File file);
-        void    da66Parsed(DA66Parser parser);
-    } // interface Parser
-
-
     /** Data collected so far, last element will be currentLine. */
     protected Map<Double, List<XY>> data;
 
@@ -175,6 +168,17 @@
         data = new TreeMap<Double, List<XY>>();
     }
 
+    @Override
+    public String getDescription() {
+        return "da66-dummy";
+    }
+
+    @Override
+    public Integer getYear() {
+        return 2012;
+    }
+
+    @Override
     public Map<Double, List<XY>> getData() {
         return data;
     }
@@ -198,13 +202,13 @@
             public boolean visit(File file) {
                 if (file.isFile() && file.canRead()
                 && file.getName().toLowerCase().endsWith(".d66")
-                && (callback == null || callback.da66Accept(file))) {
+                && (callback == null || callback.accept(file))) {
                     reset();
                     try {
                         parse(file);
                         logger.info("parsing done");
                         if (callback != null) {
-                            callback.da66Parsed(DA66Parser.this);
+                            callback.parsed(DA66Parser.this);
                         }
                     }
                     catch (IOException ioe) {
@@ -284,7 +288,7 @@
     protected void handleLine(int lineNum, String line) {
         String head = line.substring(0,2);
         if (HEAD_HEAD.equals(head)) {
-                logger.debug("Hit a 00");
+                //logger.debug("New station");
                 Matcher m = LINE_PATTERN.matcher(line);
                 if (m.find()) {
                     // Actually matches!
diff -r 47c1d656a152 -r 2f7a509f5acf flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java	Wed Dec 19 14:58:34 2012 +0100
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java	Wed Dec 19 14:59:14 2012 +0100
@@ -26,7 +26,7 @@
  * Parse files in .prf format and generate a mapping of double
  * (km) to List of Points (XY).
  */
-public class PRFParser
+public class PRFParser implements CrossSectionParser
 {
     private static Logger log = Logger.getLogger(PRFParser.class);
 
@@ -47,11 +47,6 @@
     public static final int MIN_YEAR = 1800;
     public static final int MAX_YEAR = 2100;
 
-    public interface Callback {
-        boolean prfAccept(File file);
-        void    prfParsed(PRFParser parser);
-    } // interface Parser
-
     public static class DataFormat {
 
         protected int deleteChars;
@@ -188,6 +183,7 @@
         data = new TreeMap<Double, List<XY>>();
     }
 
+    @Override
     public Integer getYear() {
         return year;
     }
@@ -196,6 +192,7 @@
         this.year = year;
     }
 
+    @Override
     public String getDescription() {
         return description;
     }
@@ -204,6 +201,7 @@
         this.description = description;
     }
 
+    @Override
     public Map<Double, List<XY>> getData() {
         return data;
     }
@@ -396,19 +394,19 @@
         description = null;
     }
 
-    public void parsePRFs(File root, final Callback callback) {
+    public void parsePRFs(File root, final CrossSectionParser.Callback callback) {
 
         FileTools.walkTree(root, new FileTools.FileVisitor() {
             @Override
             public boolean visit(File file) {
                 if (file.isFile() && file.canRead()
                 && file.getName().toLowerCase().endsWith(".prf")
-                && (callback == null || callback.prfAccept(file))) {
+                && (callback == null || callback.accept(file))) {
                     reset();
                     boolean success = parse(file);
                     log.info("parsing " + (success ? "succeeded" : "failed"));
                     if (success && callback != null) {
-                        callback.prfParsed(PRFParser.this);
+                        callback.parsed(PRFParser.this);
                     }
                 }
                 return true;


More information about the Dive4elements-commits mailing list