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 / BitAndFunction.java @ 44009

History | View | Annotate | Download (1.56 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 BitAndFunction extends AbstractFunction {
8

    
9
    public BitAndFunction() {
10
        super("Numeric", "BITAND", Range.is(2),
11
            "The BITAND function treats its inputs and its output as vectors of bits; the output is the bitwise AND 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
            "BITAND({{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 boolean allowConstantFolding() {
27
        return true;
28
    }
29
    
30
    @Override
31
    public Object call(Interpreter interpreter, Object[] args) {
32
        Object op1 = args[0];
33
        Object op2 = args[1];
34
        
35
        if( op1 instanceof Integer ) {
36
            int value = ((Number) op1).intValue() & ((Number) op2).intValue();
37
            return value;
38
        } 
39
        if( op1 instanceof Number ) {
40
            long value = ((Number) op1).longValue() & ((Number) op2).longValue();
41
            return value;
42
        } 
43
        
44
        throw new IllegalArgumentException("Types not allowed in '"+name()+"' function.");
45
    }
46
    
47

    
48
}