[PATCH 2 of 2] (issue1596) Sort Export of Middle bedHeight
Wald Commits
scm-commit at wald.intevation.org
Mon Dec 16 12:26:58 CET 2013
# HG changeset patch
# User Andre Heinecke <aheinecke at intevation.de>
# Date 1387193212 -3600
# Node ID c130196389dfa98d35273db78bead6ac0bf90272
# Parent 4508501cdde711658886f9bc1f50943104336d76
(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
diff -r 4508501cdde7 -r c130196389df artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightExporter.java
--- 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)),
+ });
+ }
+
}
}
More information about the Dive4elements-commits
mailing list