changeset 7625:e999a920f0e5

Refactoring: extracted method
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 02 Dec 2013 10:42:43 +0100
parents 3dd505477fcc
children 182f78d5f3eb
files artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java
diffstat 1 files changed, 32 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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];

http://dive4elements.wald.intevation.org