Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java @ 1630:cafd8af6734a
Improved bounds validation for distance only states.
flys-artifacts/trunk@2806 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 22 Sep 2011 07:58:24 +0000 |
parents | 9a77a9adbb36 |
children | 022f62c75878 |
comparison
equal
deleted
inserted
replaced
1629:4aec853a2f85 | 1630:cafd8af6734a |
---|---|
26 protected abstract String getUpperField(); | 26 protected abstract String getUpperField(); |
27 protected abstract String getStepField(); | 27 protected abstract String getStepField(); |
28 protected abstract double[] getMinMax(Artifact artifact); | 28 protected abstract double[] getMinMax(Artifact artifact); |
29 | 29 |
30 | 30 |
31 protected boolean validateBounds( | |
32 double fromValid, double toValid, | |
33 double from, double to) | |
34 throws IllegalArgumentException | |
35 { | |
36 if (from < fromValid) { | |
37 logger.error( | |
38 "Invalid 'from'. " + from + " is smaller than " + fromValid); | |
39 throw new IllegalArgumentException("error_feed_from_out_of_range"); | |
40 } | |
41 else if (to > toValid) { | |
42 logger.error( | |
43 "Invalid 'to'. " + to + " is bigger than " + toValid); | |
44 throw new IllegalArgumentException("error_feed_to_out_of_range"); | |
45 } | |
46 | |
47 return true; | |
48 } | |
49 | |
50 | |
31 /** | 51 /** |
32 * Validates a given range with a given valid range. | 52 * Validates a given range with a given valid range. |
33 * | 53 * |
34 * @param fromValid Valid lower value of the range. | 54 * @param fromValid Valid lower value of the range. |
35 * @param toValid Valid upper value of the range. | 55 * @param toValid Valid upper value of the range. |
44 double from, double to, double step) | 64 double from, double to, double step) |
45 throws IllegalArgumentException | 65 throws IllegalArgumentException |
46 { | 66 { |
47 logger.debug("RangeState.validateRange"); | 67 logger.debug("RangeState.validateRange"); |
48 | 68 |
49 if (from < fromValid) { | 69 // XXX The step width is not validated at the moment! |
50 logger.error( | 70 return validateBounds(fromValid, toValid, from, to); |
51 "Invalid 'from'. " + from + " is smaller than " + fromValid); | |
52 throw new IllegalArgumentException("error_feed_from_out_of_range"); | |
53 } | |
54 else if (to > toValid) { | |
55 logger.error( | |
56 "Invalid 'to'. " + to + " is bigger than " + toValid); | |
57 throw new IllegalArgumentException("error_feed_to_out_of_range"); | |
58 } | |
59 | |
60 return true; | |
61 } | 71 } |
62 | 72 |
63 | 73 |
64 @Override | 74 @Override |
65 public boolean validate(Artifact artifact) | 75 public boolean validate(Artifact artifact) |