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 / BitOrFunction.java @ 43983
History | View | Annotate | Download (1.44 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 BitOrFunction extends AbstractFunction { |
||
8 | |||
9 | public BitOrFunction() {
|
||
10 | 43983 | jjdelcerro | super("Numeric", "BITOR", Range.is(2), |
11 | "The BITOR function treats its inputs and its output as vectors of bits; the output is the bitwise OR 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 | "BITOR({{expr1}}, expr2)",
|
||
16 | new String[]{ |
||
17 | "expr1 - the fisrt argument",
|
||
18 | "expr2 - the second argument"
|
||
19 | }, |
||
20 | "Long"
|
||
21 | ); |
||
22 | 43512 | jjdelcerro | } |
23 | |||
24 | @Override
|
||
25 | 43521 | jjdelcerro | public Object call(Interpreter interpreter, Object[] args) { |
26 | 43512 | jjdelcerro | 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 | } |