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 / numeric / BitXorFunction.java @ 43983

History | View | Annotate | Download (1.45 KB)

1
package org.gvsig.expressionevaluator.impl.function.numeric;
2

    
3
import org.apache.commons.lang3.Range;
4
import org.gvsig.expressionevaluator.Interpreter;
5
import org.gvsig.expressionevaluator.spi.AbstractFunction;
6

    
7
public class BitXorFunction extends AbstractFunction {
8

    
9
    public BitXorFunction() {
10
        super("Numeric", "BITXOR", Range.is(2),
11
            "The BITXOR function treats its inputs and its output as vectors of bits; the output is the bitwise XOR of the inputs.\n" +
12
            "\n" +
13
            "The types of expr1 and expr2 are INTEGER or LONG, and the result is of type INTEGER or LONG.\n" +
14
            "If the types of expr1 or expr2 are not INTEGER or LONG a error is raised.\n",
15
            "BITXOR({{expr1}}, expr2)",
16
            new String[]{
17
                "expr1 - the fisrt argument",
18
                "expr2 - the second argument"
19
            },
20
            "Long"
21
        );
22
    }
23

    
24
    @Override
25
    public Object call(Interpreter interpreter, Object[] args) {
26
        Object op1 = args[0];
27
        Object op2 = args[1];
28
        
29
        if( op1 instanceof Integer ) {
30
            int value = ((Number) op1).intValue() ^ ((Number) op2).intValue();
31
            return value;
32
        } 
33
        if( op1 instanceof Number ) {
34
            long value = ((Number) op1).longValue() ^ ((Number) op2).longValue();
35
            return value;
36
        } 
37
        
38
        throw new IllegalArgumentException("Types not allowed in '"+name()+"' function.");
39
    }
40

    
41
}