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 / ForFunction.java @ 44738
History | View | Annotate | Download (1.71 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
---|---|
2 |
|
3 |
import org.apache.commons.lang3.Range; |
4 |
import org.gvsig.expressionevaluator.Codes; |
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 static final String NAME = "FOR"; |
12 |
|
13 |
public ForFunction() {
|
14 |
super(Function.GROUP_PROGRAMMING,
|
15 |
NAME, |
16 |
Range.is(4),
|
17 |
"The for() function evaluate body and incr while the condition is true.",
|
18 |
NAME+"( init, condition, incr, body )",
|
19 |
null,
|
20 |
"Object",
|
21 |
false
|
22 |
); |
23 |
} |
24 |
|
25 |
@Override
|
26 |
public boolean isHidden() { |
27 |
return true; |
28 |
} |
29 |
|
30 |
@Override
|
31 |
public boolean useArgumentsInsteadObjects() { |
32 |
return true; |
33 |
} |
34 |
|
35 |
@Override
|
36 |
public boolean allowConstantFolding() { |
37 |
return false; |
38 |
} |
39 |
|
40 |
@Override
|
41 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
42 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
43 |
} |
44 |
|
45 |
@Override
|
46 |
public Object call(Interpreter interpreter, Codes args) throws Exception { |
47 |
Object body = null; |
48 |
Object init = getObject(interpreter, args, 0); |
49 |
boolean condition = getBoolean(interpreter, args, 1); |
50 |
while( condition ) {
|
51 |
body = getObject(interpreter, args, 3);
|
52 |
Object incr = getObject(interpreter, args, 2); |
53 |
condition = getBoolean(interpreter, args, 1);
|
54 |
} |
55 |
return body;
|
56 |
} |
57 |
|
58 |
} |