Mercurial > dive4elements > river
annotate 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 |
rev | line source |
---|---|
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5867
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5994
af13ceeba52a
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5867
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5863
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
4897a58c8746
River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4949
diff
changeset
|
9 package org.dive4elements.river.artifacts.states; |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
9102 | 11 import org.apache.log4j.Logger; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4949
diff
changeset
|
12 import org.dive4elements.artifacts.Artifact; |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
13 import org.dive4elements.river.artifacts.D4EArtifact; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4949
diff
changeset
|
14 import org.dive4elements.river.artifacts.access.RangeAccess; |
4949
53be73133104
Removed obsolete imports.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
15 |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
16 /** |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
17 * State in which km range is set. |
9102 | 18 * |
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 * @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
|
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 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
|
22 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
6101
diff
changeset
|
23 /** The log that is used in this class. */ |
9102 | 24 private final Logger log = 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
|
25 |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 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
|
27 } |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
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
|
29 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
|
30 |
9102 | 31 protected boolean validateBounds(final double fromValid, final double toValid, final double from, final double to) throws IllegalArgumentException { |
32 if (from < fromValid || from > toValid) { | |
33 this.log.error("Invalid 'from'. " + from + " is smaller than " + fromValid); | |
8776 | 34 // error message used in client to resolve i18n |
1630
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
35 throw new IllegalArgumentException("error_feed_from_out_of_range"); |
9102 | 36 } else if (to > toValid || to < fromValid) { |
37 this.log.error("Invalid 'to'. " + to + " is bigger than " + toValid); | |
8776 | 38 // error message used in client to resolve i18n |
1630
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
39 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
|
40 } |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
41 |
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
42 return true; |
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 |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 /** |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 * 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
|
47 * |
9102 | 48 * @param fromValid |
49 * Valid lower value of the range. | |
50 * @param toValid | |
51 * Valid upper value of the range. | |
52 * @param from | |
53 * The lower value. | |
54 * @param to | |
55 * The upper value. | |
56 * @param step | |
57 * The step width. | |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 * |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 * @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
|
60 */ |
9102 | 61 protected boolean validateBounds(final double fromValid, final double toValid, final double from, final double to, final double step) |
62 throws IllegalArgumentException { | |
63 this.log.debug("RangeState.validateRange"); | |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
64 |
1630
cafd8af6734a
Improved bounds validation for distance only states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
1051
diff
changeset
|
65 // 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
|
66 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
|
67 } |
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
|
68 |
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 @Override |
9102 | 70 public boolean validate(final Artifact artifact) throws IllegalArgumentException { |
71 final D4EArtifact flys = (D4EArtifact) 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
|
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 try { |
9102 | 74 final RangeAccess rangeAccess = new RangeAccess(flys); |
75 final double from = rangeAccess.getFrom(); | |
76 final double to = rangeAccess.getTo(); | |
77 final 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
|
78 |
9102 | 79 final double[] minmax = getMinMax(flys); |
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
|
80 |
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 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
|
82 } |
9102 | 83 catch (final NumberFormatException nfe) { |
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
|
84 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
|
85 } |
9102 | 86 catch (final NullPointerException npe) { |
4865
1358d0c8481c
RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
1685
diff
changeset
|
87 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
|
88 } |
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
|
89 } |
322
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 } |
448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |