svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / operator / NegOperator.java @ 44139
History | View | Annotate | Download (1.07 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.operator; |
---|---|
2 |
|
3 |
import org.gvsig.expressionevaluator.Function; |
4 |
import org.gvsig.expressionevaluator.Interpreter; |
5 |
|
6 |
|
7 |
public class NegOperator extends AbstractUnaryOperator { |
8 |
|
9 |
public static final String NAME = "NEGATE"; |
10 |
|
11 |
public NegOperator() {
|
12 |
super(Function.GROUP_NUMERIC,NAME);
|
13 |
} |
14 |
|
15 |
@Override
|
16 |
public boolean allowConstantFolding() { |
17 |
return true; |
18 |
} |
19 |
|
20 |
@Override
|
21 |
public Object call(Interpreter interpreter, Object arg) { |
22 |
if( !(arg instanceof Number) ) { |
23 |
throw new IllegalArgumentException("NEGATE function require a number"); |
24 |
} |
25 |
if( arg instanceof Double ) { |
26 |
return -((Number)arg).doubleValue(); |
27 |
} |
28 |
if( arg instanceof Float ) { |
29 |
return -((Number)arg).floatValue(); |
30 |
} |
31 |
if( arg instanceof Long ) { |
32 |
return -((Number)arg).longValue(); |
33 |
} |
34 |
if( arg instanceof Integer ) { |
35 |
return -((Number)arg).intValue(); |
36 |
} |
37 |
return -((Number)arg).doubleValue(); |
38 |
} |
39 |
|
40 |
} |