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