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