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 / GeOperator.java @ 44855
History | View | Annotate | Download (1.99 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_GE; |
6 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Function; |
7 | import org.gvsig.expressionevaluator.Interpreter; |
||
8 | |||
9 | 43512 | jjdelcerro | public class GeOperator extends AbstractBinaryOperator { |
10 | |||
11 | public GeOperator() {
|
||
12 | 44207 | jjdelcerro | super(Function.GROUP_BOOLEAN, OPERATOR_GE, 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 | 44855 | jjdelcerro | double accuracy = MathUtils.EPSILON;
|
25 | if( interpreter.getAccuracy()!=null ) { |
||
26 | accuracy = interpreter.getAccuracy(); |
||
27 | } |
||
28 | boolean value = MathUtils.compareTo(getDouble(op2, 1),getDouble(op2, 2),accuracy) >= 0; |
||
29 | 43531 | jjdelcerro | return value;
|
30 | 43521 | jjdelcerro | } |
31 | 43531 | jjdelcerro | if( (type & TYPE_FLOAT) == TYPE_FLOAT ) {
|
32 | 44855 | jjdelcerro | double accuracy = MathUtils.EPSILON;
|
33 | if( interpreter.getAccuracy()!=null ) { |
||
34 | accuracy = interpreter.getAccuracy(); |
||
35 | } |
||
36 | boolean value = MathUtils.compareTo(getFloat(op1, 1),getFloat(op2, 2),accuracy) >= 0; |
||
37 | 43531 | jjdelcerro | return value;
|
38 | } |
||
39 | if( (type & TYPE_LONG) == TYPE_LONG ) {
|
||
40 | 44855 | jjdelcerro | boolean value = Long.compare(getLong(op1, 1),getLong(op2, 2)) >= 0; |
41 | 43531 | jjdelcerro | return value;
|
42 | } |
||
43 | if( (type & TYPE_INT) == TYPE_INT ) {
|
||
44 | 44855 | jjdelcerro | boolean value = Integer.compare(getInt(op1, 1),getInt(op2, 2)) >= 0; |
45 | 43531 | jjdelcerro | return value;
|
46 | 44855 | jjdelcerro | } |
47 | 43512 | jjdelcerro | if( op2 instanceof Comparable && op2 instanceof Comparable ) { |
48 | 44855 | jjdelcerro | boolean value = getComparable(op1,1).compareTo(getComparable(op2,2)) >= 0; |
49 | 43512 | jjdelcerro | return value;
|
50 | } |
||
51 | throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand."); |
||
52 | } |
||
53 | |||
54 | |||
55 | } |