diff flys-artifacts/src/main/java/de/intevation/flys/exports/WstWriter.java @ 447:5606ba4139e0

WSTs will now have a header that contains the names of the Ws or Qs that had been defined for the computation. flys-artifacts/trunk@1939 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 18 May 2011 08:04:54 +0000
parents c0bec245f608
children 72bcbc308501
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WstWriter.java	Tue May 17 16:31:07 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WstWriter.java	Wed May 18 08:04:54 2011 +0000
@@ -5,8 +5,10 @@
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.TreeMap;
@@ -34,6 +36,9 @@
     /** The lines that need to be included for the export.*/
     protected Map<Double, WstLine> lines;
 
+    /** The column names.*/
+    protected List<String> columnNames;
+
     /** The locale used to format the values.*/
     protected Locale locale;
 
@@ -53,10 +58,11 @@
      * @param cols The number of columns of the resulting WST.
      */
     public WstWriter(int cols) {
-        this.cols   = cols;
-        this.qs     = new double[cols];
-        this.locale = Locale.US;
-        this.lines  = new HashMap<Double, WstLine>();
+        this.columnNames = new ArrayList<String>(cols);
+        this.lines       = new HashMap<Double, WstLine>();
+        this.qs          = new double[cols];
+        this.locale      = Locale.US;
+        this.cols        = cols;
 
     }
 
@@ -105,6 +111,18 @@
 
 
     /**
+     * Adds a further column name.
+     *
+     * @param name The name of the new column.
+     */
+    public void addColumn(String name) {
+        if (name != null) {
+            columnNames.add(name);
+        }
+    }
+
+
+    /**
      * This method writes the header of the WST.
      *
      * @param writer The PrintWriter that creates the output.
@@ -113,8 +131,13 @@
         logger.debug("WstWriter.writeHeader");
 
         writer.println(cols);
+        writer.print("        ");
 
-        // TODO WRITE DISCHARGE COLUMNS
+        for (String columnName: columnNames) {
+            writer.printf(locale, "%9s", columnName);
+        }
+
+        writer.println();
 
         writer.write("*   KM     ");
         writer.write(DEFAULT_UNIT);

http://dive4elements.wald.intevation.org