changeset 9621:387822d7d5e8

Missing class added
author mschaefer
date Thu, 10 Oct 2019 17:21:19 +0200
parents 26e113e8224f
children 677ff7ed9a60
files artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationInfrastructureChoice.java
diffstat 1 files changed, 109 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationInfrastructureChoice.java	Thu Oct 10 17:21:19 2019 +0200
@@ -0,0 +1,109 @@
+/* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.artifacts.sinfo.flood_duration;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+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.ResultRow;
+import org.dive4elements.river.artifacts.resources.Resources;
+import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
+import org.dive4elements.river.model.Attribute.AttributeKey;
+
+/**
+ * Infrastructure group plus type and riverside choice
+ *
+ * @author Domenico Nardi Tironi
+ */
+public final class FloodDurationInfrastructureChoice 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 FloodDurationInfrastructureChoice(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);
+        this.m_riverside = (AttributeKey) row.getValue(SInfoResultType.riverside);
+    }
+
+    public AttributeKey getRiverside() {
+        return this.m_riverside;
+    }
+
+    public String getGroup() {
+        return this.m_group;
+    }
+
+    public String getType() {
+        return this.m_type;
+    }
+
+    @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 FloodDurationInfrastructureChoice other = (FloodDurationInfrastructureChoice) 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);
+    }
+
+    /**
+     * Gets all group-type-pairs (separated by a tab) of a set of choices
+     */
+    public static Set<String> getGroupTypes(final Set<FloodDurationInfrastructureChoice> choices) {
+        final Set<String> choiceStrings = new HashSet<>();
+        for (final FloodDurationInfrastructureChoice choice : choices)
+            choiceStrings.add(choice.getGroup() + '\t' + choice.getType());
+        return choiceStrings;
+    }
+}

http://dive4elements.wald.intevation.org