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 / GreaterThanOrEqualsOperator.java @ 40665
History | View | Annotate | Download (1.92 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 |
* Implements the funcionality of a ( >= ) operator
|
12 |
*
|
13 |
* @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
|
14 |
*
|
15 |
*/
|
16 |
public class GreaterThanOrEqualsOperator extends Operator { |
17 |
|
18 |
private ArrayList<Expression> arguments = new ArrayList<Expression>(); |
19 |
|
20 |
public GreaterThanOrEqualsOperator(Hashtable<String, Value> symbol_table) { |
21 |
super(symbol_table);
|
22 |
} |
23 |
|
24 |
public String getName() { |
25 |
return OperationTags.GREATER_THAN_OR_EQ_OP;
|
26 |
} |
27 |
|
28 |
public Object evaluate()throws ExpressionException { |
29 |
Object eval1=((Expression)arguments.get(0)).evaluate(); |
30 |
Object eval2=((Expression)arguments.get(1)).evaluate(); |
31 |
if (eval1==null || eval2==null){ |
32 |
return false; |
33 |
} |
34 |
Double left = new Double(eval1.toString()); |
35 |
Double right = new Double(eval2.toString()); |
36 |
|
37 |
if (left >= right)
|
38 |
return true; |
39 |
else
|
40 |
return false; |
41 |
} |
42 |
|
43 |
public void addArgument(int i, Expression arg) { |
44 |
arguments.add(i, arg); |
45 |
|
46 |
} |
47 |
|
48 |
public String getPattern() { |
49 |
return "("+Messages.getString(OperationTags.OPERAND) |
50 |
+ OperationTags.GREATER_THAN_OR_EQ_OP +Messages.getString(OperationTags.OPERAND)+ ")\n"+
|
51 |
Messages.getString(OperationTags.OPERAND) +" = "+
|
52 |
Messages.getString(OperationTags.NUMERIC_VALUE); |
53 |
} |
54 |
|
55 |
public ArrayList<Expression> getArguments() { |
56 |
return arguments;
|
57 |
} |
58 |
|
59 |
public void setArguments(ArrayList<Expression> arguments) { |
60 |
this.arguments = arguments;
|
61 |
} |
62 |
|
63 |
public void check() throws ExpressionException { |
64 |
if (arguments.size() > 2) |
65 |
throw new ExpressionException(ExpressionException.INCORRECT_NUMBER_OF_ARGUMENTS); |
66 |
|
67 |
for (int i = 0; i < arguments.size(); i++) { |
68 |
if(!(arguments.get(i).evaluate()instanceof Double)) |
69 |
throw new ExpressionException(ExpressionException.CLASS_CASTING_EXCEPTION); |
70 |
} |
71 |
} |
72 |
} |