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

History | View | Annotate | Download (1.46 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
            true
22
        );
23
    }
24

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

    
42
}