Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/RangeState.java @ 9102:21e65960a9e3
fix-analysis distance range bugfix
author | gernotbelger |
---|---|
date | Mon, 28 May 2018 18:18:21 +0200 |
parents | 1116079e6624 |
children |
comparison
equal
deleted
inserted
replaced
9101:2c6aba003112 | 9102:21e65960a9e3 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.artifacts.states; | 9 package org.dive4elements.river.artifacts.states; |
10 | 10 |
11 import org.apache.log4j.Logger; | |
11 import org.dive4elements.artifacts.Artifact; | 12 import org.dive4elements.artifacts.Artifact; |
12 | |
13 import org.dive4elements.river.artifacts.D4EArtifact; | 13 import org.dive4elements.river.artifacts.D4EArtifact; |
14 | |
15 import org.dive4elements.river.artifacts.access.RangeAccess; | 14 import org.dive4elements.river.artifacts.access.RangeAccess; |
16 | |
17 import org.apache.log4j.Logger; | |
18 | |
19 | 15 |
20 /** | 16 /** |
21 * State in which km range is set. | 17 * State in which km range is set. |
18 * | |
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
23 */ | 20 */ |
24 public abstract class RangeState extends DefaultState { | 21 public abstract class RangeState extends DefaultState { |
25 | 22 |
26 /** The log that is used in this class. */ | 23 /** The log that is used in this class. */ |
27 private Logger log = Logger.getLogger(RangeState.class); | 24 private final Logger log = Logger.getLogger(RangeState.class); |
28 | |
29 | 25 |
30 public RangeState() { | 26 public RangeState() { |
31 } | 27 } |
32 | 28 |
33 protected abstract double[] getMinMax(Artifact artifact); | 29 protected abstract double[] getMinMax(Artifact artifact); |
34 | 30 |
35 | 31 protected boolean validateBounds(final double fromValid, final double toValid, final double from, final double to) throws IllegalArgumentException { |
36 protected boolean validateBounds( | 32 if (from < fromValid || from > toValid) { |
37 double fromValid, double toValid, | 33 this.log.error("Invalid 'from'. " + from + " is smaller than " + fromValid); |
38 double from, double to) | |
39 throws IllegalArgumentException | |
40 { | |
41 if (from < fromValid) { | |
42 log.error( | |
43 "Invalid 'from'. " + from + " is smaller than " + fromValid); | |
44 // error message used in client to resolve i18n | 34 // error message used in client to resolve i18n |
45 throw new IllegalArgumentException("error_feed_from_out_of_range"); | 35 throw new IllegalArgumentException("error_feed_from_out_of_range"); |
46 } | 36 } else if (to > toValid || to < fromValid) { |
47 else if (to > toValid) { | 37 this.log.error("Invalid 'to'. " + to + " is bigger than " + toValid); |
48 log.error( | |
49 "Invalid 'to'. " + to + " is bigger than " + toValid); | |
50 // error message used in client to resolve i18n | 38 // error message used in client to resolve i18n |
51 throw new IllegalArgumentException("error_feed_to_out_of_range"); | 39 throw new IllegalArgumentException("error_feed_to_out_of_range"); |
52 } | 40 } |
53 | 41 |
54 return true; | 42 return true; |
55 } | 43 } |
56 | 44 |
57 | |
58 /** | 45 /** |
59 * Validates a given range with a given valid range. | 46 * Validates a given range with a given valid range. |
60 * | 47 * |
61 * @param fromValid Valid lower value of the range. | 48 * @param fromValid |
62 * @param toValid Valid upper value of the range. | 49 * Valid lower value of the range. |
63 * @param from The lower value. | 50 * @param toValid |
64 * @param to The upper value. | 51 * Valid upper value of the range. |
65 * @param step The step width. | 52 * @param from |
53 * The lower value. | |
54 * @param to | |
55 * The upper value. | |
56 * @param step | |
57 * The step width. | |
66 * | 58 * |
67 * @return true, if everything was fine, otherwise an exception is thrown. | 59 * @return true, if everything was fine, otherwise an exception is thrown. |
68 */ | 60 */ |
69 protected boolean validateBounds( | 61 protected boolean validateBounds(final double fromValid, final double toValid, final double from, final double to, final double step) |
70 double fromValid, double toValid, | 62 throws IllegalArgumentException { |
71 double from, double to, double step) | 63 this.log.debug("RangeState.validateRange"); |
72 throws IllegalArgumentException | |
73 { | |
74 log.debug("RangeState.validateRange"); | |
75 | 64 |
76 // XXX The step width is not validated at the moment! | 65 // XXX The step width is not validated at the moment! |
77 return validateBounds(fromValid, toValid, from, to); | 66 return validateBounds(fromValid, toValid, from, to); |
78 } | 67 } |
79 | 68 |
80 | |
81 @Override | 69 @Override |
82 public boolean validate(Artifact artifact) | 70 public boolean validate(final Artifact artifact) throws IllegalArgumentException { |
83 throws IllegalArgumentException | 71 final D4EArtifact flys = (D4EArtifact) artifact; |
84 { | |
85 D4EArtifact flys = (D4EArtifact) artifact; | |
86 | 72 |
87 try { | 73 try { |
88 RangeAccess rangeAccess = new RangeAccess(flys); | 74 final RangeAccess rangeAccess = new RangeAccess(flys); |
89 double from = rangeAccess.getFrom(); | 75 final double from = rangeAccess.getFrom(); |
90 double to = rangeAccess.getTo(); | 76 final double to = rangeAccess.getTo(); |
91 double step = rangeAccess.getStep(); | 77 final double step = rangeAccess.getStep(); |
92 | 78 |
93 double[] minmax = getMinMax(flys); | 79 final double[] minmax = getMinMax(flys); |
94 | 80 |
95 return validateBounds(minmax[0], minmax[1], from, to, step); | 81 return validateBounds(minmax[0], minmax[1], from, to, step); |
96 } | 82 } |
97 catch (NumberFormatException nfe) { | 83 catch (final NumberFormatException nfe) { |
98 throw new IllegalArgumentException("error_invalid_double_value"); | 84 throw new IllegalArgumentException("error_invalid_double_value"); |
99 } | 85 } |
100 catch (NullPointerException npe) { | 86 catch (final NullPointerException npe) { |
101 throw new IllegalArgumentException("error_empty_state"); | 87 throw new IllegalArgumentException("error_empty_state"); |
102 } | 88 } |
103 } | 89 } |
104 } | 90 } |
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 91 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |