Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java @ 921:610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
flys-artifacts/trunk@2270 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 30 Jun 2011 11:32:17 +0000 |
parents | acf3b49ec31f |
children | eccf966fb677 |
comparison
equal
deleted
inserted
replaced
920:a618dd6d80ea | 921:610d0e0f4f85 |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | 2 |
3 import org.apache.log4j.Logger; | 3 import org.apache.log4j.Logger; |
4 | |
5 import de.intevation.artifacts.Artifact; | |
6 import de.intevation.artifacts.CallContext; | |
7 | |
8 import de.intevation.artifactdatabase.data.StateData; | |
9 | |
10 import de.intevation.flys.artifacts.FLYSArtifact; | |
4 | 11 |
5 | 12 |
6 /** | 13 /** |
7 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
8 */ | 15 */ |
9 public abstract class RangeState extends DefaultState { | 16 public abstract class RangeState extends DefaultState { |
10 | 17 |
11 /** The logger that is used in this class.*/ | 18 /** The logger that is used in this class.*/ |
12 private static Logger logger = Logger.getLogger(RangeState.class); | 19 private Logger logger = Logger.getLogger(RangeState.class); |
13 | 20 |
14 | 21 |
15 public RangeState() { | 22 public RangeState() { |
16 } | 23 } |
24 | |
25 | |
26 protected abstract String getLowerField(); | |
27 protected abstract String getUpperField(); | |
28 protected abstract String getStepField(); | |
29 protected abstract double[] getMinMax(Artifact artifact); | |
17 | 30 |
18 | 31 |
19 /** | 32 /** |
20 * Validates a given range with a given valid range. | 33 * Validates a given range with a given valid range. |
21 * | 34 * |
42 else if (to > toValid) { | 55 else if (to > toValid) { |
43 logger.error( | 56 logger.error( |
44 "Invalid 'to'. " + to + " is bigger than " + toValid); | 57 "Invalid 'to'. " + to + " is bigger than " + toValid); |
45 throw new IllegalArgumentException("error_feed_to_out_of_range"); | 58 throw new IllegalArgumentException("error_feed_to_out_of_range"); |
46 } | 59 } |
47 /* | |
48 else if (from > to) { | |
49 throw new IllegalArgumentException("error_feed_from_bigger_to"); | |
50 } | |
51 */ | |
52 | 60 |
53 return true; | 61 return true; |
54 } | 62 } |
63 | |
64 | |
65 @Override | |
66 public boolean validate(Artifact artifact, CallContext context) | |
67 throws IllegalArgumentException | |
68 { | |
69 FLYSArtifact flys = (FLYSArtifact) artifact; | |
70 | |
71 StateData dFrom = getData(flys, getLowerField()); | |
72 StateData dTo = getData(flys, getUpperField()); | |
73 StateData dStep = getData(flys, getStepField()); | |
74 | |
75 String fromStr = dFrom != null ? (String) dFrom.getValue() : null; | |
76 String toStr = dTo != null ? (String) dTo.getValue() : null; | |
77 String stepStr = dStep != null ? (String) dStep.getValue() : null; | |
78 | |
79 if (fromStr == null || toStr == null || stepStr == null) { | |
80 throw new IllegalArgumentException("error_empty_state"); | |
81 } | |
82 | |
83 try { | |
84 double from = Double.parseDouble(fromStr); | |
85 double to = Double.parseDouble(toStr); | |
86 double step = Double.parseDouble(stepStr); | |
87 | |
88 double[] minmax = getMinMax(flys); | |
89 | |
90 return validateBounds(minmax[0], minmax[1], from, to, step); | |
91 } | |
92 catch (NumberFormatException nfe) { | |
93 throw new IllegalArgumentException("error_invalid_double_value"); | |
94 } | |
95 } | |
55 } | 96 } |
56 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 97 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |