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