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 / obj / forFunction.java @ 43939

History | View | Annotate | Download (1.45 KB)

1 43939 jjdelcerro
package org.gvsig.expressionevaluator.impl.function.obj;
2 43512 jjdelcerro
3
import org.apache.commons.lang3.Range;
4 43939 jjdelcerro
import org.gvsig.expressionevaluator.Code.Caller.Arguments;
5
import org.gvsig.expressionevaluator.Function;
6 43521 jjdelcerro
import org.gvsig.expressionevaluator.Interpreter;
7 43512 jjdelcerro
import org.gvsig.expressionevaluator.spi.AbstractFunction;
8
9 43939 jjdelcerro
public class forFunction extends AbstractFunction {
10 43512 jjdelcerro
11 43939 jjdelcerro
    public forFunction() {
12
        super(
13
                Function.GROUP_OTHER,
14
                "FOR",
15
                Range.is(4),
16
                "The for() function evaluate body and incr while the condition is true.",
17
                "FOR( init, condition, incr, body )"
18
        );
19 43512 jjdelcerro
    }
20
21
    @Override
22 43939 jjdelcerro
    public boolean useArgumentsInsteadObjects() {
23
        return true;
24
    }
25
26
    @Override
27 43521 jjdelcerro
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
28 43939 jjdelcerro
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
29
    }
30
31
    @Override
32
    public Object call(Interpreter interpreter, Arguments args) throws Exception {
33
        Object body = null;
34
        Object init = getObject(interpreter, args, 0);
35
        boolean condition = getBoolean(interpreter, args, 1);
36
        while( condition ) {
37
            body = getObject(interpreter, args, 3);
38
            Object incr = getObject(interpreter, args, 2);
39
            condition = getBoolean(interpreter, args, 1);
40 43512 jjdelcerro
        }
41 43939 jjdelcerro
        return body;
42 43512 jjdelcerro
    }
43
44
}