[PATCH 1 of 4] Refactoring: extracted method
Wald Commits
scm-commit at wald.intevation.org
Mon Dec 2 12:16:53 CET 2013
# HG changeset patch
# User Felix Wolfsteller <felix.wolfsteller at intevation.de>
# Date 1385977363 -3600
# Node ID e999a920f0e5120e7b666bc88ca7da43eba935f8
# Parent 3dd505477fcc8b4fb5ad4486dcf4250ce1ff52dd
Refactoring: extracted method
diff -r 3dd505477fcc -r e999a920f0e5 artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java Mon Dec 02 10:08:23 2013 +0100
+++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java Mon Dec 02 10:42:43 2013 +0100
@@ -59,39 +59,51 @@
results = new BedQualityResult[0];
}
+ /** Populate param kms with kms from param beds and loads, return it. */
+ private TDoubleArrayList populateKmList(BedDiameterResult[] beds,
+ BedloadDiameterResult[] loads,
+ TDoubleArrayList kms) {
+ for (int j = 0; j < beds.length; j++) {
+ TDoubleArrayList bkms = beds[j].getKms();
+ for (int k = 0, K = bkms.size(); k < K; k++) {
+ double km = bkms.get(k);
+ if (!kms.contains(km)) { // XXX: O(N^2)
+ kms.add(km);
+ }
+ }
+ }
+ for (int j = 0; j < loads.length; j++) {
+ TDoubleArrayList lkms = loads[j].getKms();
+ for (int k = 0, L = lkms.size(); k < L; k++) {
+ double km = lkms.get(k);
+ if (!kms.contains(km)) { // XXX: O(N^2)
+ kms.add(km);
+ }
+ }
+ }
+ return kms;
+ }
private List<double[]> createDataRows() {
+ // Calculate how many columns and rows we need.
TDoubleArrayList kms = new TDoubleArrayList();
+
int cols = 1;
for (BedQualityResult result : results) {
- BedDiameterResult[] beds = result.getBedResults();
- for (int j = 0; j < beds.length; j++) {
- TDoubleArrayList bkms = beds[j].getKms();
- for (int k = 0, K = bkms.size(); k < K; k++) {
- double km = bkms.get(k);
- if (!kms.contains(km)) { // XXX: O(N^2)
- kms.add(km);
- }
- }
- }
+ BedDiameterResult[] beds = result.getBedResults();
BedloadDiameterResult[] loads = result.getBedloadResults();
- for (int j = 0; j < loads.length; j++) {
- TDoubleArrayList lkms = loads[j].getKms();
- for (int k = 0, L = lkms.size(); k < L; k++) {
- double km = lkms.get(k);
- if (!kms.contains(km)) { // XXX: O(N^2)
- kms.add(km);
- }
- }
- }
+
+ kms = populateKmList(beds, loads, kms);
+
cols += beds.length * 2;
- cols += loads.length;
if (beds.length > 0) {
cols += 4;
}
+ cols += loads.length;
}
kms.sort();
+
List<double[]> rows = new ArrayList<double[]>(kms.size());
for (int i = 0, K = kms.size(); i < K; i++) {
double[] row = new double[cols];
More information about the Dive4elements-commits
mailing list