# HG changeset patch # User Felix Wolfsteller # 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 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 rows = new ArrayList(kms.size()); for (int i = 0, K = kms.size(); i < K; i++) { double[] row = new double[cols];