Revision 44098 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractFunction.java
AbstractFunction.java | ||
---|---|---|
14 | 14 |
import org.gvsig.expressionevaluator.Code; |
15 | 15 |
import org.gvsig.expressionevaluator.Code.Caller.Arguments; |
16 | 16 |
import org.gvsig.expressionevaluator.Function; |
17 |
import org.gvsig.expressionevaluator.I18N; |
|
17 | 18 |
import org.gvsig.expressionevaluator.Interpreter; |
18 | 19 |
import org.gvsig.fmap.geom.Geometry; |
19 | 20 |
import org.gvsig.fmap.geom.primitive.Point; |
... | ... | |
141 | 142 |
|
142 | 143 |
protected int getInt(Object args[], int n) { |
143 | 144 |
if( args.length < n ) { |
144 |
throw new IllegalArgumentException("Required argument "+n+" and only found " + args.length +" arguments in call to '"+name()+"'.");
|
|
145 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n));
|
|
145 | 146 |
} |
146 |
if( !(args[n] instanceof Number) ) {
|
|
147 |
String type = (args[n]==null)? "null" : args[n].getClass().getCanonicalName();
|
|
148 |
throw new IllegalArgumentException("Type not allowed for argument " + n + " in '" + name() + "' function, expected Number and got " + type + ".");
|
|
147 |
Object value = args[n];
|
|
148 |
if( value == null ) {
|
|
149 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n));
|
|
149 | 150 |
} |
150 |
return ((Number)args[n]).intValue(); |
|
151 |
if( !(value instanceof Number) ) { |
|
152 |
String type = value.getClass().getCanonicalName(); |
|
153 |
throw new IllegalArgumentException( |
|
154 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
155 |
I18N.Expected_XexpectedX_and_found_XfoundX("Number",type) |
|
156 |
); |
|
157 |
} |
|
158 |
return ((Number)value).intValue(); |
|
151 | 159 |
} |
152 | 160 |
|
153 | 161 |
protected long getLong(Object args[], int n) { |
154 | 162 |
if( args.length < n ) { |
155 |
throw new IllegalArgumentException("Required argument "+n+" and only found " + args.length +" arguments in call to '"+name()+"'.");
|
|
163 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n));
|
|
156 | 164 |
} |
157 |
if( !(args[n] instanceof Number) ) {
|
|
158 |
String type = (args[n]==null)? "null" : args[n].getClass().getCanonicalName();
|
|
159 |
throw new IllegalArgumentException("Type not allowed for argument " + n + " in '" + name() + "' function, expected Number and got " + type + ".");
|
|
165 |
Object value = args[n];
|
|
166 |
if( value == null ) {
|
|
167 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n));
|
|
160 | 168 |
} |
161 |
return ((Number)args[n]).longValue(); |
|
169 |
if( !(value instanceof Number) ) { |
|
170 |
String type = value.getClass().getCanonicalName(); |
|
171 |
throw new IllegalArgumentException( |
|
172 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
173 |
I18N.Expected_XexpectedX_and_found_XfoundX("Number",type) |
|
174 |
); |
|
175 |
} |
|
176 |
return ((Number)value).longValue(); |
|
162 | 177 |
} |
163 | 178 |
|
164 | 179 |
protected double getDouble(Object args[], int n) { |
165 | 180 |
if( args.length < n ) { |
166 |
throw new IllegalArgumentException("Required argument "+n+" and only found " + args.length +" arguments in call to '"+name()+"'.");
|
|
181 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n));
|
|
167 | 182 |
} |
168 |
if( !(args[n] instanceof Number) ) {
|
|
169 |
String type = (args[n]==null)? "null" : args[n].getClass().getCanonicalName();
|
|
170 |
throw new IllegalArgumentException("Type not allowed for argument " + n + " in '" + name() + "' function, expected Number and got " + type + ".");
|
|
183 |
Object value = args[n];
|
|
184 |
if( value == null ) {
|
|
185 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n));
|
|
171 | 186 |
} |
172 |
return ((Number)args[n]).doubleValue(); |
|
187 |
if( !(value instanceof Number) ) { |
|
188 |
String type = value.getClass().getCanonicalName(); |
|
189 |
throw new IllegalArgumentException( |
|
190 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
191 |
I18N.Expected_XexpectedX_and_found_XfoundX("Number",type) |
|
192 |
); |
|
193 |
} |
|
194 |
return ((Number)value).doubleValue(); |
|
173 | 195 |
} |
174 | 196 |
|
175 | 197 |
protected String getStr(Object args[], int n) { |
176 | 198 |
if( args.length < n ) { |
177 |
throw new IllegalArgumentException("Required argument "+n+" and only found " + args.length +" arguments in call to '"+name()+"'.");
|
|
199 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n));
|
|
178 | 200 |
} |
179 | 201 |
return Objects.toString(args[n], ""); |
180 | 202 |
} |
181 | 203 |
|
182 | 204 |
protected Object getObject(Object args[], int n) { |
183 | 205 |
if( args.length < n ) { |
184 |
throw new IllegalArgumentException("Required argument "+n+" and only found " + args.length +" arguments in call to '"+name()+"'.");
|
|
206 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n));
|
|
185 | 207 |
} |
186 | 208 |
return args[n]; |
187 | 209 |
} |
188 | 210 |
|
189 | 211 |
protected Object getObject(Interpreter interpreter, Arguments args, int n) { |
190 | 212 |
if( args.count() < n ) { |
191 |
throw new IllegalArgumentException("Required argument "+n+" and only found " + args.count() +" arguments in call to '"+name()+"'.");
|
|
213 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.count(), n));
|
|
192 | 214 |
} |
193 | 215 |
Code arg = args.get(n); |
194 | 216 |
Object value = interpreter.run(arg); |
... | ... | |
196 | 218 |
} |
197 | 219 |
|
198 | 220 |
protected Geometry getGeom(Object[] args, int n) { |
221 |
return this.getGeom(args, n, false); |
|
222 |
} |
|
223 |
|
|
224 |
protected Geometry getGeom(Object[] args, int n, boolean allowNull) { |
|
199 | 225 |
if( args.length < n ) { |
200 |
throw new IllegalArgumentException("Required argument "+n+" and only found " + args.length +" arguments in call to '"+name()+"'.");
|
|
226 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n));
|
|
201 | 227 |
} |
202 |
if( !(args[n] instanceof Geometry) ) { |
|
203 |
String type = (args[n]==null)? "null" : args[n].getClass().getCanonicalName(); |
|
204 |
throw new IllegalArgumentException("Type not allowed for argument " + n + " in '" + name() + "' function, expected Geometry and got " + type + "."); |
|
228 |
Object value = args[n]; |
|
229 |
if( value == null ) { |
|
230 |
if( allowNull ) { |
|
231 |
return null; |
|
232 |
} |
|
233 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
|
205 | 234 |
} |
206 |
return (Geometry)args[n]; |
|
235 |
if( !(value instanceof Geometry) ) { |
|
236 |
String type = value.getClass().getCanonicalName(); |
|
237 |
throw new IllegalArgumentException( |
|
238 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
239 |
I18N.Expected_XexpectedX_and_found_XfoundX("Geometry",type) |
|
240 |
); |
|
241 |
} |
|
242 |
return (Geometry)value; |
|
207 | 243 |
} |
208 | 244 |
|
209 | 245 |
protected Point getPoint(Object[] args, int n) { |
210 | 246 |
if( args.length < n ) { |
211 |
throw new IllegalArgumentException("Required argument "+n+" and only found " + args.length +" arguments in call to '"+name()+"'.");
|
|
247 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n));
|
|
212 | 248 |
} |
213 |
if( !(args[n] instanceof Point) ) {
|
|
214 |
String type = (args[n]==null)? "null" : args[n].getClass().getCanonicalName();
|
|
215 |
throw new IllegalArgumentException("Type not allowed for argument " + n + " in '" + name() + "' function, expected Point and got " + type + ".");
|
|
249 |
Object value = args[n];
|
|
250 |
if( value == null ) {
|
|
251 |
return null;
|
|
216 | 252 |
} |
217 |
return (Point)args[n]; |
|
253 |
if( !(value instanceof Point) ) { |
|
254 |
String type = value.getClass().getCanonicalName(); |
|
255 |
throw new IllegalArgumentException( |
|
256 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
257 |
I18N.Expected_XexpectedX_and_found_XfoundX("Point",type) |
|
258 |
); |
|
259 |
} |
|
260 |
return (Point)value; |
|
218 | 261 |
} |
219 | 262 |
|
220 | 263 |
protected boolean getBoolean(Object args[], int n, Double accuracy) { |
221 | 264 |
if( args.length < n ) { |
222 |
throw new IllegalArgumentException("Required argument "+n+" and only found " + args.length +" arguments in call to '"+name()+"'.");
|
|
265 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n));
|
|
223 | 266 |
} |
224 | 267 |
Object value = args[n]; |
225 | 268 |
return toBoolean(value, accuracy); |
Also available in: Unified diff