# HG changeset patch # User mschaefer # Date 1570720879 -7200 # Node ID 387822d7d5e830d1678e2e151147faf8db9c02f8 # Parent 26e113e8224f4ce1e7ec0088ba7f643f1fadcab6 Missing class added diff -r 26e113e8224f -r 387822d7d5e8 artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flood_duration/FloodDurationInfrastructureChoice.java --- /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 getGroupTypes(final Set choices) { + final Set choiceStrings = new HashSet<>(); + for (final FloodDurationInfrastructureChoice choice : choices) + choiceStrings.add(choice.getGroup() + '\t' + choice.getType()); + return choiceStrings; + } +}