comparison 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
comparison
equal deleted inserted replaced
446:c0bec245f608 447:5606ba4139e0
3 import java.io.BufferedWriter; 3 import java.io.BufferedWriter;
4 import java.io.OutputStream; 4 import java.io.OutputStream;
5 import java.io.OutputStreamWriter; 5 import java.io.OutputStreamWriter;
6 import java.io.PrintWriter; 6 import java.io.PrintWriter;
7 7
8 import java.util.ArrayList;
8 import java.util.Collection; 9 import java.util.Collection;
9 import java.util.HashMap; 10 import java.util.HashMap;
11 import java.util.List;
10 import java.util.Locale; 12 import java.util.Locale;
11 import java.util.Map; 13 import java.util.Map;
12 import java.util.TreeMap; 14 import java.util.TreeMap;
13 15
14 import org.apache.log4j.Logger; 16 import org.apache.log4j.Logger;
32 34
33 35
34 /** The lines that need to be included for the export.*/ 36 /** The lines that need to be included for the export.*/
35 protected Map<Double, WstLine> lines; 37 protected Map<Double, WstLine> lines;
36 38
39 /** The column names.*/
40 protected List<String> columnNames;
41
37 /** The locale used to format the values.*/ 42 /** The locale used to format the values.*/
38 protected Locale locale; 43 protected Locale locale;
39 44
40 /** The number of discharge columns.*/ 45 /** The number of discharge columns.*/
41 protected int cols; 46 protected int cols;
51 * 56 *
52 * @param out The output stream where the WST is written to. 57 * @param out The output stream where the WST is written to.
53 * @param cols The number of columns of the resulting WST. 58 * @param cols The number of columns of the resulting WST.
54 */ 59 */
55 public WstWriter(int cols) { 60 public WstWriter(int cols) {
56 this.cols = cols; 61 this.columnNames = new ArrayList<String>(cols);
57 this.qs = new double[cols]; 62 this.lines = new HashMap<Double, WstLine>();
58 this.locale = Locale.US; 63 this.qs = new double[cols];
59 this.lines = new HashMap<Double, WstLine>(); 64 this.locale = Locale.US;
65 this.cols = cols;
60 66
61 } 67 }
62 68
63 69
64 /** 70 /**
103 line.add(wqkms[0], wqkms[1]); 109 line.add(wqkms[0], wqkms[1]);
104 } 110 }
105 111
106 112
107 /** 113 /**
114 * Adds a further column name.
115 *
116 * @param name The name of the new column.
117 */
118 public void addColumn(String name) {
119 if (name != null) {
120 columnNames.add(name);
121 }
122 }
123
124
125 /**
108 * This method writes the header of the WST. 126 * This method writes the header of the WST.
109 * 127 *
110 * @param writer The PrintWriter that creates the output. 128 * @param writer The PrintWriter that creates the output.
111 */ 129 */
112 protected void writeHeader(PrintWriter writer) { 130 protected void writeHeader(PrintWriter writer) {
113 logger.debug("WstWriter.writeHeader"); 131 logger.debug("WstWriter.writeHeader");
114 132
115 writer.println(cols); 133 writer.println(cols);
116 134 writer.print(" ");
117 // TODO WRITE DISCHARGE COLUMNS 135
136 for (String columnName: columnNames) {
137 writer.printf(locale, "%9s", columnName);
138 }
139
140 writer.println();
118 141
119 writer.write("* KM "); 142 writer.write("* KM ");
120 writer.write(DEFAULT_UNIT); 143 writer.write(DEFAULT_UNIT);
121 writer.println(); 144 writer.println();
122 } 145 }

http://dive4elements.wald.intevation.org