Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extExpressionField / src / com / iver / cit / gvsig / project / documents / table / operators / Abs.java @ 27752

History | View | Annotate | Download (1.87 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
/**
13
 *
14
 * @author Vicente Caballero Navarro
15
 */
16
public class Abs extends AbstractOperator {
17
    public String addText(String s) {
18
        return toString() + "(" + s + ")";
19
    }
20

    
21
    public String toString() {
22
        return "abs";
23
    }
24

    
25
    public void eval(BSFManager interpreter) throws BSFException {
26
        interpreter.exec(ExpressionFieldExtension.JYTHON, null, -1, -1,
27
            "def abs(value):\n" +
28
            "  import java.lang.Math\n"+
29
            "  return java.lang.Math.abs(value)\n");
30
    }
31

    
32
    public boolean isEnable() {
33
        return (getType() == IOperator.NUMBER);
34
    }
35

    
36
    public double abs(double value) {
37
        return java.lang.Math.abs(value);
38
    }
39

    
40
    public String getDescription() {
41
        return PluginServices.getText(this, "parameter") + ": " +
42
        PluginServices.getText(this, "numeric_value") + "\n" +
43
        PluginServices.getText(this, "returns") + ": " +
44
        PluginServices.getText(this, "numeric_value") + "\n" +
45
        PluginServices.getText(this, "description") + ": " +
46
        "Returns the absolute value of a double value. If the argument is not negative, the argument is returned. " +
47
        "If the argument is negative, the negation of the argument is returned.\n " +
48
        "Special cases:\n" +
49
        "* If the argument is positive zero or negative zero, the result is positive zero.\n" +
50
        "* If the argument is infinite, the result is positive infinity.\n" +
51
        "* If the argument is NaN, the result is NaN.";
52
    }
53
}