annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/LocationSelect.java @ 9584:1a7cfeb1ff89

Punkt 10.8 WQ-Vorschau
author gernotbelger
date Wed, 09 Jan 2019 17:13:25 +0100
parents e4606eae8ea5
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3284
diff changeset
9 package org.dive4elements.river.artifacts.states;
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import org.apache.log4j.Logger;
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
12 import org.dive4elements.artifactdatabase.data.StateData;
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
13 import org.dive4elements.artifacts.Artifact;
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
14 import org.dive4elements.artifacts.CallContext;
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
15 import org.dive4elements.artifacts.common.utils.XMLUtils;
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
16 import org.dive4elements.river.artifacts.D4EArtifact;
679
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
17 import org.w3c.dom.Element;
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
18
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
19 import gnu.trove.TDoubleArrayList;
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 /**
3284
d9af29a4bb85 Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2235
diff changeset
22 * This state is used to realize the input of multiple locations as string.
d9af29a4bb85 Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2235
diff changeset
23 *
d9af29a4bb85 Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2235
diff changeset
24 * The string should be a whitespace separated list of double values where each
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 * double value represents a location.
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 *
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 */
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 public class LocationSelect extends LocationDistanceSelect {
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
31 private static final long serialVersionUID = 1L;
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
32 /** The log used in this class. */
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
33 private static Logger log = Logger.getLogger(LocationSelect.class);
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public LocationSelect() {
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 }
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
3284
d9af29a4bb85 Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2235
diff changeset
38 /** UI Provider (which input method should the client provide to user. */
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 @Override
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 protected String getUIProvider() {
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 return "location_panel";
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 }
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 @Override
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
45 protected Element[] createItems(final XMLUtils.ElementCreator cr, final Artifact artifact, final String name, final CallContext context) {
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
46 final double[] minmax = getMinMax(artifact);
679
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
47
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
48 double minVal = Double.MIN_VALUE;
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
49 double maxVal = Double.MAX_VALUE;
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
50
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
51 if (minmax != null) {
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
52 minVal = minmax[0];
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
53 maxVal = minmax[1];
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
54 } else {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
55 log.warn("Could not read min/max distance values!");
679
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
56 }
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
57
2235
ee5310134463 Cosmetics/care/refac.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2223
diff changeset
58 if (name.equals(LOCATIONS)) {
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
59 final Element min = createItem(cr, new String[] { "min", new Double(minVal).toString() });
679
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
60
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
61 final Element max = createItem(cr, new String[] { "max", new Double(maxVal).toString() });
679
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
62
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
63 return new Element[] { min, max };
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
64 }
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
65
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
66 return null;
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
67 }
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
68
3284
d9af29a4bb85 Various cosmetic doc fixes.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2235
diff changeset
69 /** Validates data from artifact. */
679
9a035ef7b595 The state that is used to enter locations writes the river's range into the DESCRIBE now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
70 @Override
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
71 public boolean validate(final Artifact artifact) throws IllegalArgumentException {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
72 log.debug("LocationSelect.validate");
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
74 final D4EArtifact flys = (D4EArtifact) artifact;
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
75 final StateData data = getData(flys, LOCATIONS);
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
77 final String locationStr = data != null ? (String) data.getValue() : null;
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 if (locationStr == null || locationStr.length() == 0) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
80 log.error("No locations given.");
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 throw new IllegalArgumentException("error_empty_state");
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 }
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
84 final double[] minmax = getMinMax(artifact);
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
85 final double[] mm = extractLocations(locationStr);
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
87 log.debug("Inserted min location: " + mm[0]);
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
88 log.debug("Inserted max location: " + mm[mm.length - 1]);
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
90 return validateBounds(minmax[0], minmax[1], mm[0], mm[mm.length - 1], 0d);
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 }
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 /**
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 * This method takes a string that consist of whitespace separated double
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 * values and returns the double values as array.
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 *
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
97 * @param locationStr
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
98 * The locations inserted in this state.
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 *
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 * @return the locations as array.
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 */
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
102 protected double[] extractLocations(final String locationStr) {
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
103 final String[] tmp = locationStr.split(" ");
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
104 final TDoubleArrayList locations = new TDoubleArrayList();
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
106 for (final String l : tmp) {
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 try {
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 locations.add(Double.parseDouble(l));
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 }
9584
1a7cfeb1ff89 Punkt 10.8 WQ-Vorschau
gernotbelger
parents: 8202
diff changeset
110 catch (final NumberFormatException nfe) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
111 log.warn(nfe, nfe);
383
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 }
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 }
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 locations.sort();
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 return locations.toNativeArray();
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 }
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 }
dcc3cd962c0e Enhanced the transition model to reach a state that creates duration curves.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org