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 @ 44207
History | View | Annotate | Download (1.56 KB)
1 | 43512 | jjdelcerro | package org.gvsig.expressionevaluator.impl.function.numeric; |
---|---|---|---|
2 | |||
3 | import org.apache.commons.lang3.Range; |
||
4 | 43521 | jjdelcerro | import org.gvsig.expressionevaluator.Interpreter; |
5 | 43512 | jjdelcerro | 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 | 43983 | jjdelcerro | "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 | 43989 | jjdelcerro | "Long",
|
21 | true
|
||
22 | 43512 | jjdelcerro | ); |
23 | } |
||
24 | |||
25 | @Override
|
||
26 | 44009 | jjdelcerro | public boolean allowConstantFolding() { |
27 | return true; |
||
28 | } |
||
29 | |||
30 | @Override
|
||
31 | 43521 | jjdelcerro | public Object call(Interpreter interpreter, Object[] args) { |
32 | 43512 | jjdelcerro | 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 | } |