changeset 1219:d80997bd94ce

HYKParser: Create data structures while parsing. flys-backend/trunk@2345 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 17 Jul 2011 22:30:09 +0000
parents 00e37d22a589
children 3c860d3e79d9
files flys-backend/ChangeLog flys-backend/src/main/java/de/intevation/flys/importer/ImportHYK.java flys-backend/src/main/java/de/intevation/flys/importer/ImportHYKFormation.java flys-backend/src/main/java/de/intevation/flys/importer/parsers/HYKParser.java
diffstat 4 files changed, 89 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/flys-backend/ChangeLog	Sun Jul 17 19:03:33 2011 +0000
+++ b/flys-backend/ChangeLog	Sun Jul 17 22:30:09 2011 +0000
@@ -1,3 +1,12 @@
+2011-07-18	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
+
+	* src/main/java/de/intevation/flys/importer/parsers/HYKParser.java:
+	  Create data structures while parsing.
+
+	* src/main/java/de/intevation/flys/importer/ImportHYKFormation.java,
+	  src/main/java/de/intevation/flys/importer/ImportHYK.java: Added
+	  getters/setters to ease model wiring.
+
 2011-07-17	Sascha L. Teichmann	<sascha.teichmann@intevation.de>
 
 	* src/main/java/de/intevation/flys/importer/ImportHYKFormation.java,
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportHYK.java	Sun Jul 17 19:03:33 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportHYK.java	Sun Jul 17 22:30:09 2011 +0000
@@ -28,6 +28,14 @@
         this.description = description;
     }
 
+    public ImportRiver getRiver() {
+        return river;
+    }
+
+    public void setRiver(ImportRiver river) {
+        this.river = river;
+    }
+
     public void addEntry(ImportHYKEntry entry) {
         entries.add(entry);
         entry.setHYK(this);
--- a/flys-backend/src/main/java/de/intevation/flys/importer/ImportHYKFormation.java	Sun Jul 17 19:03:33 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/ImportHYKFormation.java	Sun Jul 17 22:30:09 2011 +0000
@@ -69,6 +69,30 @@
         this.entry = entry;
     }
 
+    public BigDecimal getDistanceVL() {
+        return distanceVL;
+    }
+
+    public void setDistanceVL(BigDecimal distanceVL) {
+        this.distanceVL = distanceVL;
+    }
+
+    public BigDecimal getDistanceHF() {
+        return distanceHF;
+    }
+
+    public void setDistanceHF(BigDecimal distanceHF) {
+        this.distanceHF = distanceHF;
+    }
+
+    public BigDecimal getDistanceVR() {
+        return distanceVR;
+    }
+
+    public void setDistanceVR(BigDecimal distanceVR) {
+        this.distanceVR = distanceVR;
+    }
+
     public HYKFormation getPeer() {
         if (peer == null) {
             HYKEntry e = entry.getPeer();
--- a/flys-backend/src/main/java/de/intevation/flys/importer/parsers/HYKParser.java	Sun Jul 17 19:03:33 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/parsers/HYKParser.java	Sun Jul 17 22:30:09 2011 +0000
@@ -1,5 +1,9 @@
 package de.intevation.flys.importer.parsers;
 
+import de.intevation.flys.importer.ImportHYK;
+import de.intevation.flys.importer.ImportHYKEntry;
+import de.intevation.flys.importer.ImportHYKFormation;
+import de.intevation.flys.importer.ImportHYKFlowZone;
 import de.intevation.flys.importer.ImportHYKFlowZoneType;
 
 import java.io.File;
@@ -10,6 +14,8 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Date;
+import java.util.Calendar;
 
 import java.math.BigDecimal;
 
@@ -34,10 +40,27 @@
 
     protected Map<String, ImportHYKFlowZoneType> flowZoneTypes;
 
+    protected ImportHYK hyk;
+
     public HYKParser() {
         flowZoneTypes = new HashMap<String, ImportHYKFlowZoneType>();
     }
 
+    public ImportHYK getHYK() {
+        return hyk;
+    }
+
+    private static Date yearToDate(Integer year) {
+        if (year == null) {
+            return null;
+        }
+        Calendar cal = Calendar.getInstance();
+        cal.set(year, 0, 1, 12, 0, 0);
+        long ms = cal.getTimeInMillis();
+        cal.setTimeInMillis(ms - ms%1000);
+        return cal.getTime();
+    }
+
     public boolean parse(File file) {
 
         boolean debug = log.isDebugEnabled();
@@ -46,6 +69,11 @@
 
         LineNumberReader in = null;
 
+        String description =
+            file.getParentFile().getName() + "/" + file.getName();
+
+        hyk = new ImportHYK(null, description);
+
         try {
             in =
                 new LineNumberReader(
@@ -72,6 +100,9 @@
             BigDecimal            [] coords   = null;
             int                      coordPos = 0;
 
+            ImportHYKEntry     entry     = null;
+            ImportHYKFormation formation = null;
+
             while ((line = in.readLine()) != null) {
 
                 if (line.startsWith("*") || line.startsWith("----")) {
@@ -124,7 +155,8 @@
                                 "or km failed in line " + in.getLineNumber());
                             return false;
                         }
-                        // TODO: Store HYKEntry
+                        entry = new ImportHYKEntry(hyk, km, yearToDate(year));
+                        hyk.addEntry(entry);
 
                         state = State.LINE_2;
                         break;
@@ -146,6 +178,9 @@
                                 "failed in line " + in.getLineNumber());
                             return false;
                         }
+                        formation = new ImportHYKFormation();
+                        formation.setEntry(entry);
+
                         state = State.LINE_3;
                         break;
 
@@ -200,6 +235,14 @@
                                 in.getLineNumber());
                             return false;
                         }
+                        for (int i = 0; i < coords.length; ++i) {
+                            ImportHYKFlowZone zone = new ImportHYKFlowZone(
+                                formation,
+                                fzts[i],
+                                coords[i],
+                                coords[i == coords.length-1 ? i : i+1]);
+                            formation.addFlowZone(zone);
+                        }
                         state = State.LINE_6;
                         break;
 
@@ -219,8 +262,9 @@
                                 in.getLineNumber());
                             return false;
                         }
-                        // TODO: now we have enough information 
-                        //       to store a formation.
+                        formation.setDistanceVL(distanceVL);
+                        formation.setDistanceHF(distanceHF);
+                        formation.setDistanceVR(distanceVR);
 
                         // continue with next formation.
                         state = --numFormations > 0 // formations left?
@@ -259,7 +303,7 @@
     }
 
     protected void reset() {
-        // TODO: reset per file data structures
+        hyk = null;
     }
 
     public void parseHYKs(File root, final Callback callback) {

http://dive4elements.wald.intevation.org