changeset 4715:2f7a509f5acf

Implement new CrossSectionParser interface.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 19 Dec 2012 14:59:14 +0100 (2012-12-19)
parents 47c1d656a152
children 6016b9aa827a
files flys-backend/src/main/java/de/intevation/flys/importer/parsers/DA66Parser.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/PRFParser.java
diffstat 2 files changed, 22 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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!
--- 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;

http://dive4elements.wald.intevation.org