[PATCH] (issue1754) Unify PDF and CSV export and invert presentation if start > end
Wald Commits
scm-commit at wald.intevation.org
Thu Mar 26 18:25:41 CET 2015
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1427390478 -3600
# Node ID 8bff94ea044f445635eb75d3e373b746e8952c47
# Parent 5533aa8f8b73ccb08cf8eb45990fc87ace8eea95
(issue1754) Unify PDF and CSV export and invert presentation if start > end
diff -r 5533aa8f8b73 -r 8bff94ea044f artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesExporter.java
--- 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 :
More information about the Dive4Elements-commits
mailing list