Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DistanceOnlySelect.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 | cafd8af6734a |
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 public class DistanceOnlySelect extends DistanceSelect { | 13 public class DistanceOnlySelect extends DistanceSelect { |
13 | 14 |
21 | 22 |
22 @Override | 23 @Override |
23 public boolean validate(Artifact artifact) | 24 public boolean validate(Artifact artifact) |
24 throws IllegalArgumentException | 25 throws IllegalArgumentException |
25 { | 26 { |
27 // TODO think about better hierarchy wrt RangeState#validate. | |
26 FLYSArtifact flys = (FLYSArtifact) artifact; | 28 FLYSArtifact flys = (FLYSArtifact) artifact; |
27 | 29 |
28 StateData dFrom = getData(flys, getLowerField()); | |
29 StateData dTo = getData(flys, getUpperField()); | |
30 | |
31 String fromStr = dFrom != null ? (String) dFrom.getValue() : null; | |
32 String toStr = dTo != null ? (String) dTo.getValue() : null; | |
33 | |
34 if (fromStr == null || toStr == null) { | |
35 throw new IllegalArgumentException("error_empty_state"); | |
36 } | |
37 | |
38 try { | 30 try { |
39 double from = Double.parseDouble(fromStr); | 31 RangeAccess rangeAccess = new RangeAccess(flys, null); |
40 double to = Double.parseDouble(toStr); | 32 double from = rangeAccess.getFrom(); |
33 double to = rangeAccess.getTo(); | |
41 | 34 |
42 double[] minmax = getMinMax(flys); | 35 double[] minmax = getMinMax(flys); |
43 | 36 |
44 return validateBounds(minmax[0], minmax[1], from, to); | 37 return validateBounds(minmax[0], minmax[1], from, to); |
45 } | 38 } |
46 catch (NumberFormatException nfe) { | 39 catch (NumberFormatException nfe) { |
47 throw new IllegalArgumentException("error_invalid_double_value"); | 40 throw new IllegalArgumentException("error_invalid_double_value"); |
48 } | 41 } |
42 catch (NullPointerException npe) { | |
43 throw new IllegalArgumentException("error_empty_state"); | |
44 } | |
49 } | 45 } |
50 } | 46 } |
51 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 47 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |