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 / GtOperator.java @ 44207
History | View | Annotate | Download (1.98 KB)
1 | 43512 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.operator; |
---|---|---|---|
2 | |||
3 | 43521 | jjdelcerro | import org.apache.commons.lang3.ObjectUtils; |
4 | import org.apache.commons.math.util.MathUtils; |
||
5 | 44207 | jjdelcerro | import static org.gvsig.expressionevaluator.ExpressionBuilder.OPERATOR_GT; |
6 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Function; |
7 | import org.gvsig.expressionevaluator.Interpreter; |
||
8 | |||
9 | 43512 | jjdelcerro | public class GtOperator extends AbstractBinaryOperator { |
10 | |||
11 | public GtOperator() {
|
||
12 | 44207 | jjdelcerro | super(Function.GROUP_BOOLEAN, OPERATOR_GT, true); |
13 | 43512 | jjdelcerro | } |
14 | |||
15 | @Override
|
||
16 | 44009 | jjdelcerro | public boolean allowConstantFolding() { |
17 | return true; |
||
18 | } |
||
19 | |||
20 | @Override
|
||
21 | 43521 | jjdelcerro | public Object call(Interpreter interpreter, Object op1, Object op2) { |
22 | 43531 | jjdelcerro | int type = this.getType(op1, op2); |
23 | if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) {
|
||
24 | boolean value = MathUtils.compareTo(
|
||
25 | ((Number) op1).doubleValue(),
|
||
26 | ((Number) op2).doubleValue(),
|
||
27 | interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
||
28 | ) > 0;
|
||
29 | return value;
|
||
30 | 43521 | jjdelcerro | } |
31 | 43531 | jjdelcerro | if( (type & TYPE_FLOAT) == TYPE_FLOAT ) {
|
32 | boolean value = MathUtils.compareTo(
|
||
33 | ((Number) op1).floatValue(),
|
||
34 | ((Number) op2).floatValue(),
|
||
35 | interpreter.getAccuracy()==null? MathUtils.EPSILON:interpreter.getAccuracy()
|
||
36 | ) > 0;
|
||
37 | return value;
|
||
38 | } |
||
39 | if( (type & TYPE_LONG) == TYPE_LONG ) {
|
||
40 | boolean value = ((Number) op1).longValue() > ((Number) op2).longValue(); |
||
41 | return value;
|
||
42 | } |
||
43 | if( (type & TYPE_INT) == TYPE_INT ) {
|
||
44 | boolean value = ((Number) op1).intValue() > ((Number) op2).intValue(); |
||
45 | return value;
|
||
46 | } |
||
47 | 43512 | jjdelcerro | if( op2 instanceof Comparable && op2 instanceof Comparable ) { |
48 | 43521 | jjdelcerro | boolean value = ObjectUtils.compare((Comparable)op1,(Comparable)op2) > 0; |
49 | 43512 | jjdelcerro | return value;
|
50 | } |
||
51 | throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
||
52 | } |
||
53 | |||
54 | |||
55 | } |