Statistics
| Revision:

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 @ 45041

History | View | Annotate | Download (2.07 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 45041 jjdelcerro
        if( (type & TYPE_NULL) == TYPE_NULL ) {
24
            return false;
25
        }
26 43531 jjdelcerro
        if( (type & TYPE_DOUBLE) == TYPE_DOUBLE ) {
27 44855 jjdelcerro
            double accuracy = MathUtils.EPSILON;
28
            if( interpreter.getAccuracy()!=null ) {
29
              accuracy = interpreter.getAccuracy();
30
            }
31
            boolean value = MathUtils.compareTo(getDouble(op1, 1),getDouble(op2, 2),accuracy) > 0;
32 43531 jjdelcerro
            return value;
33 43521 jjdelcerro
        }
34 43531 jjdelcerro
        if( (type & TYPE_FLOAT) == TYPE_FLOAT ) {
35 44855 jjdelcerro
            double accuracy = MathUtils.EPSILON;
36
            if( interpreter.getAccuracy()!=null ) {
37
              accuracy = interpreter.getAccuracy();
38
            }
39
            boolean value = MathUtils.compareTo(getFloat(op1, 1),getFloat(op2, 2),accuracy) > 0;
40 43531 jjdelcerro
            return value;
41
        }
42
        if( (type & TYPE_LONG) == TYPE_LONG ) {
43 44855 jjdelcerro
            boolean value = Long.compare(getLong(op1, 1),getLong(op2, 2)) > 0;
44 43531 jjdelcerro
            return value;
45
        }
46
        if( (type & TYPE_INT) == TYPE_INT ) {
47 44855 jjdelcerro
            boolean value = Integer.compare(getInt(op1, 1),getInt(op2, 2)) > 0;
48 43531 jjdelcerro
            return value;
49 44855 jjdelcerro
        }
50 43512 jjdelcerro
        if( op2 instanceof Comparable && op2 instanceof Comparable ) {
51 44855 jjdelcerro
            boolean value =   getComparable(op1,1).compareTo(getComparable(op2,2)) > 0;
52 43512 jjdelcerro
            return value;
53
        }
54
        throw new IllegalArgumentException("Types not allowed in '"+name()+"' operand.");
55
    }
56
57
58
}