root / trunk / libraries / libExpressions / src / main / java / org / gvsig / operators / Random.java @ 23299
History | View | Annotate | Download (1.31 KB)
1 |
package org.gvsig.operators; |
---|---|
2 |
|
3 |
import org.apache.bsf.BSFException; |
4 |
import org.apache.bsf.BSFManager; |
5 |
import org.gvsig.baseclasses.AbstractOperator; |
6 |
import org.gvsig.baseclasses.IOperator; |
7 |
import org.gvsig.expresions.EvalOperatorsTask; |
8 |
|
9 |
/**
|
10 |
* @author Vicente Caballero Navarro
|
11 |
*/
|
12 |
public class Random extends AbstractOperator{ |
13 |
|
14 |
public String addText(String s) { |
15 |
return s.concat(toString()+"()"); |
16 |
} |
17 |
public String toString() { |
18 |
return "random"; |
19 |
} |
20 |
public void eval(BSFManager interpreter) throws BSFException { |
21 |
// interpreter.eval(ExpressionFieldExtension.BEANSHELL,null,-1,-1,"double random(){return java.lang.Math.random();};");
|
22 |
interpreter.exec(EvalOperatorsTask.JYTHON,null,-1,-1,"def random():\n" + |
23 |
" import java.lang.Math\n" +
|
24 |
" return java.lang.Math.random()");
|
25 |
} |
26 |
public boolean isEnable() { |
27 |
return (getType()==IOperator.NUMBER);
|
28 |
} |
29 |
public String getTooltip(){ |
30 |
return "operator"+": "+addText("")+"\n"+getDescription(); |
31 |
} |
32 |
public String getDescription() { |
33 |
return "returns" + ": " + |
34 |
"numeric_value" + "\n" + |
35 |
"description" + ": " + |
36 |
"Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range.";
|
37 |
} |
38 |
} |