9067
|
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 |
|
11 package org.dive4elements.river.artifacts.sinfo.flood_duration; |
|
12 |
|
13 import org.apache.commons.lang.math.DoubleRange; |
|
14 import org.apache.log4j.Logger; |
|
15 import org.dive4elements.river.artifacts.access.RangeAccess; |
|
16 import org.dive4elements.river.artifacts.common.AccessHelper; |
|
17 import org.dive4elements.river.artifacts.sinfo.SINFOArtifact; |
|
18 import org.dive4elements.river.artifacts.sinfo.SinfoCalcMode; |
|
19 |
|
20 import gnu.trove.TDoubleArrayList; |
|
21 |
|
22 /** |
|
23 * Access to the flow depth calculation type specific SInfo artifact data. |
|
24 * REMARK: this class is NOT intended to be hold in the results (or anywhere else), in order to avoid a permanent |
|
25 * reference to the artifact instance. |
|
26 * Hence we do NOT cache any data. |
|
27 * |
|
28 * @author Gernot Belger |
|
29 */ |
|
30 final class FloodDurationAccess extends RangeAccess { |
|
31 |
|
32 private static Logger log = Logger.getLogger(FloodDurationAccess.class); |
|
33 |
|
34 private static final String FIELD_DIFFIDS = "diffids"; //$NON-NLS-1$ |
|
35 |
|
36 private static final String FIELD_USE_TKH = "use_transport_bodies"; //$NON-NLS-1$ |
|
37 |
|
38 private final AccessHelper helper; |
|
39 |
|
40 /// Fields from state: |
|
41 |
|
42 // calculation_mode (String), sollte sinfo_calc_flood_duration sein |
|
43 // ld_from, ld_to, ld_step |
|
44 // riverside, mögliche werte: "state.sinfo.riverside.left" "state.sinfo.riverside.right" "state.sinfo.riverside.both" |
|
45 // wspl |
|
46 // State.sinfo.WQ: |
|
47 // <data name="wq_isq" type="Boolean" /> |
|
48 // <data name="wq_isfree" type="Boolean" /> |
|
49 // <data name="wq_isrange" type="Boolean" /> |
|
50 // <data name="wq_from" type="Double" /> |
|
51 // <data name="wq_to" type="Double" /> |
|
52 // <data name="wq_step" type="Double" /> |
|
53 // <data name="wq_single" type="Double[]" /> |
|
54 public FloodDurationAccess(final SINFOArtifact artifact) { |
|
55 super(artifact); |
|
56 |
|
57 /* assert calculation mode */ |
|
58 final SinfoCalcMode calculationMode = artifact.getCalculationMode(); |
|
59 this.helper = new AccessHelper(artifact); |
|
60 assert (calculationMode == SinfoCalcMode.sinfo_calc_flood_duration); |
|
61 } |
|
62 |
|
63 public DoubleRange getRange() { |
|
64 final double from = getFrom(); |
|
65 final double to = getTo(); |
|
66 return new DoubleRange(from, to); |
|
67 } |
|
68 |
|
69 @Override |
|
70 public Double getStep() { |
|
71 return super.getStep(); |
|
72 } |
|
73 |
|
74 public String getRiverside() { |
|
75 return super.getString("riverside"); |
|
76 } |
|
77 |
|
78 public Boolean getWspl() { |
|
79 return super.getBoolean("wspl"); |
|
80 } |
|
81 |
|
82 public Boolean getWqIsQ() { |
|
83 if (!getWspl()) { |
|
84 return null;// |
|
85 } |
|
86 return super.getBoolean("wq_isq"); |
|
87 } |
|
88 |
|
89 public Boolean getWqIsFree() { |
|
90 if (!getWspl()) { |
|
91 return null;// |
|
92 } |
|
93 return super.getBoolean("wq_isfree"); |
|
94 } |
|
95 |
|
96 public Boolean getWqIsRange() { |
|
97 if (!getWspl()) { |
|
98 return null;// |
|
99 } |
|
100 return super.getBoolean("wq_isrange"); |
|
101 } |
|
102 |
|
103 public Double getWqFrom() { |
|
104 if (!getWspl()) { |
|
105 return null;// |
|
106 } |
|
107 if (!getWqIsRange()) |
|
108 return null; |
|
109 |
|
110 return super.getDouble("wq_from"); |
|
111 } |
|
112 |
|
113 public Double getWqTo() { |
|
114 if (!getWspl()) { |
|
115 return null;// |
|
116 } |
|
117 if (!getWqIsRange()) |
|
118 return null; |
|
119 return super.getDouble("wq_to"); |
|
120 } |
|
121 |
|
122 public Double getWqStep() { |
|
123 if (!getWspl()) { |
|
124 return null; |
|
125 } |
|
126 if (!getWqIsRange()) |
|
127 return null; |
|
128 |
|
129 return super.getDouble("wq_step"); |
|
130 } |
|
131 |
|
132 public double[] getWqSingle() { |
|
133 if (!getWspl()) { |
|
134 return null;// |
|
135 } |
|
136 if (getWqIsRange()) |
|
137 return null; |
|
138 |
|
139 final String wqSingles = super.getString("wq_single"); |
|
140 |
|
141 if (wqSingles == null || wqSingles.isEmpty()) { |
|
142 log.warn("No wqSingles provided"); |
|
143 return null; |
|
144 } |
|
145 final TDoubleArrayList doubles = new gnu.trove.TDoubleArrayList(); |
|
146 for (final String value : wqSingles.split(" ")) { |
|
147 try { |
|
148 |
|
149 doubles.add(Double.parseDouble(value));// Punkt/komma? |
|
150 } |
|
151 catch (final NumberFormatException e) { |
|
152 /* Client should prevent this */ |
|
153 log.warn("Invalid wqsingle value: " + value); |
|
154 continue; |
|
155 } |
|
156 } |
|
157 return doubles.toNativeArray(); |
|
158 } |
|
159 |
|
160 } |