Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.impl / src / main / java / org / gvsig / expressionevaluator / impl / function / programming / IIFFunction.java @ 44924

History | View | Annotate | Download (1.68 KB)

1
package org.gvsig.expressionevaluator.impl.function.programming;
2

    
3
import org.apache.commons.lang3.Range;
4
import org.gvsig.expressionevaluator.Codes;
5
import org.gvsig.expressionevaluator.Function;
6
import org.gvsig.expressionevaluator.Interpreter;
7
import org.gvsig.expressionevaluator.spi.AbstractFunction;
8

    
9
public class IIFFunction extends AbstractFunction {
10

    
11
    public static final String NAME = "IFF";
12
    
13
    public IIFFunction() {
14
        super(Function.GROUP_BOOLEAN, 
15
                NAME, 
16
                Range.between(2,3),
17
                "The IFF() function tests a specified numeric expression and returns one of two values, based on whether the expression tested was true or false.",
18
                "IF {{condition}} THEN\n  PASS\nELSE\n  PASS;\nEND IF\n",
19
                null,
20
                "Object",
21
                true
22
        );
23
    }
24

    
25
    @Override
26
    public boolean useArgumentsInsteadObjects() {
27
        return true;
28
    }
29

    
30
    @Override
31
    public boolean allowConstantFolding() {
32
        return false;
33
    }
34
    
35
    @Override
36
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
37
        throw new UnsupportedOperationException("Not supported yet."); 
38
    }
39
    
40
    @Override
41
    public Object call(Interpreter interpreter, Codes args) throws Exception {
42
        Object value;
43
        boolean condition = getBoolean(interpreter, args, 0);
44
        if( condition ) {
45
            value = getObject(interpreter, args, 1);
46
        } else {
47
            if( args.size()>2 && args.get(2)!=null ) {
48
                value = getObject(interpreter, args, 2);
49
            } else {
50
                value = null;
51
            }
52
        }
53
        return value;
54
    }
55
    
56
}