Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeState.java @ 2696:1bc35de0b786
Improved the states for MINFO flow velocity calculation.
flys-artifacts/trunk@4406 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 15 May 2012 07:15:36 +0000 |
parents | |
children | 71f072d8b3d8 |
comparison
equal
deleted
inserted
replaced
2695:ae0742f92cd5 | 2696:1bc35de0b786 |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import de.intevation.artifacts.Artifact; | |
8 | |
9 import de.intevation.artifacts.common.model.KVP; | |
10 | |
11 import de.intevation.flys.model.DischargeZone; | |
12 import de.intevation.flys.model.River; | |
13 | |
14 import de.intevation.flys.artifacts.FLYSArtifact; | |
15 import de.intevation.flys.utils.FLYSUtils; | |
16 | |
17 | |
18 public class DischargeState extends MultiIntArrayState { | |
19 | |
20 public static final String MAIN_CHANNEL = "main.channel"; | |
21 public static final String TOTAL_CHANNEL = "total.channel"; | |
22 | |
23 | |
24 private static final Logger logger = Logger.getLogger(DischargeState.class); | |
25 | |
26 | |
27 @Override | |
28 public String getUIProvider() { | |
29 return "parameter-matrix"; | |
30 } | |
31 | |
32 | |
33 /** | |
34 * This method fetches all DischargeZones for a given river (extracted from | |
35 * <i>artifact</i>) and returns a KVP[] where the key is the ID of the | |
36 * DischargeZone and the value is a string that consists of lower discharge | |
37 * and upper discharge. | |
38 * | |
39 * @param artifact Needs to be a FLYSArtifact that provides river | |
40 * information. | |
41 * @param parameterName The name of a parameter. | |
42 * | |
43 * @return a KVP[]. | |
44 */ | |
45 @Override | |
46 protected KVP<Integer, String>[] getOptions( | |
47 Artifact artifact, | |
48 String parameterName | |
49 ) | |
50 throws IllegalArgumentException | |
51 { | |
52 if (!testParameterName(parameterName)) { | |
53 throw new IllegalArgumentException( | |
54 "Invalid parameter for state: '" + parameterName + "'"); | |
55 } | |
56 | |
57 List<DischargeZone> zones = getDischargeZones(artifact); | |
58 | |
59 KVP[] kvp = new KVP[zones.size()]; | |
60 | |
61 for (int i = 0; i < zones.size(); i++) { | |
62 DischargeZone zone = zones.get(i); | |
63 | |
64 String lower = zone.getLowerDischarge(); | |
65 String upper = zone.getUpperDischarge(); | |
66 | |
67 if (lower.equals(upper)) { | |
68 kvp[i] = new KVP(zone.getId(), lower); | |
69 } | |
70 else { | |
71 kvp[i] = new KVP(zone.getId(), lower + " - " + upper); | |
72 } | |
73 } | |
74 | |
75 return kvp; | |
76 } | |
77 | |
78 | |
79 /** | |
80 * This method might be used to test, if a parameter name is handled by this | |
81 * state. | |
82 * | |
83 * @param parameterName The name of a parameter. | |
84 * | |
85 * @return true, if parameterName is one of <i>MAIN_CHANNEL</i> or | |
86 * <i>TOTAL_CHANNEL</i>. Otherwise false. | |
87 */ | |
88 protected boolean testParameterName(String parameterName) { | |
89 if (parameterName == null || parameterName.length() == 0) { | |
90 return false; | |
91 } | |
92 else if (parameterName.equals(MAIN_CHANNEL)) { | |
93 return true; | |
94 } | |
95 else if (parameterName.equals(TOTAL_CHANNEL)) { | |
96 return true; | |
97 } | |
98 else { | |
99 return false; | |
100 } | |
101 } | |
102 | |
103 | |
104 /** | |
105 * Returns all discharge zones for a given river. The river information is | |
106 * extracted from <i>artifact</i> using FLYSUtils.getRiver(). | |
107 * | |
108 * @param artifact Needs to be a FLYSArtifact that stores a rivername. | |
109 * | |
110 * @return a list of DischargeZones. | |
111 * | |
112 * @throws IllegalArgumentException if no river information is provided by | |
113 * <i>artifact</i>. | |
114 */ | |
115 protected List<DischargeZone> getDischargeZones(Artifact artifact) | |
116 throws IllegalArgumentException | |
117 { | |
118 River river = FLYSUtils.getRiver((FLYSArtifact) artifact); | |
119 | |
120 if (river == null) { | |
121 throw new IllegalArgumentException("No river found"); | |
122 } | |
123 | |
124 List<DischargeZone> zones = DischargeZone.getDischargeZones(river); | |
125 | |
126 logger.debug("Found " + zones.size() + " DischargeZones."); | |
127 | |
128 return zones; | |
129 } | |
130 } | |
131 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |