svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / operations / AndOperator.java @ 40665
History | View | Annotate | Download (1.84 KB)
1 |
package org.gvsig.labeling.operations; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Hashtable; |
5 |
|
6 |
import com.hardcode.gdbms.engine.values.Value; |
7 |
import com.iver.cit.gvsig.fmap.Messages; |
8 |
|
9 |
|
10 |
|
11 |
|
12 |
/**
|
13 |
* Implements the funcionality of an AND operator
|
14 |
*
|
15 |
* @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
|
16 |
*
|
17 |
*/
|
18 |
public class AndOperator extends Operator{ |
19 |
private ArrayList<Expression> arguments = new ArrayList<Expression>(); |
20 |
|
21 |
public String getName() { |
22 |
return OperationTags.AND_OP;
|
23 |
} |
24 |
|
25 |
|
26 |
public AndOperator(Hashtable<String, Value> symbol_table) { |
27 |
super(symbol_table);
|
28 |
} |
29 |
|
30 |
public Object evaluate()throws ExpressionException { |
31 |
Object value1=((Expression)arguments.get(0)).evaluate(); |
32 |
if (value1 ==null) |
33 |
return false; |
34 |
Boolean result = ((Boolean)value1).booleanValue(); |
35 |
|
36 |
for (int i = 1; i < arguments.size(); i++){ |
37 |
Expression function = (Expression)arguments.get(i); |
38 |
Object value2=function.evaluate();
|
39 |
if (value2 ==null) |
40 |
return false; |
41 |
result = result && ((Boolean)value2).booleanValue();
|
42 |
} |
43 |
return result;
|
44 |
} |
45 |
|
46 |
public void addArgument(int i, Expression arg) { |
47 |
arguments.add(i, arg); |
48 |
|
49 |
} |
50 |
|
51 |
public String getPattern() { |
52 |
return "("+Messages.getString(OperationTags.OPERAND) |
53 |
+ OperationTags.AND_OP +Messages.getString(OperationTags.OPERAND)+ ")\n"+
|
54 |
Messages.getString(OperationTags.OPERAND) +" = "+
|
55 |
Messages.getString(OperationTags.BOOLEAN_VALUE); } |
56 |
|
57 |
public ArrayList<Expression> getArguments() { |
58 |
return arguments;
|
59 |
} |
60 |
|
61 |
public void setArguments(ArrayList<Expression> arguments) { |
62 |
this.arguments = arguments;
|
63 |
} |
64 |
|
65 |
public void check() throws ExpressionException { |
66 |
|
67 |
|
68 |
for (int i = 0; i < arguments.size(); i++) { |
69 |
if(!(arguments.get(i).evaluate()instanceof Boolean)) |
70 |
throw new ExpressionException(ExpressionException.CLASS_CASTING_EXCEPTION); |
71 |
} |
72 |
|
73 |
} |
74 |
|
75 |
} |