comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/WaterlevelGroundDifferences.java @ 9277:2323d005f9a5

compile error fix
author gernotbelger
date Fri, 20 Jul 2018 10:39:02 +0200
parents e4606eae8ea5
children
comparison
equal deleted inserted replaced
9276:3141f0e7314e 9277:2323d005f9a5
6 * documentation coming with Dive4Elements River for details. 6 * documentation coming with Dive4Elements River for details.
7 */ 7 */
8 8
9 package org.dive4elements.river.artifacts.states; 9 package org.dive4elements.river.artifacts.states;
10 10
11 import org.w3c.dom.Element;
12
13 import org.apache.log4j.Logger; 11 import org.apache.log4j.Logger;
14 12 import org.dive4elements.artifactdatabase.data.StateData;
15 import org.dive4elements.river.artifacts.D4EArtifact;
16
17 import org.dive4elements.artifacts.Artifact; 13 import org.dive4elements.artifacts.Artifact;
18 import org.dive4elements.artifacts.CallContext; 14 import org.dive4elements.artifacts.CallContext;
19
20 import org.dive4elements.artifacts.common.utils.XMLUtils; 15 import org.dive4elements.artifacts.common.utils.XMLUtils;
21 16 import org.dive4elements.river.artifacts.D4EArtifact;
22 import org.dive4elements.artifactdatabase.data.StateData; 17 import org.w3c.dom.Element;
23 import org.dive4elements.artifactdatabase.ProtocolUtils;
24
25 18
26 /** 19 /**
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
28 */ 21 */
29 public class WaterlevelGroundDifferences extends RangeState { 22 public class WaterlevelGroundDifferences extends RangeState {
30 23
31 public static final String LOWER_FIELD = "diff_from"; 24 public static final String LOWER_FIELD = "diff_from";
32 public static final String UPPER_FIELD = "diff_to"; 25 public static final String UPPER_FIELD = "diff_to";
33 public static final String DIFF_FIELD = "diff_diff"; 26 public static final String DIFF_FIELD = "diff_diff";
34 27
35 public static final double DEFAULT_STEP = 0d; 28 public static final double DEFAULT_STEP = 0d;
36 29
37 30 private static Logger log = Logger.getLogger(WaterlevelGroundDifferences.class);
38 private static Logger log =
39 Logger.getLogger(WaterlevelGroundDifferences.class);
40
41 31
42 protected String getLowerField() { 32 protected String getLowerField() {
43 return LOWER_FIELD; 33 return LOWER_FIELD;
44 } 34 }
45 35
46
47 protected String getUpperField() { 36 protected String getUpperField() {
48 return UPPER_FIELD; 37 return UPPER_FIELD;
49 } 38 }
50
51 39
52 protected String getStepField() { 40 protected String getStepField() {
53 return DIFF_FIELD; 41 return DIFF_FIELD;
54 } 42 }
55 43
56
57 @Override 44 @Override
58 protected double[] getMinMax(Artifact artifact) { 45 protected double[] getMinMax(final Artifact artifact) {
59 return new double[] { -Double.MAX_VALUE, Double.MAX_VALUE }; 46 return new double[] { -Double.MAX_VALUE, Double.MAX_VALUE };
60 } 47 }
61
62 48
63 @Override 49 @Override
64 protected String getUIProvider() { 50 protected String getUIProvider() {
65 return "waterlevel_ground_panel"; 51 return "waterlevel_ground_panel";
66 } 52 }
67 53
68
69 protected double getDefaultStep() { 54 protected double getDefaultStep() {
70 return DEFAULT_STEP; 55 return DEFAULT_STEP;
71 } 56 }
72 57
73
74 @Override 58 @Override
75 protected Element[] createItems( 59 protected Element[] createItems(final XMLUtils.ElementCreator cr, final Artifact artifact, final String name, final CallContext context) {
76 XMLUtils.ElementCreator cr, 60 final double[] minmax = getMinMax(artifact);
77 Artifact artifact,
78 String name,
79 CallContext context)
80 {
81 double[] minmax = getMinMax(artifact);
82 61
83 double minVal = Double.MIN_VALUE; 62 double minVal = Double.MIN_VALUE;
84 double maxVal = Double.MAX_VALUE; 63 double maxVal = Double.MAX_VALUE;
85 64
86 if (minmax != null) { 65 if (minmax != null) {
87 minVal = minmax[0]; 66 minVal = minmax[0];
88 maxVal = minmax[1]; 67 maxVal = minmax[1];
89 } 68 } else {
90 else {
91 log.warn("Could not read min/max distance values!"); 69 log.warn("Could not read min/max distance values!");
92 } 70 }
93 71
94 if (name.equals(LOWER_FIELD)) { 72 if (name.equals(LOWER_FIELD)) {
95 Element min = createItem( 73 final Element min = createItem(cr, new String[] { "min", new Double(minVal).toString() });
96 cr,
97 new String[] {"min", new Double(minVal).toString()});
98 74
99 return new Element[] { min }; 75 return new Element[] { min };
100 } 76 } else if (name.equals(UPPER_FIELD)) {
101 else if (name.equals(UPPER_FIELD)) { 77 final Element max = createItem(cr, new String[] { "max", new Double(maxVal).toString() });
102 Element max = createItem(
103 cr,
104 new String[] {"max", new Double(maxVal).toString()});
105 78
106 return new Element[] { max }; 79 return new Element[] { max };
107 } 80 } else {
108 else { 81 final Element step = createItem(cr, new String[] { "step", String.valueOf(getDefaultStep()) });
109 Element step = createItem(
110 cr,
111 new String[] {"step", String.valueOf(getDefaultStep())});
112 return new Element[] { step }; 82 return new Element[] { step };
113 } 83 }
114 } 84 }
115 85
116 86 // ist mit super identisch!
117 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { 87 // protected Element createItem(XMLUtils.ElementCreator cr, Object obj) {
118 Element item = ProtocolUtils.createArtNode(cr, "item", null, null); 88 // Element item = ProtocolUtils.createArtNode(cr, "item", null, null);
119 Element label = ProtocolUtils.createArtNode(cr, "label", null, null); 89 // Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
120 Element value = ProtocolUtils.createArtNode(cr, "value", null, null); 90 // Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
121 91 //
122 String[] arr = (String[]) obj; 92 // String[] arr = (String[]) obj;
123 93 //
124 label.setTextContent(arr[0]); 94 // label.setTextContent(arr[0]);
125 value.setTextContent(arr[1]); 95 // value.setTextContent(arr[1]);
126 96 //
127 item.appendChild(label); 97 // item.appendChild(label);
128 item.appendChild(value); 98 // item.appendChild(value);
129 99 //
130 return item; 100 // return item;
131 } 101 // }
132 102
133 @Override 103 @Override
134 public boolean validate(Artifact artifact) 104 public boolean validate(final Artifact artifact) throws IllegalArgumentException {
135 throws IllegalArgumentException 105 final D4EArtifact flys = (D4EArtifact) artifact;
136 {
137 D4EArtifact flys = (D4EArtifact) artifact;
138 106
139 StateData dFrom = getData(flys, getLowerField()); 107 final StateData dFrom = getData(flys, getLowerField());
140 StateData dTo = getData(flys, getUpperField()); 108 final StateData dTo = getData(flys, getUpperField());
141 StateData dStep = getData(flys, getStepField()); 109 final StateData dStep = getData(flys, getStepField());
142 110
143 String fromStr = dFrom != null ? (String) dFrom.getValue() : null; 111 final String fromStr = dFrom != null ? (String) dFrom.getValue() : null;
144 String toStr = dTo != null ? (String) dTo.getValue() : null; 112 final String toStr = dTo != null ? (String) dTo.getValue() : null;
145 String stepStr = dStep != null ? (String) dStep.getValue() : null; 113 final String stepStr = dStep != null ? (String) dStep.getValue() : null;
146 114
147 if (fromStr == null || toStr == null || stepStr == null) { 115 if (fromStr == null || toStr == null || stepStr == null) {
148 throw new IllegalArgumentException("error_empty_state"); 116 throw new IllegalArgumentException("error_empty_state");
149 } 117 }
150 118
151 try { 119 try {
152 double from = Double.parseDouble(fromStr); 120 final double from = Double.parseDouble(fromStr);
153 double to = Double.parseDouble(toStr); 121 final double to = Double.parseDouble(toStr);
154 double step = Double.parseDouble(stepStr); 122 final double step = Double.parseDouble(stepStr);
155 123
156 double[] minmax = getMinMax(flys); 124 final double[] minmax = getMinMax(flys);
157 125
158 return validateBounds(minmax[0], minmax[1], from, to, step); 126 return validateBounds(minmax[0], minmax[1], from, to, step);
159 } 127 }
160 catch (NumberFormatException nfe) { 128 catch (final NumberFormatException nfe) {
161 throw new IllegalArgumentException("error_invalid_double_value"); 129 throw new IllegalArgumentException("error_invalid_double_value");
162 } 130 }
163 } 131 }
164 132
165 @Override 133 @Override
166 protected boolean validateBounds( 134 protected boolean validateBounds(final double fromValid, final double toValid, final double from, final double to) throws IllegalArgumentException {
167 double fromValid, double toValid,
168 double from, double to
169 ) throws IllegalArgumentException {
170 if (to < 0d) { 135 if (to < 0d) {
171 log.error( 136 log.error("Invalid 'to' " + to + " is lesser than zero.");
172 "Invalid 'to' " + to + " is lesser than zero.");
173 throw new IllegalArgumentException("error_feed_from_out_of_range"); 137 throw new IllegalArgumentException("error_feed_from_out_of_range");
174 } 138 }
175 return super.validateBounds(fromValid, toValid, from, to); 139 return super.validateBounds(fromValid, toValid, from, to);
176 } 140 }
177 } 141 }

http://dive4elements.wald.intevation.org