9621
|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; |
|
11 |
|
12 import java.io.Serializable; |
|
13 import java.util.HashSet; |
|
14 import java.util.Set; |
|
15 |
|
16 import org.apache.commons.lang.builder.EqualsBuilder; |
|
17 import org.apache.commons.lang.builder.HashCodeBuilder; |
|
18 import org.dive4elements.artifacts.CallContext; |
|
19 import org.dive4elements.river.artifacts.common.ResultRow; |
|
20 import org.dive4elements.river.artifacts.resources.Resources; |
|
21 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; |
|
22 import org.dive4elements.river.model.Attribute.AttributeKey; |
|
23 |
|
24 /** |
|
25 * Infrastructure group plus type and riverside choice |
|
26 * |
|
27 * @author Domenico Nardi Tironi |
|
28 */ |
|
29 public final class FloodDurationInfrastructureChoice implements Serializable { |
|
30 |
|
31 private static final long serialVersionUID = 1L; |
|
32 |
|
33 private final String m_group; |
|
34 |
|
35 private final String m_type; |
|
36 |
|
37 private final AttributeKey m_riverside; |
|
38 |
|
39 private static final String FACET_FLOOD_DURATION_DESCRIPTION = "sinfo_facet_flood_duration"; |
|
40 |
|
41 private static final String FACET_ABSOLUTE_HEIGHT = "sinfo.flood_duration.absolute.height"; |
|
42 |
|
43 public FloodDurationInfrastructureChoice(final ResultRow row) { |
|
44 this.m_group = String.valueOf(row.getValue(SInfoResultType.infrastructuregroup)); |
|
45 this.m_type = String.valueOf(row.getValue(SInfoResultType.infrastructuretype)); |
|
46 // final String riversideStr = String.valueOf(row.getValue(SInfoResultType.riverside)); |
|
47 // this.m_riverside = riversideStr.equals("null") ? AttributeKey.NONE : AttributeKey.valueOf(riversideStr); |
|
48 this.m_riverside = (AttributeKey) row.getValue(SInfoResultType.riverside); |
|
49 } |
|
50 |
|
51 public AttributeKey getRiverside() { |
|
52 return this.m_riverside; |
|
53 } |
|
54 |
|
55 public String getGroup() { |
|
56 return this.m_group; |
|
57 } |
|
58 |
|
59 public String getType() { |
|
60 return this.m_type; |
|
61 } |
|
62 |
|
63 @Override |
|
64 public int hashCode() { |
|
65 return new HashCodeBuilder() // |
|
66 .append(this.m_group)// |
|
67 .append(this.m_type)// |
|
68 .append(this.m_riverside)// |
|
69 .toHashCode(); |
|
70 } |
|
71 |
|
72 @Override |
|
73 public boolean equals(final Object obj) { |
|
74 |
|
75 if (obj == null) |
|
76 return false; |
|
77 if (obj == this) |
|
78 return true; |
|
79 if (obj.getClass() != getClass()) |
|
80 return false; |
|
81 |
|
82 final FloodDurationInfrastructureChoice other = (FloodDurationInfrastructureChoice) obj; |
|
83 return new EqualsBuilder() // |
|
84 .append(this.m_group, other.m_group) // |
|
85 .append(this.m_type, other.m_type) // |
|
86 .append(this.m_riverside, other.m_riverside) // |
|
87 .isEquals(); |
|
88 } |
|
89 |
|
90 public String getFloodHeightLabel(final CallContext context) { |
|
91 return Resources.getMsg(context.getMeta(), FACET_ABSOLUTE_HEIGHT, FACET_ABSOLUTE_HEIGHT) |
|
92 + " " + SInfoResultType.getInfrastructureLabel(context, this.m_group, this.m_type, this.m_riverside); |
|
93 } |
|
94 |
|
95 public String getFloodDurationLabel(final CallContext context) { |
|
96 return Resources.getMsg(context.getMeta(), FACET_FLOOD_DURATION_DESCRIPTION, FACET_FLOOD_DURATION_DESCRIPTION) |
|
97 + " " + SInfoResultType.getInfrastructureLabel(context, this.m_group, this.m_type, this.m_riverside); |
|
98 } |
|
99 |
|
100 /** |
|
101 * Gets all group-type-pairs (separated by a tab) of a set of choices |
|
102 */ |
|
103 public static Set<String> getGroupTypes(final Set<FloodDurationInfrastructureChoice> choices) { |
|
104 final Set<String> choiceStrings = new HashSet<>(); |
|
105 for (final FloodDurationInfrastructureChoice choice : choices) |
|
106 choiceStrings.add(choice.getGroup() + '\t' + choice.getType()); |
|
107 return choiceStrings; |
|
108 } |
|
109 } |