comparison 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
comparison
equal deleted inserted replaced
9619:63bbd5e45839 9620:26e113e8224f
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the 7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details. 8 * documentation coming with Dive4Elements River for details.
9 */ 9 */
10 package org.dive4elements.river.artifacts.sinfo.flood_duration; 10 package org.dive4elements.river.artifacts.sinfo.flood_duration;
11 11
12 import java.io.Serializable;
13 import java.text.NumberFormat; 12 import java.text.NumberFormat;
14 import java.util.ArrayList; 13 import java.util.ArrayList;
15 import java.util.Collection; 14 import java.util.Collection;
16 import java.util.Collections; 15 import java.util.Collections;
17 import java.util.List; 16 import java.util.List;
18 import java.util.Map.Entry; 17 import java.util.Map.Entry;
19 import java.util.Set; 18 import java.util.Set;
20 19
21 import org.apache.commons.collections.Predicate; 20 import org.apache.commons.collections.Predicate;
22 import org.apache.commons.lang.builder.EqualsBuilder;
23 import org.apache.commons.lang.builder.HashCodeBuilder;
24 import org.dive4elements.artifacts.CallContext;
25 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; 21 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
26 import org.dive4elements.river.artifacts.common.AbstractExportContext; 22 import org.dive4elements.river.artifacts.common.AbstractExportContext;
27 import org.dive4elements.river.artifacts.common.ExportContextCSV; 23 import org.dive4elements.river.artifacts.common.ExportContextCSV;
28 import org.dive4elements.river.artifacts.common.ExportContextPDF; 24 import org.dive4elements.river.artifacts.common.ExportContextPDF;
29 import org.dive4elements.river.artifacts.common.GeneralResultType; 25 import org.dive4elements.river.artifacts.common.GeneralResultType;
30 import org.dive4elements.river.artifacts.common.IResultType; 26 import org.dive4elements.river.artifacts.common.IResultType;
31 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource; 27 import org.dive4elements.river.artifacts.common.MetaAndTableJRDataSource;
32 import org.dive4elements.river.artifacts.common.ResultRow; 28 import org.dive4elements.river.artifacts.common.ResultRow;
33 import org.dive4elements.river.artifacts.resources.Resources;
34 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType; 29 import org.dive4elements.river.artifacts.sinfo.common.SInfoResultType;
35 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo; 30 import org.dive4elements.river.artifacts.sinfo.util.RiverInfo;
36 import org.dive4elements.river.model.Attribute.AttributeKey;
37 31
38 import gnu.trove.TDoubleArrayList; 32 import gnu.trove.TDoubleArrayList;
39 33
40 /** 34 /**
41 * Contains the result of a {@link FloodDurationCalculation}. 35 * Contains the result of a {@link FloodDurationCalculation}.
42 * 36 *
43 * @author Gernot Belger 37 * @author Gernot Belger
44 */ 38 */
45 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult { 39 public final class FloodDurationCalculationResult extends AbstractCalculationExportableResult {
46 40
47 private final static class InfrastructurePredicate implements Predicate { 41 private final static class IsInfrastructureChoicePredicate implements Predicate {
48 42
49 private final Infrastructure m_infrastructure; 43 private final FloodDurationInfrastructureChoice m_infrastructure;
50 44
51 public InfrastructurePredicate(final Infrastructure infrastructure) { 45 public IsInfrastructureChoicePredicate(final FloodDurationInfrastructureChoice infrastructure) {
52 this.m_infrastructure = infrastructure; 46 this.m_infrastructure = infrastructure;
53 } 47 }
54 48
55 @Override 49 @Override
56 public boolean evaluate(final Object object) { 50 public boolean evaluate(final Object object) {
57 final ResultRow row = (ResultRow) object; 51 final ResultRow row = (ResultRow) object;
58 final Infrastructure test = new Infrastructure(row); 52 final FloodDurationInfrastructureChoice test = new FloodDurationInfrastructureChoice(row);
59 return this.m_infrastructure.equals(test); 53 return this.m_infrastructure.equals(test);
60 } 54 }
61 } 55 }
62 56
63 private final static class HasInfrastructurePredicate implements Predicate { 57 private final static class HasInfrastructurePredicate implements Predicate {
68 62
69 return row.getValue(SInfoResultType.riverside) != null; 63 return row.getValue(SInfoResultType.riverside) != null;
70 } 64 }
71 } 65 }
72 66
73 public static final class Infrastructure implements Serializable {
74
75 private static final long serialVersionUID = 1L;
76
77 private final String m_group;
78
79 private final String m_type;
80
81 private final AttributeKey m_riverside;
82
83 private static final String FACET_FLOOD_DURATION_DESCRIPTION = "sinfo_facet_flood_duration";
84
85 private static final String FACET_ABSOLUTE_HEIGHT = "sinfo.flood_duration.absolute.height";
86
87 public Infrastructure(final ResultRow row) {
88 this.m_group = String.valueOf(row.getValue(SInfoResultType.infrastructuregroup));
89 this.m_type = String.valueOf(row.getValue(SInfoResultType.infrastructuretype));
90 final String riversideStr = String.valueOf(row.getValue(SInfoResultType.riverside));
91 this.m_riverside = riversideStr.equals("null") ? AttributeKey.NONE : AttributeKey.valueOf(riversideStr);
92 }
93
94 public AttributeKey getRiverside() {
95 return this.m_riverside;
96 }
97
98 @Override
99 public int hashCode() {
100 return new HashCodeBuilder() //
101 .append(this.m_group)//
102 .append(this.m_type)//
103 .append(this.m_riverside)//
104 .toHashCode();
105 }
106
107 @Override
108 public boolean equals(final Object obj) {
109
110 if (obj == null)
111 return false;
112 if (obj == this)
113 return true;
114 if (obj.getClass() != getClass())
115 return false;
116
117 final Infrastructure other = (Infrastructure) obj;
118 return new EqualsBuilder() //
119 .append(this.m_group, other.m_group) //
120 .append(this.m_type, other.m_type) //
121 .append(this.m_riverside, other.m_riverside) //
122 .isEquals();
123 }
124
125 public String getFloodHeightLabel(final CallContext context) {
126 return Resources.getMsg(context.getMeta(), FACET_ABSOLUTE_HEIGHT, FACET_ABSOLUTE_HEIGHT)
127 + " " + SInfoResultType.getInfrastructureLabel(context, this.m_group, this.m_type, this.m_riverside);
128 }
129
130 public String getFloodDurationLabel(final CallContext context) {
131 return Resources.getMsg(context.getMeta(), FACET_FLOOD_DURATION_DESCRIPTION, FACET_FLOOD_DURATION_DESCRIPTION)
132 + " " + SInfoResultType.getInfrastructureLabel(context, this.m_group, this.m_type, this.m_riverside);
133 }
134 }
135
136 private static final long serialVersionUID = 1L; 67 private static final long serialVersionUID = 1L;
137 68
138 private final boolean isUseWspl; 69 private final boolean isUseWspl;
139 70
140 private final String[] waterlevelLabels; 71 private final String[] waterlevelLabels;
141 72
142 private final int maxWaterlevelPdf = 3; 73 private final int maxWaterlevelPdf = 3;
143 74
144 private final Set<Infrastructure> m_infrastructures; 75 private final Set<FloodDurationInfrastructureChoice> m_infrastructures;
145 76
146 public interface ValueGetter { 77 public interface ValueGetter {
147 double getValue(DurationWaterlevel waterlevel); 78 double getValue(DurationWaterlevel waterlevel);
148 } 79 }
149 80
150 private enum ExportMode { 81 private enum ExportMode {
151 pdf, csv 82 pdf, csv
152 } 83 }
153 84
154 public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows, final boolean isUseWspl, 85 public FloodDurationCalculationResult(final String label, final String[] mainvalueLabels, final Collection<ResultRow> rows, final boolean isUseWspl,
155 final Set<Infrastructure> infrastructures) { 86 final Set<FloodDurationInfrastructureChoice> infrastructures) {
156 super(label, rows); 87 super(label, rows);
157 this.waterlevelLabels = mainvalueLabels; 88 this.waterlevelLabels = mainvalueLabels;
158 this.isUseWspl = isUseWspl; 89 this.isUseWspl = isUseWspl;
159 this.m_infrastructures = infrastructures; 90 this.m_infrastructures = infrastructures;
160 } 91 }
161 92
162 public Set<Infrastructure> getInfrastructureMap() { 93 public Set<FloodDurationInfrastructureChoice> getInfrastructureMap() {
163 return this.m_infrastructures; 94 return this.m_infrastructures;
164 } 95 }
165 96
166 /** 97 /**
167 * Collection of the result rows containing only the rows describing an infrastructure 98 * Collection of the result rows containing only the rows describing an infrastructure
344 } 275 }
345 276
346 /** 277 /**
347 * Gets the longitudinal section of a result value type for one river side 278 * Gets the longitudinal section of a result value type for one river side
348 */ 279 */
349 public final double[][] getInfrastructurePoints(final IResultType type, final Infrastructure infrastructure) { 280 public final double[][] getInfrastructurePoints(final IResultType type, final FloodDurationInfrastructureChoice infrastructure) {
350 281
351 return getPoints(GeneralResultType.station, type, new InfrastructurePredicate(infrastructure)); 282 return getPoints(GeneralResultType.station, type, new IsInfrastructureChoicePredicate(infrastructure));
352 } 283 }
353 284
354 /** 285 /**
355 * Gets a longitudinal section of W, Q, or flood duration of one of the waterlevels 286 * Gets a longitudinal section of W, Q, or flood duration of one of the waterlevels
356 */ 287 */

http://dive4elements.wald.intevation.org