[PATCH 1 of 2] funcion replaced by interface

Wald Commits scm-commit at wald.intevation.org
Tue Jul 3 11:30:07 CEST 2018


# HG changeset patch
# User gernotbelger
# Date 1530609411 -7200
# Node ID 53cc5b496692f3e0b20a5eb8ac1a8300b4f2e16d
# Parent  559775e2f53c190ad76ec09e5e135cd137351649
funcion replaced by interface

diff -r 559775e2f53c -r 53cc5b496692 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/FloodDurationProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/FloodDurationProcessor.java	Mon Jul 02 19:12:54 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/FloodDurationProcessor.java	Tue Jul 03 11:16:51 2018 +0200
@@ -10,27 +10,21 @@
 
 package org.dive4elements.river.artifacts.sinfo.common;
 
-import java.util.Collection;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Set;
-import java.util.function.Function;
 
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.artifactdatabase.state.Facet;
 import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.common.AbstractCalculationResult;
-import org.dive4elements.river.artifacts.common.GeneralResultType;
-import org.dive4elements.river.artifacts.common.ResultRow;
 import org.dive4elements.river.artifacts.resources.Resources;
 import org.dive4elements.river.artifacts.sinfo.flood_duration.DurationWaterlevel;
 import org.dive4elements.river.artifacts.sinfo.flood_duration.FloodDurationCalculationResult;
+import org.dive4elements.river.artifacts.sinfo.flood_duration.FloodDurationCalculationResult.ValueGetter;
 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
 import org.dive4elements.river.exports.DiagramGenerator;
 import org.dive4elements.river.themes.ThemeDocument;
 
-import gnu.trove.TDoubleArrayList;
-
 /**
  * Processor to generate the facet and data series of infrastructure flood durations
  *
@@ -86,50 +80,24 @@
 
         if (FACET_MAIN_VALUE_DURATION.contentEquals(facetName)) {
 
-            final Function<DurationWaterlevel, Double> valueGetter = new Function<DurationWaterlevel, Double>() {
-                @Override
-                public Double apply(final DurationWaterlevel waterlevel) {
-                    return (double) waterlevel.getFloodDurDaysPerYear();
-                }
-            };
+            final AbstractCalculationResult data = getResult(generator, bundle);
 
-            // FIXME: instead (see CollisionXXProcessor) delegate to result
-            final double[][] points = getMainValueDurationPoints(generator, bundle, valueGetter);
+            if (data instanceof FloodDurationCalculationResult) {
+                final int index = getDataIndex(bundle);
+                final FloodDurationCalculationResult.ValueGetter valuegetter = new ValueGetter() {
+                    @Override
+                    public double getValue(final DurationWaterlevel waterlevel) {
+                        return waterlevel.getFloodDurDaysPerYear();
+                    }
+                };
+                final double[][] points = ((FloodDurationCalculationResult) data).getMainValueDurationPoints(generator, bundle, valuegetter, index);
+                return buildSeriesForType(points, generator, bundle, theme, visible, null);
+            }
 
-            return buildSeriesForType(points, generator, bundle, theme, visible, null);
         }
 
         final String error = String.format("Unknown facet name: %s", facetName);
         throw new UnsupportedOperationException(error);
     }
 
-    public static final double[][] getMainValueDurationPoints(final DiagramGenerator generator, final ArtifactAndFacet bundle,
-            final Function<DurationWaterlevel, Double> valueGetter) {
-
-        final AbstractCalculationResult data = getResult(generator, bundle);
-
-        final int index = getDataIndex(bundle);
-
-        ((SInfoResultFacet) bundle.getFacet()).getDataIndex();
-
-        final Collection<ResultRow> rows = data.getRows();
-
-        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);
-
-            final List<DurationWaterlevel> waterlevels = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel);
-            final DurationWaterlevel waterlevel = waterlevels.get(index);
-
-            final Double value = valueGetter.apply(waterlevel);
-
-            xPoints.add(station);
-            yPoints.add(value);
-        }
-
-        return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
-    }
 }
\ No newline at end of file
diff -r 559775e2f53c -r 53cc5b496692 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/FloodHeightProcessor.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/FloodHeightProcessor.java	Mon Jul 02 19:12:54 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/FloodHeightProcessor.java	Tue Jul 03 11:16:51 2018 +0200
@@ -12,7 +12,6 @@
 
 import java.util.HashSet;
 import java.util.Set;
-import java.util.function.Function;
 
 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.artifactdatabase.state.Facet;
@@ -21,6 +20,7 @@
 import org.dive4elements.river.artifacts.resources.Resources;
 import org.dive4elements.river.artifacts.sinfo.flood_duration.DurationWaterlevel;
 import org.dive4elements.river.artifacts.sinfo.flood_duration.FloodDurationCalculationResult;
+import org.dive4elements.river.artifacts.sinfo.flood_duration.FloodDurationCalculationResult.ValueGetter;
 import org.dive4elements.river.artifacts.states.DefaultState.ComputeType;
 import org.dive4elements.river.exports.DiagramGenerator;
 import org.dive4elements.river.exports.LongitudinalSectionGenerator;
@@ -77,13 +77,21 @@
             return buildSeriesForType(generator, bundle, theme, visible, SInfoResultType.infrastructureHeight, null);
 
         if (FACET_MAIN_VALUE_HEIGHT.contentEquals(facetName)) {
-            final double[][] heightPoints = FloodDurationProcessor.getMainValueDurationPoints(generator, bundle, new Function<DurationWaterlevel, Double>() {
-                @Override
-                public Double apply(final DurationWaterlevel waterlevel) {
-                    return waterlevel.getWaterlevel();
-                }
-            });
-            return buildSeriesForType(heightPoints, generator, bundle, theme, visible, null);
+
+            final AbstractCalculationResult data = getResult(generator, bundle);
+
+            if (data instanceof FloodDurationCalculationResult) {
+                final int index = getDataIndex(bundle);
+                final FloodDurationCalculationResult.ValueGetter valuegetter = new ValueGetter() {
+                    @Override
+                    public double getValue(final DurationWaterlevel waterlevel) {
+                        return waterlevel.getWaterlevel();
+                    }
+                };
+                final double[][] points = ((FloodDurationCalculationResult) data).getMainValueDurationPoints(generator, bundle, valuegetter, index);
+                return buildSeriesForType(points, generator, bundle, theme, visible, null);
+            }
+
         }
 
         final String error = String.format("Unknown facet name: %s", facetName);
diff -r 559775e2f53c -r 53cc5b496692 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java	Mon Jul 02 19:12:54 2018 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java	Tue Jul 03 11:16:51 2018 +0200
@@ -15,6 +15,7 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.dive4elements.artifactdatabase.state.ArtifactAndFacet;
 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
 import org.dive4elements.river.artifacts.common.AbstractExportContext;
 import org.dive4elements.river.artifacts.common.ExportContextCSV;
@@ -26,6 +27,7 @@
 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 gnu.trove.TDoubleArrayList;
 
@@ -44,6 +46,10 @@
     // private final WstInfo wstInfo;
     private final int maxWaterlevelPdf = 3;
 
+    public interface ValueGetter {
+        abstract double getValue(DurationWaterlevel waterlevel);
+    }
+
     private enum ExportMode {
         pdf, csv
     }
@@ -272,4 +278,27 @@
             return this.mainvalueLabels[j];
         return "";
     }
+
+    public final double[][] getMainValueDurationPoints(final DiagramGenerator generator, final ArtifactAndFacet bundle,
+            // final Function<DurationWaterlevel, Double> valueGetter
+            final ValueGetter valuegetter, final int dataIndex) {
+
+        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 List<DurationWaterlevel> waterlevels = (List<DurationWaterlevel>) row.getValue(SInfoResultType.customMultiRowColWaterlevel);
+            final DurationWaterlevel waterlevel = waterlevels.get(dataIndex);
+
+            final Double value = valuegetter.getValue(waterlevel);
+
+            xPoints.add(station);
+            yPoints.add(value);
+        }
+
+        return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
+    }
 }
\ No newline at end of file


More information about the Dive4Elements-commits mailing list