diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java @ 9265:e5367900dd6d

Small cleanup concerning getPoints Adding validStations as dataItem to flood duration calculation Flood duration now km aware
author gernotbelger
date Tue, 17 Jul 2018 19:48:28 +0200
parents b515ed950d39
children 9b16f58c62a7
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java	Tue Jul 17 19:48:23 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java	Tue Jul 17 19:48:28 2018 +0200
@@ -15,6 +15,7 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.apache.commons.collections.Predicate;
 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
 import org.dive4elements.river.artifacts.common.AbstractExportContext;
 import org.dive4elements.river.artifacts.common.ExportContextCSV;
@@ -26,7 +27,6 @@
 import org.dive4elements.river.artifacts.sinfo.common.SInfoI18NStrings;
 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
-import org.dive4elements.river.exports.DiagramGenerator;
 import org.dive4elements.river.model.Attribute.AttributeKey;
 
 import gnu.trove.TDoubleArrayList;
@@ -38,6 +38,22 @@
  */
 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult {
 
+    private final static class RiversidePredicate implements Predicate {
+
+        private final AttributeKey riverside;
+
+        public RiversidePredicate(final AttributeKey riverside) {
+            this.riverside = riverside;
+        }
+
+        @Override
+        public boolean evaluate(final Object object) {
+            final ResultRow row = (ResultRow) object;
+
+            return row.getValue(SInfoResultType.riverside) == this.riverside;
+        }
+    }
+
     private static final long serialVersionUID = 1L;
 
     private final String[] mainvalueLabels;
@@ -62,12 +78,17 @@
     /**
      * Collection of the result rows containing only the rows describing an infrastructure
      */
+    // FIXME: bad to override, instead make new method 'getInfrastructureRows' or similar?
     @Override
     public Collection<ResultRow> getRows() {
+
+        final Collection<ResultRow> rows = super.getRows();
+
         final List<ResultRow> infrasOnlyRows = new ArrayList<>();
-        for (final ResultRow row : this.rows)
+        for (final ResultRow row : rows) {
             if (row.getValue(SInfoResultType.infrastructuretype) != null)
                 infrasOnlyRows.add(row);
+        }
         return Collections.unmodifiableCollection(infrasOnlyRows);
     }
 
@@ -82,7 +103,7 @@
                 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_NAME, String.format("%d: %s", i, label));
             }
             // "# Bezugspegel: "
-            for (final ResultRow row : this.rows) {
+            for (final ResultRow row : getRows()) {
                 exportContextCSV.writeCSVMetaEntry(SInfoI18NStrings.CSV_META_HEADER_WATERLEVEL_GAUGE, row.getValue(SInfoResultType.gaugeLabel));
                 break;
             }
@@ -94,8 +115,8 @@
     protected String getJasperFile() {
         if (this.getWaterlevelCount() <= 1)
             return "/jasper/templates/sinfo.floodduration.jrxml";
-        else
-            return "/jasper/templates/sinfo.floodduration2.jrxml";
+
+        return "/jasper/templates/sinfo.floodduration2.jrxml";
     }
 
     protected String[] formatRow(final AbstractExportContext exportContextCSV, final ResultRow row, final ExportMode mode) {
@@ -160,7 +181,10 @@
         header.add(exportContextCSV.formatCsvHeader(SInfoResultType.location));
 
         exportContextCSV.writeCSVLine(header.toArray(new String[header.size()]));
+    }
 
+    public List<Double> getValidDurationChartKilometers() {
+        return getValues(GeneralResultType.station);
     }
 
     @Override
@@ -221,32 +245,20 @@
      * Gets the longitudinal section of a result value type for one river side
      */
     public final double[][] getInfrastructurePoints(final IResultType type, final AttributeKey riverside) {
-
-        final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
-        final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
-
-        for (final ResultRow row : this.rows) {
-
-            final double station = row.getDoubleValue(GeneralResultType.station);
-            final double value = row.getDoubleValue(type);
-            if (row.getValue(SInfoResultType.riverside) == riverside) {
-                xPoints.add(station);
-                yPoints.add(value);
-            }
-        }
-
-        return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
+        return getPoints(GeneralResultType.station, type, new RiversidePredicate(riverside));
     }
 
     /**
      * Gets a longitudinal section of W, Q, or flood duration of one of the waterlevels
      */
-    public final double[][] getMainValueDurationPoints(final DiagramGenerator generator, final ValueGetter valuegetter, final int dataIndex) {
+    public final double[][] getMainValueDurationPoints(final ValueGetter valuegetter, final int dataIndex) {
 
-        final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
-        final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
+        final Collection<ResultRow> rows = getRows();
 
-        for (final ResultRow row : this.rows) {
+        final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size());
+        final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size());
+
+        for (final ResultRow row : rows) {
 
             final double station = row.getDoubleValue(GeneralResultType.station);
 

http://dive4elements.wald.intevation.org