comparison flys-artifacts/src/main/java/de/intevation/flys/utils/FLYSUtils.java @ 1740:8d08f6641372

Improved the title creation of WSP Q and W facets - named main values are taken into account while title creation. flys-artifacts/trunk@3031 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Wed, 19 Oct 2011 14:00:36 +0000
parents f58be0d661b9
children a8aa343799a2
comparison
equal deleted inserted replaced
1739:980d880c583c 1740:8d08f6641372
1 package de.intevation.flys.utils; 1 package de.intevation.flys.utils;
2 2
3 import org.apache.log4j.Logger; 3 import org.apache.log4j.Logger;
4 4
5 import java.text.NumberFormat;
5 import java.util.HashMap; 6 import java.util.HashMap;
7 import java.util.List;
6 import java.util.Map; 8 import java.util.Map;
7 9
8 import javax.xml.xpath.XPathConstants; 10 import javax.xml.xpath.XPathConstants;
9 11
10 import org.w3c.dom.Document; 12 import org.w3c.dom.Document;
16 18
17 import de.intevation.artifacts.common.utils.Config; 19 import de.intevation.artifacts.common.utils.Config;
18 import de.intevation.artifacts.common.utils.XMLUtils; 20 import de.intevation.artifacts.common.utils.XMLUtils;
19 21
20 import de.intevation.flys.artifacts.FLYSArtifact; 22 import de.intevation.flys.artifacts.FLYSArtifact;
23 import de.intevation.flys.artifacts.WINFOArtifact;
21 import de.intevation.flys.artifacts.model.RiverFactory; 24 import de.intevation.flys.artifacts.model.RiverFactory;
25 import de.intevation.flys.model.Gauge;
26 import de.intevation.flys.model.MainValue;
22 import de.intevation.flys.model.River; 27 import de.intevation.flys.model.River;
23 28
24 public class FLYSUtils { 29 public class FLYSUtils {
25 30
26 /** The logger that is used in this utility. */ 31 /** The logger that is used in this utility. */
221 XPATH_RIVER_PROJECTION, 226 XPATH_RIVER_PROJECTION,
222 XPathConstants.STRING, 227 XPathConstants.STRING,
223 null, 228 null,
224 variables); 229 variables);
225 } 230 }
231
232
233 public static String createWspWTitle(
234 WINFOArtifact winfo,
235 CallContext cc,
236 String name
237 ) {
238 String[] parts = name.split("=");
239
240 NumberFormat nf = Formatter.getWaterlevelW(cc);
241
242 String namedMainValue = null;
243
244 boolean isQ = winfo.isQ();
245 boolean isFree = winfo.isFreeQ();
246
247 double v;
248
249 try {
250 v = Double.valueOf(parts[1]);
251
252 namedMainValue = getNamedMainValue(winfo.getGauge(), v);
253 }
254 catch (NumberFormatException nfe) {
255 logger.warn("Cannot parse Double of: '" + parts[1] + "'");
256 return name;
257 }
258
259 String prefix = null;
260
261 if (isQ && !isFree && namedMainValue != null) {
262 return "W (" + namedMainValue + ")";
263 }
264
265 if (isQ) {
266 prefix = "Q=";
267 }
268
269 return prefix == null
270 ? "W(" + nf.format(v) + ")"
271 : "W(" + prefix + nf.format(v) + ")";
272 }
273
274
275 public static String createWspQTitle(
276 WINFOArtifact winfo,
277 CallContext cc,
278 String name
279 ) {
280 String[] parts = name.split("=");
281
282 NumberFormat nf = Formatter.getWaterlevelQ(cc);
283
284 String namedMainValue = null;
285
286 boolean isQ = winfo.isQ();
287 boolean isFree = winfo.isFreeQ();
288
289 double v;
290
291 try {
292 v = Double.valueOf(parts[1]);
293
294 namedMainValue = getNamedMainValue(winfo.getGauge(), v);
295 }
296 catch (NumberFormatException nfe) {
297 logger.warn("Cannot parse Double of: '" + parts[1] + "'");
298 return name;
299 }
300
301 String prefix = null;
302
303 if (isQ && !isFree && namedMainValue != null) {
304 return namedMainValue;
305 }
306
307 if (!isQ) {
308 prefix = "W=";
309 }
310
311 return prefix == null
312 ? "Q(" + nf.format(v) + ")"
313 : "Q(" + prefix + nf.format(v) + ")";
314 }
315
316
317 public static String getNamedMainValue(Gauge gauge, double value) {
318 List<MainValue> mainValues = gauge.getMainValues();
319 logger.debug("Search named main value for: " + value);
320
321 for (MainValue mv: mainValues) {
322 if (mv.getValue().doubleValue() == value) {
323 logger.debug("Found named main value: " + mv.getMainValue().getName());
324 return mv.getMainValue().getName();
325 }
326 }
327
328 logger.debug("Did not find a named main value for: " + value);
329 return null;
330 }
226 } 331 }
227 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 332 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org