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 @ 45213

History | View | Annotate | Download (1.61 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 44924 jjdelcerro
                "WHILE {{condition}} BEGIN\n  PASS;\nEND WHILE\n",
20 44098 jjdelcerro
                null,
21
                "Object",
22
                false
23 43939 jjdelcerro
        );
24 43512 jjdelcerro
    }
25
26
    @Override
27 44738 jjdelcerro
    public boolean isHidden() {
28
      return true;
29
    }
30
31
    @Override
32 43939 jjdelcerro
    public boolean useArgumentsInsteadObjects() {
33
        return true;
34
    }
35
36
    @Override
37 43521 jjdelcerro
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
38 43939 jjdelcerro
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
39
    }
40
41
    @Override
42 44138 jjdelcerro
    public boolean allowConstantFolding() {
43
        return false;
44
    }
45
46
    @Override
47
    public Object call(Interpreter interpreter, Codes args) throws Exception {
48 43939 jjdelcerro
        Object body = null;
49
        boolean condition = getBoolean(interpreter, args, 0);
50
        while( condition ) {
51
            body = getObject(interpreter, args, 1);
52
            condition = getBoolean(interpreter, args, 0);
53 43512 jjdelcerro
        }
54 43939 jjdelcerro
        return body;
55 43512 jjdelcerro
    }
56
57
}