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 @ 44738
History | View | Annotate | Download (1.59 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 |
|
10 |
public class WhileFunction extends AbstractFunction { |
11 |
|
12 |
public static final String NAME = "WHILE"; |
13 |
|
14 |
public WhileFunction() {
|
15 |
super(Function.GROUP_PROGRAMMING,
|
16 |
NAME, |
17 |
Range.is(2),
|
18 |
"The while() function evaluate expression while the condition is true.",
|
19 |
NAME+"( condition, expression )",
|
20 |
null,
|
21 |
"Object",
|
22 |
false
|
23 |
); |
24 |
} |
25 |
|
26 |
@Override
|
27 |
public boolean isHidden() { |
28 |
return true; |
29 |
} |
30 |
|
31 |
@Override
|
32 |
public boolean useArgumentsInsteadObjects() { |
33 |
return true; |
34 |
} |
35 |
|
36 |
@Override
|
37 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
38 |
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. |
39 |
} |
40 |
|
41 |
@Override
|
42 |
public boolean allowConstantFolding() { |
43 |
return false; |
44 |
} |
45 |
|
46 |
@Override
|
47 |
public Object call(Interpreter interpreter, Codes args) throws Exception { |
48 |
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 |
} |
54 |
return body;
|
55 |
} |
56 |
|
57 |
} |