Revision 44855 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 | ||
---|---|---|
159 | 159 |
if( args.length < n ) { |
160 | 160 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
161 | 161 |
} |
162 |
Object value = args[n]; |
|
162 |
return getInt(args[n],n); |
|
163 |
} |
|
164 |
|
|
165 |
protected int getInt(Object value, int n) { |
|
163 | 166 |
if( value == null ) { |
164 | 167 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
165 | 168 |
} |
... | ... | |
177 | 180 |
if( args.length < n ) { |
178 | 181 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
179 | 182 |
} |
180 |
Object value = args[n]; |
|
183 |
return getLong(args[n],n); |
|
184 |
} |
|
185 |
|
|
186 |
protected long getLong(Object value, int n) { |
|
181 | 187 |
if( value == null ) { |
182 | 188 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
183 | 189 |
} |
... | ... | |
195 | 201 |
if( args.length < n ) { |
196 | 202 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
197 | 203 |
} |
198 |
Object value = args[n]; |
|
204 |
return getDouble(args[n],n); |
|
205 |
} |
|
206 |
|
|
207 |
protected double getDouble(Object value, int arg) { |
|
199 | 208 |
if( value == null ) { |
200 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n));
|
|
209 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), arg));
|
|
201 | 210 |
} |
202 | 211 |
if( !(value instanceof Number) ) { |
203 | 212 |
String type = value.getClass().getCanonicalName(); |
204 | 213 |
throw new IllegalArgumentException( |
205 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " +
|
|
214 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), arg) + " " +
|
|
206 | 215 |
I18N.Expected_XexpectedX_and_found_XfoundX("Number",type) |
207 | 216 |
); |
208 | 217 |
} |
209 | 218 |
return ((Number)value).doubleValue(); |
210 | 219 |
} |
211 | 220 |
|
221 |
protected float getFloat(Object args[], int n) { |
|
222 |
if( args.length < n ) { |
|
223 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
|
224 |
} |
|
225 |
return getFloat(args[n],n); |
|
226 |
} |
|
227 |
|
|
228 |
protected float getFloat(Object value, int arg) { |
|
229 |
if( value == null ) { |
|
230 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), arg)); |
|
231 |
} |
|
232 |
if( !(value instanceof Number) ) { |
|
233 |
String type = value.getClass().getCanonicalName(); |
|
234 |
throw new IllegalArgumentException( |
|
235 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), arg) + " " + |
|
236 |
I18N.Expected_XexpectedX_and_found_XfoundX("Number",type) |
|
237 |
); |
|
238 |
} |
|
239 |
return ((Number)value).floatValue(); |
|
240 |
} |
|
241 |
|
|
212 | 242 |
protected String getStr(Object args[], int n) { |
213 | 243 |
if( args.length < n ) { |
214 | 244 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
215 | 245 |
} |
216 |
return Objects.toString(args[n], "");
|
|
246 |
return getStr(args[n],n);
|
|
217 | 247 |
} |
218 | 248 |
|
249 |
protected String getStr(Object value, int n) { |
|
250 |
return Objects.toString(value, ""); |
|
251 |
} |
|
252 |
|
|
219 | 253 |
protected File getFile(Object args[], int n) { |
220 | 254 |
if( args.length < n ) { |
221 | 255 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
222 | 256 |
} |
223 |
Object arg = args[n]; |
|
224 |
if( arg == null ) { |
|
257 |
return getFile(args[n],n); |
|
258 |
} |
|
259 |
|
|
260 |
protected File getFile(Object value, int n) { |
|
261 |
if( value == null ) { |
|
225 | 262 |
return null; |
226 | 263 |
} |
227 |
if( arg instanceof File ) {
|
|
228 |
return (File)arg;
|
|
264 |
if( value instanceof File ) {
|
|
265 |
return (File)value;
|
|
229 | 266 |
} |
230 |
if( arg instanceof URL ) {
|
|
267 |
if( value instanceof URL ) {
|
|
231 | 268 |
try { |
232 |
return new File(((URL)arg).toURI());
|
|
269 |
return new File(((URL)value).toURI());
|
|
233 | 270 |
} catch (URISyntaxException ex) { |
234 | 271 |
return null; |
235 | 272 |
} |
236 | 273 |
} |
237 |
if( arg instanceof URI ) {
|
|
238 |
return new File(((URI)arg));
|
|
274 |
if( value instanceof URI ) {
|
|
275 |
return new File(((URI)value));
|
|
239 | 276 |
} |
240 |
String s = Objects.toString(arg, null);
|
|
277 |
String s = Objects.toString(value, null);
|
|
241 | 278 |
if( s == null ) { |
242 | 279 |
return null; |
243 | 280 |
} |
... | ... | |
264 | 301 |
return value; |
265 | 302 |
} |
266 | 303 |
|
267 |
protected Date getDate(Object[] args, int n) {
|
|
304 |
protected Comparable getComparable(Object[] args, int n) {
|
|
268 | 305 |
if( args.length < n ) { |
269 | 306 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
270 | 307 |
} |
271 |
Object value = args[n]; |
|
308 |
return getComparable(args[n],n); |
|
309 |
} |
|
310 |
|
|
311 |
protected Comparable getComparable(Object value, int n) { |
|
272 | 312 |
if( value == null ) { |
273 | 313 |
return null; |
274 | 314 |
} |
315 |
if( !(value instanceof Comparable) ) { |
|
316 |
String type = value.getClass().getCanonicalName(); |
|
317 |
throw new IllegalArgumentException( |
|
318 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
319 |
I18N.Expected_XexpectedX_and_found_XfoundX("Comparable",type) |
|
320 |
); |
|
321 |
} |
|
322 |
return (Comparable)value; |
|
323 |
} |
|
324 |
|
|
325 |
protected Comparable getDate(Object[] args, int n) { |
|
326 |
if( args.length < n ) { |
|
327 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
|
328 |
} |
|
329 |
return getDate(args[n],n); |
|
330 |
} |
|
331 |
|
|
332 |
protected Date getDate(Object value, int n) { |
|
333 |
if( value == null ) { |
|
334 |
return null; |
|
335 |
} |
|
275 | 336 |
if( !(value instanceof Date) ) { |
276 | 337 |
String type = value.getClass().getCanonicalName(); |
277 | 338 |
throw new IllegalArgumentException( |
... | ... | |
286 | 347 |
if( args.length < n ) { |
287 | 348 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
288 | 349 |
} |
289 |
Object value = args[n]; |
|
350 |
return getLocalDateTime(args[n],n); |
|
351 |
} |
|
352 |
|
|
353 |
protected LocalDateTime getLocalDateTime(Object value, int n) { |
|
290 | 354 |
if( value == null ) { |
291 | 355 |
return null; |
292 | 356 |
} |
... | ... | |
311 | 375 |
if( args.length < n ) { |
312 | 376 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
313 | 377 |
} |
314 |
Object value = args[n]; |
|
378 |
return getBoolean(args[n], n, accuracy); |
|
379 |
} |
|
380 |
|
|
381 |
protected boolean getBoolean(Object value, int n) { |
|
382 |
return getBoolean(value, n, MathUtils.EPSILON); |
|
383 |
} |
|
384 |
|
|
385 |
protected boolean getBoolean(Object value, int n, Double accuracy) { |
|
315 | 386 |
return toBoolean(value, accuracy); |
316 | 387 |
} |
317 | 388 |
|
Also available in: Unified diff