Mercurial > dive4elements > river
changeset 8643:999b9ab16738
(issue1754) Handle inverted presentation in BedDifference exporter
This als removes dead (would have triggered an exception in pdf export)
code to handle beddiff results which are not "BedDiffYearResults"
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Fri, 27 Mar 2015 18:59:27 +0100 |
parents | 9db1f48bfea9 |
children | c15cebcf60da |
files | artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java |
diffstat | 1 files changed, 50 insertions(+), 68 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java Fri Mar 27 18:54:03 2015 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java Fri Mar 27 18:59:27 2015 +0100 @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.Date; +import java.util.Collections; import java.text.DateFormat; import org.apache.log4j.Logger; @@ -87,57 +88,57 @@ results = new BedDifferencesResult[0]; } + protected List<String[]> data2StringArrays() { + NumberFormat kmf = Formatter.getCalculationKm(context.getMeta()); + NumberFormat mf = Formatter.getMeterFormat(context); + D4EArtifact arti = (D4EArtifact) master; + RangeAccess access = new RangeAccess(arti); + + List<String[]> retval = new ArrayList<String[]>(); + + for (BedDifferencesResult result : results) { + BedDiffYearResult yResult = (BedDiffYearResult) result; + String desc = result.getDiffDescription(); + double[][] kms = yResult.getDifferencesData(); + double[][] sounding1 = yResult.getSoundingWidth1Data(); + double[][] sounding2 = yResult.getSoundingWidth2Data(); + double[][] gap1 = yResult.getDataGap1Data(); + double[][] gap2 = yResult.getDataGap2Data(); + + for (int j = 0; j < kms[0].length; j++) { + String sound1 = !Double.isNaN(sounding1[1][j]) + ? mf.format(sounding1[1][j]) + : ""; + String sound2 = !Double.isNaN(sounding2[1][j]) + ? mf.format(sounding2[1][j]) + : ""; + String g1 = !Double.isNaN(gap1[1][j]) + ? mf.format(gap1[1][j]) + : ""; + String g2 = !Double.isNaN(gap2[1][j]) + ? mf.format(gap2[1][j]) + : ""; + retval.add(new String[] { + kmf.format(kms[0][j]), + desc, + mf.format(kms[1][j]), + sound1, + sound2, + g1, + g2 + }); + } + } + if (access.getFrom() > access.getTo()) { + Collections.reverse(retval); + } + return retval; + } @Override protected void writeCSVData(CSVWriter writer) throws IOException { writeCSVHeader(writer); - NumberFormat kmf = Formatter.getCalculationKm(context.getMeta()); - NumberFormat mf = Formatter.getMeterFormat(context); - for (BedDifferencesResult result : results) { - if (result instanceof BedDiffYearResult) { - BedDiffYearResult yResult = (BedDiffYearResult) result; - String desc = result.getDiffDescription(); - double[][] kms = yResult.getDifferencesData(); - double[][] sounding1 = yResult.getSoundingWidth1Data(); - double[][] sounding2 = yResult.getSoundingWidth2Data(); - double[][] gap1 = yResult.getDataGap1Data(); - double[][] gap2 = yResult.getDataGap2Data(); - for (int j = 0; j < kms[0].length; j++) { - String sound1 = !Double.isNaN(sounding1[1][j]) - ? mf.format(sounding1[1][j]) - : ""; - String sound2 = !Double.isNaN(sounding2[1][j]) - ? mf.format(sounding2[1][j]) - : ""; - String g1 = !Double.isNaN(gap1[1][j]) - ? mf.format(gap1[1][j]) - : ""; - String g2 = !Double.isNaN(gap2[1][j]) - ? mf.format(gap2[1][j]) - : ""; - writer.writeNext(new String[] { - kmf.format(kms[0][j]), - desc, - mf.format(kms[1][j]), - sound1, - sound2, - g1, - g2 - }); - } - } - else { - double[][] kms = result.getDifferencesData(); - String desc = result.getDiffDescription(); - for (int j = 0; j < kms[0].length; j++) { - writer.writeNext(new String[] { - kmf.format(kms[0][j]), - desc, - mf.format(kms[1][j]), - }); - } - } - } + writer.writeAll(data2StringArrays()); } @Override @@ -216,27 +217,8 @@ BedDifferenceJRDataSource source = new BedDifferenceJRDataSource(); addMetaData(source); - NumberFormat kmf = Formatter.getCalculationKm(context.getMeta()); - NumberFormat mf = Formatter.getMeterFormat(context); - for (BedDifferencesResult result: results) { - BedDiffYearResult yResult = (BedDiffYearResult) result; - double[][] kms = result.getDifferencesData(); - String desc = result.getDiffDescription(); - double[][] sounding1 = yResult.getSoundingWidth1Data(); - double[][] sounding2 = yResult.getSoundingWidth2Data(); - double[][] gap1 = yResult.getDataGap1Data(); - double[][] gap2 = yResult.getDataGap2Data(); - for (int j = 0; j < kms[0].length; j++) { - source.addData(new String[] { - kmf.format(kms[0][j]), - desc, - mf.format(kms[1][j]), - mf.format(sounding1[1][j]), - mf.format(sounding2[1][j]), - mf.format(gap1[1][j]), - mf.format(gap2[1][j]) - }); - } + for (String[] str: data2StringArrays()) { + source.addData(str); } return source; }