comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RangeState.java @ 4865:1358d0c8481c

RangeState and descendants: Use RangeAccess, resolve direct ld_* usage.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 24 Jan 2013 16:09:46 +0100
parents 022f62c75878
children 53be73133104
comparison
equal deleted inserted replaced
4864:dc0d37715e16 4865:1358d0c8481c
4 4
5 import de.intevation.artifacts.Artifact; 5 import de.intevation.artifacts.Artifact;
6 6
7 import de.intevation.artifactdatabase.data.StateData; 7 import de.intevation.artifactdatabase.data.StateData;
8 8
9 import de.intevation.flys.artifacts.access.RangeAccess;
9 import de.intevation.flys.artifacts.FLYSArtifact; 10 import de.intevation.flys.artifacts.FLYSArtifact;
10 11
11 12
12 /** 13 /**
14 * State in which km range is set.
13 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
14 */ 16 */
15 public abstract class RangeState extends DefaultState { 17 public abstract class RangeState extends DefaultState {
16 18
17 /** The logger that is used in this class. */ 19 /** The logger that is used in this class. */
19 21
20 22
21 public RangeState() { 23 public RangeState() {
22 } 24 }
23 25
24
25 protected abstract String getLowerField();
26 protected abstract String getUpperField();
27 protected abstract String getStepField();
28 protected abstract double[] getMinMax(Artifact artifact); 26 protected abstract double[] getMinMax(Artifact artifact);
29 27
30 28
31 protected boolean validateBounds( 29 protected boolean validateBounds(
32 double fromValid, double toValid, 30 double fromValid, double toValid,
75 public boolean validate(Artifact artifact) 73 public boolean validate(Artifact artifact)
76 throws IllegalArgumentException 74 throws IllegalArgumentException
77 { 75 {
78 FLYSArtifact flys = (FLYSArtifact) artifact; 76 FLYSArtifact flys = (FLYSArtifact) artifact;
79 77
80 StateData dFrom = getData(flys, getLowerField());
81 StateData dTo = getData(flys, getUpperField());
82 StateData dStep = getData(flys, getStepField());
83
84 String fromStr = dFrom != null ? (String) dFrom.getValue() : null;
85 String toStr = dTo != null ? (String) dTo.getValue() : null;
86 String stepStr = dStep != null ? (String) dStep.getValue() : null;
87
88 if (fromStr == null || toStr == null || stepStr == null) {
89 throw new IllegalArgumentException("error_empty_state");
90 }
91
92 try { 78 try {
93 double from = Double.parseDouble(fromStr); 79 RangeAccess rangeAccess = new RangeAccess(flys, null);
94 double to = Double.parseDouble(toStr); 80 double from = rangeAccess.getFrom();
95 double step = Double.parseDouble(stepStr); 81 double to = rangeAccess.getTo();
82 double step = rangeAccess.getStep();
96 83
97 double[] minmax = getMinMax(flys); 84 double[] minmax = getMinMax(flys);
98 85
99 return validateBounds(minmax[0], minmax[1], from, to, step); 86 return validateBounds(minmax[0], minmax[1], from, to, step);
100 } 87 }
101 catch (NumberFormatException nfe) { 88 catch (NumberFormatException nfe) {
102 throw new IllegalArgumentException("error_invalid_double_value"); 89 throw new IllegalArgumentException("error_invalid_double_value");
103 } 90 }
91 catch (NullPointerException npe) {
92 throw new IllegalArgumentException("error_empty_state");
93 }
104 } 94 }
105 } 95 }
106 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 96 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org