Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveExporter.java @ 2046:2ae0627f956e
Improved ChartSettings and depending classes to avoid a lot of casting.
flys-artifacts/trunk@3534 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 23 Dec 2011 08:51:28 +0000 |
parents | 9665d6a48f7b |
children | 65dac9cf6ff5 |
line wrap: on
line source
package de.intevation.flys.exports; import java.io.OutputStream; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.w3c.dom.Document; import org.apache.log4j.Logger; import au.com.bytecode.opencsv.CSVWriter; import de.intevation.artifacts.CallContext; import de.intevation.flys.artifacts.model.CalculationResult; import de.intevation.flys.artifacts.model.WQKms; import de.intevation.flys.utils.Formatter; /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class ComputedDischargeCurveExporter extends AbstractExporter { /** The logger used in this exporter.*/ private static Logger logger = Logger.getLogger(ComputedDischargeCurveExporter.class); public static final String CSV_W_HEADER = "export.computed.discharge.curve.csv.header.w"; public static final String CSV_Q_HEADER = "export.computed.discharge.curve.csv.header.q"; public static final String DEFAULT_CSV_W_HEADER = "W [NN + m]"; public static final String DEFAULT_CSV_Q_HEADER = "Q [m\u00b3/s]"; protected List<WQKms> data; public void init(Document request, OutputStream out, CallContext context) { logger.debug("ComputedDischargeCurveExporter.init"); super.init(request, out, context); this.data = new ArrayList<WQKms>(); } @Override protected void addData(Object d) { if (d instanceof CalculationResult) { d = ((CalculationResult)d).getData(); if (d instanceof WQKms []) { data.addAll(Arrays.asList((WQKms [])d)); } } } protected void writeCSVData(CSVWriter writer) { logger.info("ComputedDischargeCurveExporter.writeData"); writeCSVHeader(writer); NumberFormat wf = getWFormatter(); NumberFormat qf = getQFormatter(); double[] res = new double[3]; for (WQKms wqkms: data) { int size = wqkms.size(); for (int i = 0; i < size; i++) { res = wqkms.get(i, res); writer.writeNext(new String[] { wf.format(res[0]), qf.format(res[1]) }); } } } protected void writeCSVHeader(CSVWriter writer) { logger.debug("ComputedDischargeCurveExporter.writeCSVHeader"); writer.writeNext(new String[] { msg(CSV_W_HEADER, DEFAULT_CSV_W_HEADER), msg(CSV_Q_HEADER, DEFAULT_CSV_Q_HEADER) }); } /** * Returns the number formatter for W values. * * @return the number formatter for W values. */ protected NumberFormat getWFormatter() { return Formatter.getComputedDischargeW(context); } /** * Returns the number formatter for Q values. * * @return the number formatter for Q values. */ protected NumberFormat getQFormatter() { return Formatter.getComputedDischargeQ(context); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :