diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java @ 9620:26e113e8224f

Nachtrag Pos. 20: flood duration calculation for multiple infrastructure groups/types, local class FloodDurationCalculationResult.Infrastructure renamed and extracted into own class
author mschaefer
date Thu, 10 Oct 2019 17:11:54 +0200
parents d889ffe2fb05
children 677ff7ed9a60
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java	Thu Oct 10 16:08:47 2019 +0200
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationCalculationResult.java	Thu Oct 10 17:11:54 2019 +0200
@@ -9,7 +9,6 @@
  */
 package org.dive4elements.river.artifacts.sinfo.flood_duration;
 
-import java.io.Serializable;
 import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -19,9 +18,6 @@
 import java.util.Set;
 
 import org.apache.commons.collections.Predicate;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.dive4elements.artifacts.CallContext;
 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
 import org.dive4elements.river.artifacts.common.AbstractExportContext;
 import org.dive4elements.river.artifacts.common.ExportContextCSV;
@@ -30,10 +26,8 @@
 import org.dive4elements.river.artifacts.common.IResultType;
 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
 import org.dive4elements.river.artifacts.common.ResultRow;
-import org.dive4elements.river.artifacts.resources.Resources;
 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
-import org.dive4elements.river.model.Attribute.AttributeKey;
 
 import gnu.trove.TDoubleArrayList;
 
@@ -44,18 +38,18 @@
  */
 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult {
 
-    private final static class InfrastructurePredicate implements Predicate {
+    private final static class IsInfrastructureChoicePredicate implements Predicate {
 
-        private final Infrastructure m_infrastructure;
+        private final FloodDurationInfrastructureChoice m_infrastructure;
 
-        public InfrastructurePredicate(final Infrastructure infrastructure) {
+        public IsInfrastructureChoicePredicate(final FloodDurationInfrastructureChoice infrastructure) {
             this.m_infrastructure = infrastructure;
         }
 
         @Override
         public boolean evaluate(final Object object) {
             final ResultRow row = (ResultRow) object;
-            final Infrastructure test = new Infrastructure(row);
+            final FloodDurationInfrastructureChoice test = new FloodDurationInfrastructureChoice(row);
             return this.m_infrastructure.equals(test);
         }
     }
@@ -70,69 +64,6 @@
         }
     }
 
-    public static final class Infrastructure implements Serializable {
-
-        private static final long serialVersionUID = 1L;
-
-        private final String m_group;
-
-        private final String m_type;
-
-        private final AttributeKey m_riverside;
-
-        private static final String FACET_FLOOD_DURATION_DESCRIPTION = "sinfo_facet_flood_duration";
-
-        private static final String FACET_ABSOLUTE_HEIGHT = "sinfo.flood_duration.absolute.height";
-
-        public Infrastructure(final ResultRow row) {
-            this.m_group = String.valueOf(row.getValue(SInfoResultType.infrastructuregroup));
-            this.m_type = String.valueOf(row.getValue(SInfoResultType.infrastructuretype));
-            final String riversideStr = String.valueOf(row.getValue(SInfoResultType.riverside));
-            this.m_riverside = riversideStr.equals("null") ? AttributeKey.NONE : AttributeKey.valueOf(riversideStr);
-        }
-
-        public AttributeKey getRiverside() {
-            return this.m_riverside;
-        }
-
-        @Override
-        public int hashCode() {
-            return new HashCodeBuilder() //
-                    .append(this.m_group)//
-                    .append(this.m_type)//
-                    .append(this.m_riverside)//
-                    .toHashCode();
-        }
-
-        @Override
-        public boolean equals(final Object obj) {
-
-            if (obj == null)
-                return false;
-            if (obj == this)
-                return true;
-            if (obj.getClass() != getClass())
-                return false;
-
-            final Infrastructure other = (Infrastructure) obj;
-            return new EqualsBuilder() //
-                    .append(this.m_group, other.m_group) //
-                    .append(this.m_type, other.m_type) //
-                    .append(this.m_riverside, other.m_riverside) //
-                    .isEquals();
-        }
-
-        public String getFloodHeightLabel(final CallContext context) {
-            return Resources.getMsg(context.getMeta(), FACET_ABSOLUTE_HEIGHT, FACET_ABSOLUTE_HEIGHT)
-                    + " " + SInfoResultType.getInfrastructureLabel(context, this.m_group, this.m_type, this.m_riverside);
-        }
-
-        public String getFloodDurationLabel(final CallContext context) {
-            return Resources.getMsg(context.getMeta(), FACET_FLOOD_DURATION_DESCRIPTION, FACET_FLOOD_DURATION_DESCRIPTION)
-                    + " " + SInfoResultType.getInfrastructureLabel(context, this.m_group, this.m_type, this.m_riverside);
-        }
-    }
-
     private static final long serialVersionUID = 1L;
 
     private final boolean isUseWspl;
@@ -141,7 +72,7 @@
 
     private final int maxWaterlevelPdf = 3;
 
-    private final Set<Infrastructure> m_infrastructures;
+    private final Set<FloodDurationInfrastructureChoice> m_infrastructures;
 
     public interface ValueGetter {
         double getValue(DurationWaterlevel waterlevel);
@@ -152,14 +83,14 @@
     }
 
     public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows, final boolean isUseWspl,
-            final Set<Infrastructure> infrastructures) {
+            final Set<FloodDurationInfrastructureChoice> infrastructures) {
         super(label, rows);
         this.waterlevelLabels = mainvalueLabels;
         this.isUseWspl = isUseWspl;
         this.m_infrastructures = infrastructures;
     }
 
-    public Set<Infrastructure> getInfrastructureMap() {
+    public Set<FloodDurationInfrastructureChoice> getInfrastructureMap() {
         return this.m_infrastructures;
     }
 
@@ -346,9 +277,9 @@
     /**
      * Gets the longitudinal section of a result value type for one river side
      */
-    public final double[][] getInfrastructurePoints(final IResultType type, final Infrastructure infrastructure) {
+    public final double[][] getInfrastructurePoints(final IResultType type, final FloodDurationInfrastructureChoice infrastructure) {
 
-        return getPoints(GeneralResultType.station, type, new InfrastructurePredicate(infrastructure));
+        return getPoints(GeneralResultType.station, type, new IsInfrastructureChoicePredicate(infrastructure));
     }
 
     /**

http://dive4elements.wald.intevation.org