Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/utils/RiverUtils.java @ 9761:c088f7a5797d 3.2.x
Reduce code duplication
RiverUtils.getValueFromWQ(wq) was equivalent to wq.getRawValue().
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 10 Nov 2022 18:16:25 +0100 |
parents | a83029cc7e6a |
children |
comparison
equal
deleted
inserted
replaced
9760:9bbb29142ddb | 9761:c088f7a5797d |
---|---|
18 import org.dive4elements.river.artifacts.access.RangeAccess; | 18 import org.dive4elements.river.artifacts.access.RangeAccess; |
19 import org.dive4elements.river.artifacts.context.RiverContext; | 19 import org.dive4elements.river.artifacts.context.RiverContext; |
20 import org.dive4elements.river.artifacts.model.LocationProvider; | 20 import org.dive4elements.river.artifacts.model.LocationProvider; |
21 import org.dive4elements.river.artifacts.model.RiverFactory; | 21 import org.dive4elements.river.artifacts.model.RiverFactory; |
22 import org.dive4elements.river.artifacts.model.WKms; | 22 import org.dive4elements.river.artifacts.model.WKms; |
23 import org.dive4elements.river.artifacts.model.WQ; | |
24 import org.dive4elements.river.artifacts.states.WDifferencesState; | 23 import org.dive4elements.river.artifacts.states.WDifferencesState; |
25 import org.dive4elements.river.artifacts.states.WaterlevelSelectState; | 24 import org.dive4elements.river.artifacts.states.WaterlevelSelectState; |
26 import org.dive4elements.river.backend.SessionFactoryProvider; | 25 import org.dive4elements.river.backend.SessionFactoryProvider; |
27 import org.dive4elements.river.model.Gauge; | 26 import org.dive4elements.river.model.Gauge; |
28 import org.dive4elements.river.model.MainValue; | 27 import org.dive4elements.river.model.MainValue; |
36 | 35 |
37 import java.text.NumberFormat; | 36 import java.text.NumberFormat; |
38 import java.util.HashMap; | 37 import java.util.HashMap; |
39 import java.util.List; | 38 import java.util.List; |
40 import java.util.Map; | 39 import java.util.Map; |
41 import java.util.regex.Matcher; | |
42 import java.util.regex.Pattern; | |
43 | 40 |
44 import javax.xml.xpath.XPathConstants; | 41 import javax.xml.xpath.XPathConstants; |
45 | 42 |
46 import org.apache.logging.log4j.Logger; | 43 import org.apache.logging.log4j.Logger; |
47 import org.apache.logging.log4j.LogManager; | 44 import org.apache.logging.log4j.LogManager; |
79 * An enum that represents the 4 possible WQ input modes in FLYS. The 4 | 76 * An enum that represents the 4 possible WQ input modes in FLYS. The 4 |
80 * values are | 77 * values are |
81 * <i>ADAPTED</i> <i>SINGLE</i> <i>RANGE</i> and <i>NONE</i>. | 78 * <i>ADAPTED</i> <i>SINGLE</i> <i>RANGE</i> and <i>NONE</i>. |
82 */ | 79 */ |
83 public static enum WQ_INPUT { ADAPTED, SINGLE, RANGE, NONE }; | 80 public static enum WQ_INPUT { ADAPTED, SINGLE, RANGE, NONE }; |
84 | |
85 public static final Pattern NUMBERS_PATTERN = | |
86 Pattern.compile("\\D*(\\d++.\\d*)\\D*"); | |
87 | 81 |
88 public static final String XPATH_FLOODMAP_RIVER_PROJECTION = | 82 public static final String XPATH_FLOODMAP_RIVER_PROJECTION = |
89 "/artifact-database/floodmap/river[@name=$name]/srid/@value"; | 83 "/artifact-database/floodmap/river[@name=$name]/srid/@value"; |
90 | 84 |
91 public static final String XPATH_MAPSERVER_URL = | 85 public static final String XPATH_MAPSERVER_URL = |
443 Gauge refGauge = getReferenceGauge(flys); | 437 Gauge refGauge = getReferenceGauge(flys); |
444 | 438 |
445 return refGauge != null | 439 return refGauge != null |
446 ? refGauge.getName() | 440 ? refGauge.getName() |
447 : "-- not found --"; | 441 : "-- not found --"; |
448 } | |
449 | |
450 | |
451 public static Double getValueFromWQ(WQ wq) { | |
452 if (wq == null) { | |
453 return null; | |
454 } | |
455 | |
456 Matcher m = NUMBERS_PATTERN.matcher(wq.getName()); | |
457 | |
458 if (m.matches()) { | |
459 log.debug("Found a number."); | |
460 | |
461 String raw = m.group(1); | |
462 | |
463 try { | |
464 return Double.valueOf(raw); | |
465 } | |
466 catch (NumberFormatException nfe) { | |
467 } | |
468 } | |
469 | |
470 return null; | |
471 } | 442 } |
472 | 443 |
473 | 444 |
474 /** Creates human-readable name for a wsp (waterlevel/longitudinal section). | 445 /** Creates human-readable name for a wsp (waterlevel/longitudinal section). |
475 * @param name will be split at '='s. | 446 * @param name will be split at '='s. |