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 @ 44207
History | View | Annotate | Download (1.12 KB)
1 | 43512 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.operator; |
---|---|---|---|
2 | |||
3 | 44207 | jjdelcerro | import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_NEGATE; |
4 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Function; |
5 | import org.gvsig.expressionevaluator.Interpreter; |
||
6 | 43512 | jjdelcerro | |
7 | 43521 | jjdelcerro | |
8 | 44098 | jjdelcerro | public class NegOperator extends AbstractUnaryOperator { |
9 | 43512 | jjdelcerro | |
10 | 44098 | jjdelcerro | public NegOperator() {
|
11 | 44207 | jjdelcerro | super(Function.GROUP_NUMERIC, OPERATOR_NEGATE, true); |
12 | 43512 | jjdelcerro | } |
13 | |||
14 | @Override
|
||
15 | 44009 | jjdelcerro | public boolean allowConstantFolding() { |
16 | return true; |
||
17 | } |
||
18 | |||
19 | @Override
|
||
20 | 43521 | jjdelcerro | public Object call(Interpreter interpreter, Object arg) { |
21 | 44098 | jjdelcerro | if( !(arg instanceof Number) ) { |
22 | throw new IllegalArgumentException("NEGATE function require a number"); |
||
23 | 43512 | jjdelcerro | } |
24 | 44098 | jjdelcerro | if( arg instanceof Double ) { |
25 | return -((Number)arg).doubleValue(); |
||
26 | } |
||
27 | if( arg instanceof Float ) { |
||
28 | return -((Number)arg).floatValue(); |
||
29 | } |
||
30 | if( arg instanceof Long ) { |
||
31 | return -((Number)arg).longValue(); |
||
32 | } |
||
33 | if( arg instanceof Integer ) { |
||
34 | return -((Number)arg).intValue(); |
||
35 | } |
||
36 | return -((Number)arg).doubleValue(); |
||
37 | 43512 | jjdelcerro | } |
38 | |||
39 | } |