Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java @ 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 | ce325339e9ba |
children | 5e38e2924c07 |
comparison
equal
deleted
inserted
replaced
8642:9db1f48bfea9 | 8643:999b9ab16738 |
---|---|
15 import java.util.List; | 15 import java.util.List; |
16 import java.util.Map; | 16 import java.util.Map; |
17 import java.util.HashMap; | 17 import java.util.HashMap; |
18 import java.util.Locale; | 18 import java.util.Locale; |
19 import java.util.Date; | 19 import java.util.Date; |
20 import java.util.Collections; | |
20 import java.text.DateFormat; | 21 import java.text.DateFormat; |
21 | 22 |
22 import org.apache.log4j.Logger; | 23 import org.apache.log4j.Logger; |
23 import org.apache.commons.lang.StringUtils; | 24 import org.apache.commons.lang.StringUtils; |
24 | 25 |
85 | 86 |
86 public BedDifferenceExporter() { | 87 public BedDifferenceExporter() { |
87 results = new BedDifferencesResult[0]; | 88 results = new BedDifferencesResult[0]; |
88 } | 89 } |
89 | 90 |
91 protected List<String[]> data2StringArrays() { | |
92 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta()); | |
93 NumberFormat mf = Formatter.getMeterFormat(context); | |
94 D4EArtifact arti = (D4EArtifact) master; | |
95 RangeAccess access = new RangeAccess(arti); | |
96 | |
97 List<String[]> retval = new ArrayList<String[]>(); | |
98 | |
99 for (BedDifferencesResult result : results) { | |
100 BedDiffYearResult yResult = (BedDiffYearResult) result; | |
101 String desc = result.getDiffDescription(); | |
102 double[][] kms = yResult.getDifferencesData(); | |
103 double[][] sounding1 = yResult.getSoundingWidth1Data(); | |
104 double[][] sounding2 = yResult.getSoundingWidth2Data(); | |
105 double[][] gap1 = yResult.getDataGap1Data(); | |
106 double[][] gap2 = yResult.getDataGap2Data(); | |
107 | |
108 for (int j = 0; j < kms[0].length; j++) { | |
109 String sound1 = !Double.isNaN(sounding1[1][j]) | |
110 ? mf.format(sounding1[1][j]) | |
111 : ""; | |
112 String sound2 = !Double.isNaN(sounding2[1][j]) | |
113 ? mf.format(sounding2[1][j]) | |
114 : ""; | |
115 String g1 = !Double.isNaN(gap1[1][j]) | |
116 ? mf.format(gap1[1][j]) | |
117 : ""; | |
118 String g2 = !Double.isNaN(gap2[1][j]) | |
119 ? mf.format(gap2[1][j]) | |
120 : ""; | |
121 retval.add(new String[] { | |
122 kmf.format(kms[0][j]), | |
123 desc, | |
124 mf.format(kms[1][j]), | |
125 sound1, | |
126 sound2, | |
127 g1, | |
128 g2 | |
129 }); | |
130 } | |
131 } | |
132 if (access.getFrom() > access.getTo()) { | |
133 Collections.reverse(retval); | |
134 } | |
135 return retval; | |
136 } | |
90 @Override | 137 @Override |
91 protected void writeCSVData(CSVWriter writer) throws IOException { | 138 protected void writeCSVData(CSVWriter writer) throws IOException { |
92 writeCSVHeader(writer); | 139 writeCSVHeader(writer); |
93 | 140 |
94 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta()); | 141 writer.writeAll(data2StringArrays()); |
95 NumberFormat mf = Formatter.getMeterFormat(context); | |
96 for (BedDifferencesResult result : results) { | |
97 if (result instanceof BedDiffYearResult) { | |
98 BedDiffYearResult yResult = (BedDiffYearResult) result; | |
99 String desc = result.getDiffDescription(); | |
100 double[][] kms = yResult.getDifferencesData(); | |
101 double[][] sounding1 = yResult.getSoundingWidth1Data(); | |
102 double[][] sounding2 = yResult.getSoundingWidth2Data(); | |
103 double[][] gap1 = yResult.getDataGap1Data(); | |
104 double[][] gap2 = yResult.getDataGap2Data(); | |
105 for (int j = 0; j < kms[0].length; j++) { | |
106 String sound1 = !Double.isNaN(sounding1[1][j]) | |
107 ? mf.format(sounding1[1][j]) | |
108 : ""; | |
109 String sound2 = !Double.isNaN(sounding2[1][j]) | |
110 ? mf.format(sounding2[1][j]) | |
111 : ""; | |
112 String g1 = !Double.isNaN(gap1[1][j]) | |
113 ? mf.format(gap1[1][j]) | |
114 : ""; | |
115 String g2 = !Double.isNaN(gap2[1][j]) | |
116 ? mf.format(gap2[1][j]) | |
117 : ""; | |
118 writer.writeNext(new String[] { | |
119 kmf.format(kms[0][j]), | |
120 desc, | |
121 mf.format(kms[1][j]), | |
122 sound1, | |
123 sound2, | |
124 g1, | |
125 g2 | |
126 }); | |
127 } | |
128 } | |
129 else { | |
130 double[][] kms = result.getDifferencesData(); | |
131 String desc = result.getDiffDescription(); | |
132 for (int j = 0; j < kms[0].length; j++) { | |
133 writer.writeNext(new String[] { | |
134 kmf.format(kms[0][j]), | |
135 desc, | |
136 mf.format(kms[1][j]), | |
137 }); | |
138 } | |
139 } | |
140 } | |
141 } | 142 } |
142 | 143 |
143 @Override | 144 @Override |
144 protected void addData(Object data) { | 145 protected void addData(Object data) { |
145 if (!(data instanceof CalculationResult)) { | 146 if (!(data instanceof CalculationResult)) { |
214 | 215 |
215 protected BedDifferenceJRDataSource createJRData() { | 216 protected BedDifferenceJRDataSource createJRData() { |
216 BedDifferenceJRDataSource source = new BedDifferenceJRDataSource(); | 217 BedDifferenceJRDataSource source = new BedDifferenceJRDataSource(); |
217 | 218 |
218 addMetaData(source); | 219 addMetaData(source); |
219 NumberFormat kmf = Formatter.getCalculationKm(context.getMeta()); | 220 for (String[] str: data2StringArrays()) { |
220 NumberFormat mf = Formatter.getMeterFormat(context); | 221 source.addData(str); |
221 for (BedDifferencesResult result: results) { | |
222 BedDiffYearResult yResult = (BedDiffYearResult) result; | |
223 double[][] kms = result.getDifferencesData(); | |
224 String desc = result.getDiffDescription(); | |
225 double[][] sounding1 = yResult.getSoundingWidth1Data(); | |
226 double[][] sounding2 = yResult.getSoundingWidth2Data(); | |
227 double[][] gap1 = yResult.getDataGap1Data(); | |
228 double[][] gap2 = yResult.getDataGap2Data(); | |
229 for (int j = 0; j < kms[0].length; j++) { | |
230 source.addData(new String[] { | |
231 kmf.format(kms[0][j]), | |
232 desc, | |
233 mf.format(kms[1][j]), | |
234 mf.format(sounding1[1][j]), | |
235 mf.format(sounding2[1][j]), | |
236 mf.format(gap1[1][j]), | |
237 mf.format(gap2[1][j]) | |
238 }); | |
239 } | |
240 } | 222 } |
241 return source; | 223 return source; |
242 } | 224 } |
243 | 225 |
244 @Override | 226 @Override |