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