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

History | View | Annotate | Download (1.52 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
                null,
19
                "Object",
20
                false
21
        );
22
    }
23

    
24
    @Override
25
    public boolean useArgumentsInsteadObjects() {
26
        return true;
27
    }
28

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