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