Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelGroundDifferences.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelGroundDifferences.java@1358d0c8481c |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.states; | |
2 | |
3 import org.w3c.dom.Element; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.dive4elements.river.artifacts.FLYSArtifact; | |
8 | |
9 import org.dive4elements.artifacts.Artifact; | |
10 import org.dive4elements.artifacts.CallContext; | |
11 | |
12 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
13 | |
14 import org.dive4elements.artifactdatabase.data.StateData; | |
15 import org.dive4elements.artifactdatabase.ProtocolUtils; | |
16 | |
17 | |
18 /** | |
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
20 */ | |
21 public class WaterlevelGroundDifferences extends RangeState { | |
22 | |
23 public static final String LOWER_FIELD = "diff_from"; | |
24 public static final String UPPER_FIELD = "diff_to"; | |
25 public static final String DIFF_FIELD = "diff_diff"; | |
26 | |
27 public static final double DEFAULT_STEP = 0d; | |
28 | |
29 | |
30 private static Logger logger = | |
31 Logger.getLogger(WaterlevelGroundDifferences.class); | |
32 | |
33 | |
34 protected String getLowerField() { | |
35 return LOWER_FIELD; | |
36 } | |
37 | |
38 | |
39 protected String getUpperField() { | |
40 return UPPER_FIELD; | |
41 } | |
42 | |
43 | |
44 protected String getStepField() { | |
45 return DIFF_FIELD; | |
46 } | |
47 | |
48 | |
49 @Override | |
50 protected double[] getMinMax(Artifact artifact) { | |
51 return new double[] { -Double.MAX_VALUE, Double.MAX_VALUE }; | |
52 } | |
53 | |
54 | |
55 @Override | |
56 protected String getUIProvider() { | |
57 return "waterlevel_ground_panel"; | |
58 } | |
59 | |
60 | |
61 protected double getDefaultStep() { | |
62 return DEFAULT_STEP; | |
63 } | |
64 | |
65 | |
66 @Override | |
67 protected Element[] createItems( | |
68 XMLUtils.ElementCreator cr, | |
69 Artifact artifact, | |
70 String name, | |
71 CallContext context) | |
72 { | |
73 double[] minmax = getMinMax(artifact); | |
74 | |
75 double minVal = Double.MIN_VALUE; | |
76 double maxVal = Double.MAX_VALUE; | |
77 | |
78 if (minmax != null) { | |
79 minVal = minmax[0]; | |
80 maxVal = minmax[1]; | |
81 } | |
82 else { | |
83 logger.warn("Could not read min/max distance values!"); | |
84 } | |
85 | |
86 if (name.equals(LOWER_FIELD)) { | |
87 Element min = createItem( | |
88 cr, | |
89 new String[] {"min", new Double(minVal).toString()}); | |
90 | |
91 return new Element[] { min }; | |
92 } | |
93 else if (name.equals(UPPER_FIELD)) { | |
94 Element max = createItem( | |
95 cr, | |
96 new String[] {"max", new Double(maxVal).toString()}); | |
97 | |
98 return new Element[] { max }; | |
99 } | |
100 else { | |
101 Element step = createItem( | |
102 cr, | |
103 new String[] {"step", String.valueOf(getDefaultStep())}); | |
104 return new Element[] { step }; | |
105 } | |
106 } | |
107 | |
108 | |
109 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { | |
110 Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
111 Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
112 Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
113 | |
114 String[] arr = (String[]) obj; | |
115 | |
116 label.setTextContent(arr[0]); | |
117 value.setTextContent(arr[1]); | |
118 | |
119 item.appendChild(label); | |
120 item.appendChild(value); | |
121 | |
122 return item; | |
123 } | |
124 | |
125 @Override | |
126 public boolean validate(Artifact artifact) | |
127 throws IllegalArgumentException | |
128 { | |
129 FLYSArtifact flys = (FLYSArtifact) artifact; | |
130 | |
131 StateData dFrom = getData(flys, getLowerField()); | |
132 StateData dTo = getData(flys, getUpperField()); | |
133 StateData dStep = getData(flys, getStepField()); | |
134 | |
135 String fromStr = dFrom != null ? (String) dFrom.getValue() : null; | |
136 String toStr = dTo != null ? (String) dTo.getValue() : null; | |
137 String stepStr = dStep != null ? (String) dStep.getValue() : null; | |
138 | |
139 if (fromStr == null || toStr == null || stepStr == null) { | |
140 throw new IllegalArgumentException("error_empty_state"); | |
141 } | |
142 | |
143 try { | |
144 double from = Double.parseDouble(fromStr); | |
145 double to = Double.parseDouble(toStr); | |
146 double step = Double.parseDouble(stepStr); | |
147 | |
148 double[] minmax = getMinMax(flys); | |
149 | |
150 return validateBounds(minmax[0], minmax[1], from, to, step); | |
151 } | |
152 catch (NumberFormatException nfe) { | |
153 throw new IllegalArgumentException("error_invalid_double_value"); | |
154 } | |
155 } | |
156 } | |
157 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |