changeset 9208:53cc5b496692

funcion replaced by interface
author gernotbelger
date Tue, 03 Jul 2018 11:16:51 +0200
parents 559775e2f53c
children f7f226666c59
files artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/FloodDurationProcessor.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/FloodHeightProcessor.java artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java
diffstat 3 files changed, 58 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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);
--- 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

http://dive4elements.wald.intevation.org