diff flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java @ 201:3169b559ca3c

Build models for wsts, wst columns and q ranges and store them in the backend. flys-backend/trunk@1549 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 23 Mar 2011 15:22:32 +0000
parents 88048d4f6e4d
children 29a408f80a89
line wrap: on
line diff
--- a/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java	Wed Mar 23 10:46:58 2011 +0000
+++ b/flys-backend/src/main/java/de/intevation/flys/importer/WstParser.java	Wed Mar 23 15:22:32 2011 +0000
@@ -19,6 +19,8 @@
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
 
+import java.math.BigDecimal;
+
 public class WstParser
 {
     private static Logger log = Logger.getLogger(WstParser.class);
@@ -38,13 +40,25 @@
     public static final Pattern UNIT =
         Pattern.compile("[^\\[]*\\[([^]]+)\\].*");
 
+    protected ImportWst wst;
+
     public WstParser() {
     }
 
+    public ImportWst getWst() {
+        return wst;
+    }
+
+    public void setWst(ImportWst wst) {
+        this.wst = wst;
+    }
+
     public void parse(File file) throws IOException {
 
         log.info("Parsing WST file '" + file + "'");
 
+        wst = new ImportWst(file.getName());
+
         LineNumberReader in = null;
         try {
             in =
@@ -68,7 +82,6 @@
             double minKm =  Double.MAX_VALUE;
             double maxKm = -Double.MAX_VALUE;
 
-            boolean bFirstComment = true;
             boolean columnHeaderChecked = false;
 
             double lastKm = Double.MAX_VALUE;
@@ -280,11 +293,16 @@
         // TODO: store me!
     }
 
-    protected static String format(double value) {
+    private static final NumberFormat NF = getNumberFormat();
+
+    private static getNumberFormat() {
         NumberFormat nf = NumberFormat.getInstance();
         nf.setMinimumFractionDigits(2);
         nf.setMaximumFractionDigits(2);
-        return nf.format(value);
+    }
+
+    protected static String format(double value) {
+        return NF.format(value);
     }
 
     protected void addInterval(
@@ -292,21 +310,25 @@
         double              to, 
         Map<String, Double> values
     ) {
+        log.debug("addInterval: " + from + " " + to);
+
         if (values == null) {
             return;
         }
-        if (log.isDebugEnabled()) {
-            log.debug("addInterval: " + from + " " + to);
-            StringBuilder sb = new StringBuilder();
-            for (Map.Entry<String, Double> entry: values.entrySet()) {
-                if (sb.length() > 0) {
-                    sb.append("; ");
-                }
-                sb.append('"').append(entry.getKey())
-                  .append("\": ")
-                  .append(entry.getValue());
-            }
-            log.debug("entries: " + sb.toString());
+
+        if (from > to) { double t = from; from = to; to = t; }
+
+        ImportRange range = new ImportRange(
+            new BigDecimal(from),
+            new BigDecimal(to));
+
+        for (Map.Entry<String, Double> entry: values.entrySet()) {
+            BigDecimal q = new BigDecimal(entry.getValue());
+            ImportWstQRange wstQRange = new ImportWstQRange(range, q);
+
+            String columnName = entry.getKey();
+            ImportWstColumn column = wst.getColumn(columnName);
+            column.addColumnQRange(wstQRange);
         }
     }
 

http://dive4elements.wald.intevation.org