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 / operator / AbstractBinaryOperator.java @ 43983
History | View | Annotate | Download (2.39 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.operator; |
---|---|
2 |
|
3 |
import java.util.Date; |
4 |
import org.apache.commons.lang3.Range; |
5 |
import org.gvsig.expressionevaluator.Interpreter; |
6 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
7 |
|
8 |
|
9 |
public abstract class AbstractBinaryOperator extends AbstractFunction implements BinaryOperator { |
10 |
|
11 |
protected AbstractBinaryOperator(String group, String name, String description) { |
12 |
super(group, name, Range.is(2), description, " {{oper1}} " + name + " oper2 "); |
13 |
} |
14 |
|
15 |
protected AbstractBinaryOperator(String group, String name) { |
16 |
super(group, name, Range.is(2), null, " {{oper1}} " + name + " oper2 "); |
17 |
} |
18 |
|
19 |
@Override
|
20 |
public Object call(Interpreter interpreter, Object[] args) { |
21 |
return call(interpreter, args[0], args[1]); |
22 |
|
23 |
} |
24 |
|
25 |
@Override
|
26 |
public boolean isOperator() { |
27 |
return true; |
28 |
} |
29 |
|
30 |
protected static final int TYPE_INT = 0b0000001; |
31 |
protected static final int TYPE_LONG = 0b0000010; |
32 |
protected static final int TYPE_FLOAT = 0b0000100; |
33 |
protected static final int TYPE_DOUBLE = 0b0001000; |
34 |
protected static final int TYPE_BOOLEAN = 0b0010000; |
35 |
protected static final int TYPE_STRING = 0b0100000; |
36 |
protected static final int TYPE_DATE = 0b1000000; |
37 |
|
38 |
protected int getType(Object op1, Object op2) { |
39 |
int r = 0; |
40 |
if( op1 instanceof Double ) { |
41 |
r |= TYPE_DOUBLE; |
42 |
} else if( op1 instanceof Float ) { |
43 |
r |= TYPE_FLOAT; |
44 |
} else if( op1 instanceof Long ) { |
45 |
r |= TYPE_LONG; |
46 |
} else if( op1 instanceof Integer ) { |
47 |
r |= TYPE_INT; |
48 |
} else if( op1 instanceof Boolean ) { |
49 |
r |= TYPE_BOOLEAN; |
50 |
} else if( op1 instanceof String ) { |
51 |
r |= TYPE_STRING; |
52 |
} else if( op1 instanceof Date ) { |
53 |
r |= TYPE_DATE; |
54 |
} |
55 |
if( op2 instanceof Double ) { |
56 |
r |= TYPE_DOUBLE; |
57 |
} else if( op2 instanceof Float ) { |
58 |
r |= TYPE_FLOAT; |
59 |
} else if( op2 instanceof Long ) { |
60 |
r |= TYPE_LONG; |
61 |
} else if( op2 instanceof Integer ) { |
62 |
r |= TYPE_INT; |
63 |
} else if( op2 instanceof Boolean ) { |
64 |
r |= TYPE_BOOLEAN; |
65 |
} else if( op2 instanceof String ) { |
66 |
r |= TYPE_STRING; |
67 |
} else if( op2 instanceof Date ) { |
68 |
r |= TYPE_DATE; |
69 |
} |
70 |
return r;
|
71 |
} |
72 |
|
73 |
} |