Mercurial > dive4elements > river
changeset 8633:8bff94ea044f
(issue1754) Unify PDF and CSV export and invert presentation if start > end
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Thu, 26 Mar 2015 18:21:18 +0100 |
parents | 5533aa8f8b73 |
children | 57e0bfda1c76 |
files | artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesExporter.java |
diffstat | 1 files changed, 38 insertions(+), 41 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesExporter.java Thu Mar 26 17:33:55 2015 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesExporter.java Thu Mar 26 18:21:18 2015 +0100 @@ -32,6 +32,7 @@ import org.dive4elements.artifacts.common.utils.Config; import org.dive4elements.river.artifacts.WINFOArtifact; +import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.access.RangeAccess; import org.dive4elements.river.artifacts.model.CalculationResult; @@ -66,6 +67,8 @@ /** The storage that contains all WKms objects for the different facets. */ protected List<WKms[]> data; + protected List<String[]> stringData; + public WDifferencesExporter() { data = new ArrayList<WKms[]>(); } @@ -78,7 +81,11 @@ throws IOException { log.debug("WDifferencesExporter.generate"); - + if (stringData == null) { + D4EArtifact arti = (D4EArtifact) master; + RangeAccess access = new RangeAccess(arti); + stringData = data2StringArrays(access.getFrom() > access.getTo()); + } if (facet == null) { throw new IOException("invalid (null) facet for exporter"); } @@ -122,11 +129,7 @@ writeCSVHeader(writer); - for (WKms[] tmp: data) { - for (WKms wkms: tmp) { - wKms2CSV(writer, wkms); - } - } + writer.writeAll(stringData); } @@ -144,23 +147,6 @@ } - protected void wKms2CSV(CSVWriter writer, WKms wkms) { - log.debug("WDifferencesExporter.wKms2CSV"); - - NumberFormat kmf = getKmFormatter(); - NumberFormat wf = getWFormatter(); - int size = wkms.size(); - - for (int i = 0; i < size; i ++) { - - writer.writeNext(new String[] { - kmf.format(wkms.getKm(i)), - wf.format(wkms.getW(i)) - }); - } - } - - /** * Returns the number formatter for kilometer values. * @@ -180,6 +166,33 @@ return Formatter.getWaterlevelW(context); } + protected List<String[]> data2StringArrays(boolean inverted) { + NumberFormat kmf = getKmFormatter(); + NumberFormat wf = getWFormatter(); + List<String[]> retval = new ArrayList<String[]>(); + + for (WKms[] tmp: data) { + for (WKms wkms: tmp) { + int size = wkms.size(); + if (inverted) { + for (int i = size - 1; i >= 0; i--) { + retval.add(new String[] { + kmf.format(wkms.getKm(i)), + wf.format(wkms.getW(i)) + }); + } + } else { + for (int i = 0; i < size; i++) { + retval.add(new String[] { + kmf.format(wkms.getKm(i)), + wf.format(wkms.getW(i)) + }); + } + } + } + } + return retval; + } @Override protected void writePDF(OutputStream out) { @@ -210,10 +223,8 @@ WKmsJRDataSource source = new WKmsJRDataSource(); addMetaData(source); - for (WKms[] tmp: data) { - for (WKms wkms: tmp) { - addWKmsData(source, wkms); - } + for (String[] str: stringData) { + source.addData(str); } return source; } @@ -246,19 +257,5 @@ "W Differences")); } - protected void addWKmsData(WKmsJRDataSource source, WKms wkms) { - NumberFormat kmf = getKmFormatter(); - NumberFormat wf = getWFormatter(); - int size = wkms.size(); - - for (int i = 0; i < size; i ++) { - - source.addData(new String[] { - kmf.format(wkms.getKm(i)), - wf.format(wkms.getW(i)) - }); - } - } - } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :