root / trunk / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / operators / IsNumber.java @ 13444
History | View | Annotate | Download (1.63 KB)
1 |
package com.iver.cit.gvsig.project.documents.table.operators; |
---|---|
2 |
|
3 |
import org.apache.bsf.BSFException; |
4 |
import org.apache.bsf.BSFManager; |
5 |
|
6 |
import com.iver.andami.PluginServices; |
7 |
import com.iver.cit.gvsig.ExpressionFieldExtension; |
8 |
import com.iver.cit.gvsig.project.documents.table.AbstractOperator; |
9 |
import com.iver.cit.gvsig.project.documents.table.IOperator; |
10 |
|
11 |
/**
|
12 |
* @author Vicente Caballero Navarro
|
13 |
*/
|
14 |
public class IsNumber extends AbstractOperator{ |
15 |
|
16 |
public String addText(String s) { |
17 |
return toString()+"("+s+")"; |
18 |
} |
19 |
public String toString() { |
20 |
return "isNumber"; |
21 |
} |
22 |
public void eval(BSFManager interpreter) throws BSFException { |
23 |
// interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"boolean isNumber (String value){try{java.lang.Double.parseDouble(value);}catch(java.lang.NumberFormatException e){return false;}return true;};");
|
24 |
interpreter.exec(ExpressionFieldExtension.JYTHON,null,-1,-1,"def isNumber(value):\n" + |
25 |
" import java.lang.Double\n" +
|
26 |
" import java.lang.NumberFormatException\n" +
|
27 |
" try:\n" +
|
28 |
" java.lang.Double.parseDouble(value)\n" +
|
29 |
" except java.lang.NumberFormatException:\n" +
|
30 |
" return 0==1 #false\n" +
|
31 |
" return 1==1 #true\n");
|
32 |
} |
33 |
public boolean isEnable() { |
34 |
return (getType()==IOperator.STRING);
|
35 |
} |
36 |
public String getDescription() { |
37 |
return PluginServices.getText(this, "parameter") + ": " + |
38 |
PluginServices.getText(this, "string_value") + "\n" + |
39 |
PluginServices.getText(this, "returns") + ": " + |
40 |
PluginServices.getText(this, "boolean_value") + "\n" + |
41 |
PluginServices.getText(this, "description") + ": " + |
42 |
"Returns true if the string parameter is a number.";
|
43 |
} |
44 |
} |