Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java @ 5324:807fa01b498b
SCHEMA CHANGE: added spatial indices in Oracle that work again
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Fri, 15 Mar 2013 19:00:49 +0100 |
parents | 53be73133104 |
children |
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 |
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
|
3 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
|
4 |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
5 import de.intevation.flys.artifacts.FLYSArtifact; |
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
|
6 |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
7 import de.intevation.flys.artifacts.access.RangeAccess; |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
8 |
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
9 import org.apache.log4j.Logger; |
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
|
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 /** |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
13 * State in which km range is set. |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 * @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
|
15 */ |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 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
|
17 |
1685
022f62c75878
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1630
diff
changeset
|
18 /** 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
|
19 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
|
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 |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 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
|
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 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
|
26 |
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 |
1630
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
28 protected boolean validateBounds( |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
29 double fromValid, double toValid, |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
30 double from, double to) |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
31 throws IllegalArgumentException |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
32 { |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
33 if (from < fromValid) { |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
34 logger.error( |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
35 "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
|
36 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
|
37 } |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
38 else if (to > toValid) { |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
39 logger.error( |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
40 "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
|
41 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
|
42 } |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
43 |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
44 return true; |
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 |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 /** |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 * 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
|
50 * |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 * @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
|
52 * @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
|
53 * @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
|
54 * @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
|
55 * @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
|
56 * |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 * @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
|
58 */ |
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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 { |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 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
|
65 |
1630
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
66 // 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
|
67 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
|
68 } |
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
|
69 |
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
|
70 |
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
|
71 @Override |
1050
eccf966fb677
State engine: Removed CallContext from state validation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
921
diff
changeset
|
72 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
|
73 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
|
74 { |
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
|
75 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
|
76 |
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 try { |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
78 RangeAccess rangeAccess = new RangeAccess(flys, null); |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
79 double from = rangeAccess.getFrom(); |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
80 double to = rangeAccess.getTo(); |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
81 double step = rangeAccess.getStep(); |
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
|
82 |
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 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
|
84 |
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 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
|
86 } |
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 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
|
88 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
|
89 } |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
90 catch (NullPointerException npe) { |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
91 throw new IllegalArgumentException("error_empty_state"); |
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
92 } |
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
|
93 } |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 } |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |