Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultArtifactDescription.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/shared/model/DefaultArtifactDescription.java@821a02bbfb4e |
children | 172338b1407f |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.client.shared.model; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.dive4elements.river.client.shared.DoubleUtils; | |
6 | |
7 | |
8 /** | |
9 * The default implementation of an {@link ArtifactDescription}. This class just | |
10 * implements constructors to create new instances and the necessary methods of | |
11 * the interface. | |
12 * | |
13 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
14 */ | |
15 public class DefaultArtifactDescription implements ArtifactDescription { | |
16 | |
17 /** Data that have been inserted in former states.*/ | |
18 protected DataList[] oldData; | |
19 | |
20 /** The Data that is allowed to be inserted in the current state.*/ | |
21 protected DataList currentData; | |
22 | |
23 /** The current state name.*/ | |
24 protected String currentState; | |
25 | |
26 /** The names of reachable states.*/ | |
27 protected String[] reachableStates; | |
28 | |
29 /** The output modes of this state.*/ | |
30 protected OutputMode[] outputModes; | |
31 | |
32 /** A list of recommendations suggested by the server.*/ | |
33 protected Recommendation[] recommendations; | |
34 | |
35 | |
36 public DefaultArtifactDescription() { | |
37 } | |
38 | |
39 | |
40 /** | |
41 * The default constructor. | |
42 * | |
43 * @param old The data that have been inserted in former states. | |
44 * @param current The data that might be inserted in the current state. | |
45 * @param state The name of the current state. | |
46 * @param reachableStates The names of the reachable states. | |
47 */ | |
48 public DefaultArtifactDescription( | |
49 DataList[] old, | |
50 DataList current, | |
51 String state, | |
52 String[] reachableStates) | |
53 { | |
54 this.oldData = old; | |
55 this.currentData = current; | |
56 this.currentState = state; | |
57 this.reachableStates = reachableStates; | |
58 } | |
59 | |
60 | |
61 /** | |
62 * The default constructor. | |
63 * | |
64 * @param old The data that have been inserted in former states. | |
65 * @param current The data that might be inserted in the current state. | |
66 * @param state The name of the current state. | |
67 * @param reachableStates The names of the reachable states. | |
68 * @param outputModes The available output modes of this artifact. | |
69 */ | |
70 public DefaultArtifactDescription( | |
71 DataList[] old, | |
72 DataList current, | |
73 String state, | |
74 String[] reachableStates, | |
75 OutputMode[] outputModes, | |
76 Recommendation[] recommendations) | |
77 { | |
78 this(old, current, state, reachableStates); | |
79 this.outputModes = outputModes; | |
80 this.recommendations = recommendations; | |
81 } | |
82 | |
83 | |
84 public DataList[] getOldData() { | |
85 return oldData; | |
86 } | |
87 | |
88 | |
89 public DataList getCurrentData() { | |
90 return currentData; | |
91 } | |
92 | |
93 | |
94 public String getCurrentState() { | |
95 return currentState; | |
96 } | |
97 | |
98 | |
99 public String[] getReachableStates() { | |
100 return reachableStates; | |
101 } | |
102 | |
103 | |
104 public OutputMode[] getOutputModes() { | |
105 return outputModes; | |
106 } | |
107 | |
108 | |
109 public Recommendation[] getRecommendations() { | |
110 return recommendations; | |
111 } | |
112 | |
113 | |
114 public String getRiver() { | |
115 return getDataValueAsString("river"); | |
116 } | |
117 | |
118 | |
119 /** Get [min,max] of data items. */ | |
120 public double[] getKMRange() { | |
121 Double[] mm = new Double[2]; | |
122 | |
123 for (DataList list: oldData) { | |
124 List<Data> dataList = list.getAll(); | |
125 | |
126 for (Data data: dataList) { | |
127 String dataName = data.getLabel(); | |
128 DataItem item = data.getItems()[0]; | |
129 | |
130 if (dataName.equals("ld_from") || dataName.equals("from")) { | |
131 Double d = DoubleUtils.getDouble(item.getStringValue()); | |
132 | |
133 if (d != null) { | |
134 mm[0] = d; | |
135 } | |
136 } | |
137 else if (dataName.equals("ld_to") || dataName.equals("to")) { | |
138 Double d = DoubleUtils.getDouble(item.getStringValue()); | |
139 | |
140 if (d != null) { | |
141 mm[1] = d; | |
142 } | |
143 } | |
144 else if (dataName.equals("ld_locations")) { | |
145 return DoubleUtils.getMinMax(item.getStringValue()); | |
146 } | |
147 } | |
148 | |
149 if (mm[0] != null && mm[1] != null) { | |
150 return new double[] { mm[0], mm[1] }; | |
151 } | |
152 } | |
153 | |
154 return null; | |
155 } | |
156 | |
157 | |
158 public String getReferenceGauge() { | |
159 return getDataValueAsString("reference_gauge"); | |
160 } | |
161 | |
162 | |
163 public String getDataValueAsString(String name) { | |
164 if (oldData == null) { | |
165 return null; | |
166 } | |
167 for (DataList list: oldData) { | |
168 List<Data> dataList = list.getAll(); | |
169 | |
170 for (Data d: dataList) { | |
171 String dataName = d.getLabel(); | |
172 DataItem item = d.getItems()[0]; | |
173 | |
174 if (dataName.equals(name)) { | |
175 return item.getStringValue(); | |
176 } | |
177 } | |
178 } | |
179 | |
180 return null; | |
181 } | |
182 } | |
183 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |