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 44138 jjdelcerro
package org.gvsig.expressionevaluator.impl.function.programming;
2 43512 jjdelcerro
3
import org.apache.commons.lang3.Range;
4 44138 jjdelcerro
import org.gvsig.expressionevaluator.Codes;
5 43939 jjdelcerro
import org.gvsig.expressionevaluator.Function;
6 43521 jjdelcerro
import org.gvsig.expressionevaluator.Interpreter;
7 43512 jjdelcerro
import org.gvsig.expressionevaluator.spi.AbstractFunction;
8
9 44138 jjdelcerro
10 43939 jjdelcerro
public class WhileFunction extends AbstractFunction {
11 43512 jjdelcerro
12 44138 jjdelcerro
    public static final String NAME = "WHILE";
13
14 43939 jjdelcerro
    public WhileFunction() {
15 44138 jjdelcerro
        super(Function.GROUP_PROGRAMMING,
16
                NAME,
17 43939 jjdelcerro
                Range.is(2),
18
                "The while() function evaluate expression while the condition is true.",
19 44138 jjdelcerro
                NAME+"( condition, expression )",
20 44098 jjdelcerro
                null,
21
                "Object",
22
                false
23 43939 jjdelcerro
        );
24 43512 jjdelcerro
    }
25
26
    @Override
27 43939 jjdelcerro
    public boolean useArgumentsInsteadObjects() {
28
        return true;
29
    }
30
31
    @Override
32 43521 jjdelcerro
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
33 43939 jjdelcerro
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
34
    }
35
36
    @Override
37 44138 jjdelcerro
    public boolean allowConstantFolding() {
38
        return false;
39
    }
40
41
    @Override
42
    public Object call(Interpreter interpreter, Codes args) throws Exception {
43 43939 jjdelcerro
        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 43512 jjdelcerro
        }
49 43939 jjdelcerro
        return body;
50 43512 jjdelcerro
    }
51
52
}