Mercurial > dive4elements > river
changeset 7693:c130196389df
(issue1596) Sort Export of Middle bedHeight
This simplyfies internal Data storage by removing
the ArrayList wrapper. Usually this is a list of size 1.
The data list of which each member is a distinct sounding
is then sorted by description or first indexed KM.
Afterwards the km index is mapped in a sorted map to
export it in order of km and not in oder of index
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 16 Dec 2013 12:26:52 +0100 |
parents | 4508501cdde7 |
children | 622c89640048 |
files | artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightExporter.java |
diffstat | 1 files changed, 51 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightExporter.java Mon Dec 16 12:23:01 2013 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightExporter.java Mon Dec 16 12:26:52 2013 +0100 @@ -12,6 +12,9 @@ import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; +import java.util.Collections; +import java.util.SortedMap; +import java.util.TreeMap; import org.apache.log4j.Logger; @@ -61,10 +64,10 @@ "export.bedheight_middle.csv.header.locations"; - protected List<MiddleBedHeightData[]> data; + protected List<MiddleBedHeightData> data; public MiddleBedHeightExporter() { - data = new ArrayList<MiddleBedHeightData[]>(); + data = new ArrayList<MiddleBedHeightData>(); } @Override @@ -74,7 +77,9 @@ if (d instanceof MiddleBedHeightData[]) { logger.debug("Add new data of type MiddleBedHeightData"); - data.add((MiddleBedHeightData[]) d); + for (MiddleBedHeightData mD :(MiddleBedHeightData[]) d) { + data.add(mD); + } } } } @@ -87,7 +92,9 @@ writeCSVHeader(writer); - for (MiddleBedHeightData[] d: data) { + Collections.sort(data); + + for (MiddleBedHeightData d: data) { data2CSV(writer, d); } } @@ -109,7 +116,7 @@ } - protected void data2CSV(CSVWriter writer, MiddleBedHeightData[] mData) { + protected void data2CSV(CSVWriter writer, MiddleBedHeightData data) { logger.debug("Add next MiddleBedHeightData to CSV"); D4EArtifact flys = (D4EArtifact) master; @@ -123,43 +130,48 @@ heightF.setMaximumFractionDigits(1); soundF.setMaximumFractionDigits(1); - for (MiddleBedHeightData data: mData) { - for (int i = 0, n = data.size(); i < n; i++) { - int start = data.getStartYear(); - int end = data.getEndYear(); - if (start == end) { - String uncert = !Double.isNaN(data.getUncertainty(i)) ? - uncertF.format(data.getUncertainty(i)) : ""; - String gap = !Double.isNaN(data.getDataGap(i)) ? - gapF.format(data.getDataGap(i)) + "%" : ""; - String sound = !Double.isNaN(data.getSoundingWidth(i)) ? - soundF.format(data.getSoundingWidth(i)) : ""; - writer.writeNext(new String[] { - kmF.format(data.getKM(i)), - data.getDescription(), - heightF.format(data.getMiddleHeight(i)), - uncert, - gap, - sound, - widthF.format(data.getWidth(i)), - RiverUtils.getLocationDescription(flys, data.getKM(i)), - }); - } - else { - writer.writeNext(new String[] { - kmF.format(data.getKM(i)), - data.getDescription(), - heightF.format(data.getMiddleHeight(i)), - "", - "", - "", - "", - RiverUtils.getLocationDescription(flys, data.getKM(i)), - }); - } + SortedMap <Double, Integer> kmIndexMap = new TreeMap<Double, Integer>(); + for (int i = 0, n = data.size(); i < n; i++) { + kmIndexMap.put(data.getKM(i), i); + } + + for (int i: kmIndexMap.values()) { + int start = data.getStartYear(); + int end = data.getEndYear(); + + if (start == end) { + String uncert = !Double.isNaN(data.getUncertainty(i)) ? + uncertF.format(data.getUncertainty(i)) : ""; + String gap = !Double.isNaN(data.getDataGap(i)) ? + gapF.format(data.getDataGap(i)) + "%" : ""; + String sound = !Double.isNaN(data.getSoundingWidth(i)) ? + soundF.format(data.getSoundingWidth(i)) : ""; + writer.writeNext(new String[] { + kmF.format(data.getKM(i)), + data.getDescription(), + heightF.format(data.getMiddleHeight(i)), + uncert, + gap, + sound, + widthF.format(data.getWidth(i)), + RiverUtils.getLocationDescription(flys, data.getKM(i)), + }); } + else { + writer.writeNext(new String[] { + kmF.format(data.getKM(i)), + data.getDescription(), + heightF.format(data.getMiddleHeight(i)), + "", + "", + "", + "", + RiverUtils.getLocationDescription(flys, data.getKM(i)), + }); + } + } }