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 / WhileFunction.java @ 44207

History | View | Annotate | Download (1.52 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

    
10
public class WhileFunction extends AbstractFunction {
11

    
12
    public static final String NAME = "WHILE";
13

    
14
    public WhileFunction() {
15
        super(Function.GROUP_PROGRAMMING, 
16
                NAME, 
17
                Range.is(2),
18
                "The while() function evaluate expression while the condition is true.",
19
                NAME+"( condition, expression )",
20
                null,
21
                "Object",
22
                false
23
        );
24
    }
25

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

    
31
    @Override
32
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
33
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
34
    }
35
    
36
    @Override
37
    public boolean allowConstantFolding() {
38
        return false;
39
    }    
40
    
41
    @Override
42
    public Object call(Interpreter interpreter, Codes args) throws Exception {
43
        Object body = null;
44
        boolean condition = getBoolean(interpreter, args, 0);
45
        while( condition ) {
46
            body = getObject(interpreter, args, 1);
47
            condition = getBoolean(interpreter, args, 0);
48
        }
49
        return body;
50
    }
51
    
52
}