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
package org.gvsig.expressionevaluator.impl.function.obj;
2

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

    
9
public class forFunction extends AbstractFunction {
10

    
11
    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
    }
20

    
21
    @Override
22
    public boolean useArgumentsInsteadObjects() {
23
        return true;
24
    }
25

    
26
    @Override
27
    public Object call(Interpreter interpreter, Object[] args) throws Exception {
28
        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
        }
41
        return body;
42
    }
43
    
44
}