Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java @ 1767:b2730e31ff5b
Store Facets without association to state id.
flys-artifacts/trunk@3088 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 26 Oct 2011 12:45:34 +0000 |
parents | 022f62c75878 |
children | 1358d0c8481c |
rev | line source |
---|---|
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.states; |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import org.apache.log4j.Logger; |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
5 import de.intevation.artifacts.Artifact; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
6 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
7 import de.intevation.artifactdatabase.data.StateData; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
8 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
9 import de.intevation.flys.artifacts.FLYSArtifact; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
10 |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 /** |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 */ |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 public abstract class RangeState extends DefaultState { |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 |
1685
022f62c75878
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1630
diff
changeset
|
17 /** The logger that is used in this class. */ |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
18 private Logger logger = Logger.getLogger(RangeState.class); |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 public RangeState() { |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 } |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
25 protected abstract String getLowerField(); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
26 protected abstract String getUpperField(); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
27 protected abstract String getStepField(); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
28 protected abstract double[] getMinMax(Artifact artifact); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
29 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
30 |
1630
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
31 protected boolean validateBounds( |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
32 double fromValid, double toValid, |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
33 double from, double to) |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
34 throws IllegalArgumentException |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
35 { |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
36 if (from < fromValid) { |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
37 logger.error( |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
38 "Invalid 'from'. " + from + " is smaller than " + fromValid); |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
39 throw new IllegalArgumentException("error_feed_from_out_of_range"); |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
40 } |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
41 else if (to > toValid) { |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
42 logger.error( |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
43 "Invalid 'to'. " + to + " is bigger than " + toValid); |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
44 throw new IllegalArgumentException("error_feed_to_out_of_range"); |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
45 } |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
46 |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
47 return true; |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
48 } |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
49 |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
50 |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 /** |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 * Validates a given range with a given valid range. |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 * |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 * @param fromValid Valid lower value of the range. |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 * @param toValid Valid upper value of the range. |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 * @param from The lower value. |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 * @param to The upper value. |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 * @param step The step width. |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 * |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 * @return true, if everything was fine, otherwise an exception is thrown. |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 */ |
379
c21fb8de54f8
Enabled the FLYSArtifact to handle an array of inserted WQ values (without given ranges).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
322
diff
changeset
|
62 protected boolean validateBounds( |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
63 double fromValid, double toValid, |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 double from, double to, double step) |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
65 throws IllegalArgumentException |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
66 { |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
67 logger.debug("RangeState.validateRange"); |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
68 |
1630
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
69 // XXX The step width is not validated at the moment! |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
70 return validateBounds(fromValid, toValid, from, to); |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
71 } |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
72 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
73 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
74 @Override |
1050
eccf966fb677
State engine: Removed CallContext from state validation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
921
diff
changeset
|
75 public boolean validate(Artifact artifact) |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
76 throws IllegalArgumentException |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
77 { |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
78 FLYSArtifact flys = (FLYSArtifact) artifact; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
79 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
80 StateData dFrom = getData(flys, getLowerField()); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
81 StateData dTo = getData(flys, getUpperField()); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
82 StateData dStep = getData(flys, getStepField()); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
83 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
84 String fromStr = dFrom != null ? (String) dFrom.getValue() : null; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
85 String toStr = dTo != null ? (String) dTo.getValue() : null; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
86 String stepStr = dStep != null ? (String) dStep.getValue() : null; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
87 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
88 if (fromStr == null || toStr == null || stepStr == null) { |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
89 throw new IllegalArgumentException("error_empty_state"); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
90 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
91 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
92 try { |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
93 double from = Double.parseDouble(fromStr); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
94 double to = Double.parseDouble(toStr); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
95 double step = Double.parseDouble(stepStr); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
96 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
97 double[] minmax = getMinMax(flys); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
98 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
99 return validateBounds(minmax[0], minmax[1], from, to, step); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
100 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
101 catch (NumberFormatException nfe) { |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
102 throw new IllegalArgumentException("error_invalid_double_value"); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
103 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
635
diff
changeset
|
104 } |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 } |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |