annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java @ 4867:c4973fa23674

DatacageButton: doc.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 25 Jan 2013 16:32:21 +0100
parents 1358d0c8481c
children 53be73133104
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
4865
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1685
diff changeset
9 import de.intevation.flys.artifacts.access.RangeAccess;
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 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
11
322
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 /**
4865
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1685
diff changeset
14 * 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
15 * @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
16 */
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 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
18
1685
022f62c75878 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1630
diff changeset
19 /** 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
20 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
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
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 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
24 }
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25
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
26 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
27
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
1630
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
29 protected boolean validateBounds(
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
30 double fromValid, double toValid,
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
31 double from, double to)
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
32 throws IllegalArgumentException
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
33 {
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
34 if (from < fromValid) {
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
35 logger.error(
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
36 "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
37 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
38 }
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
39 else if (to > toValid) {
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
40 logger.error(
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
41 "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
42 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
43 }
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
44
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
45 return true;
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
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
48
322
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 /**
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 * 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
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 * @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
53 * @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
54 * @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
55 * @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
56 * @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
57 *
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 * @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
59 */
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
60 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
61 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
62 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
63 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
64 {
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 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
66
1630
cafd8af6734a Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1051
diff changeset
67 // 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
68 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
69 }
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
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
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 @Override
1050
eccf966fb677 State engine: Removed CallContext from state validation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 921
diff changeset
73 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
74 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
75 {
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 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
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 try {
4865
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1685
diff changeset
79 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
80 double from = rangeAccess.getFrom();
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1685
diff changeset
81 double to = rangeAccess.getTo();
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1685
diff changeset
82 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
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 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
85
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 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
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 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
89 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
90 }
4865
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1685
diff changeset
91 catch (NullPointerException npe) {
1358d0c8481c RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1685
diff changeset
92 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
93 }
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
94 }
322
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 }
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org