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 / BreakFunction.java @ 47115
History | View | Annotate | Download (1.79 KB)
1 |
package org.gvsig.expressionevaluator.impl.function.programming; |
---|---|
2 |
|
3 |
import org.apache.commons.lang3.Range; |
4 |
import org.gvsig.expressionevaluator.Code; |
5 |
import org.gvsig.expressionevaluator.Codes; |
6 |
import org.gvsig.expressionevaluator.Formatter; |
7 |
import org.gvsig.expressionevaluator.Function; |
8 |
import org.gvsig.expressionevaluator.Interpreter; |
9 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
10 |
|
11 |
public class BreakFunction extends AbstractFunction { |
12 |
|
13 |
public static final String NAME = "BREAK"; |
14 |
|
15 |
public BreakFunction() {
|
16 |
super(Function.GROUP_PROGRAMMING,
|
17 |
NAME, |
18 |
Range.between(0, Integer.MAX_VALUE), |
19 |
null,
|
20 |
"BREAK {{value}}",
|
21 |
null,
|
22 |
"Object",
|
23 |
false
|
24 |
); |
25 |
} |
26 |
|
27 |
@Override
|
28 |
public boolean isHidden() { |
29 |
return true; |
30 |
} |
31 |
|
32 |
@Override
|
33 |
public boolean allowConstantFolding() { |
34 |
return false; |
35 |
} |
36 |
|
37 |
@Override
|
38 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
39 |
|
40 |
switch(args.length) {
|
41 |
case 0: |
42 |
throw new BreakException(null); |
43 |
case 1: |
44 |
throw new BreakException(args[0]); |
45 |
default:
|
46 |
throw new BreakException(args); |
47 |
} |
48 |
} |
49 |
|
50 |
public static class BreakException extends RuntimeException { |
51 |
|
52 |
private final Object value; |
53 |
|
54 |
public BreakException(Object value) { |
55 |
this.value = value;
|
56 |
} |
57 |
|
58 |
public Object getValue() { |
59 |
return this.value; |
60 |
} |
61 |
} |
62 |
|
63 |
@Override
|
64 |
public String toString(Codes args, Formatter<Code> formatter) { |
65 |
StringBuilder builder = new StringBuilder(); |
66 |
builder.append("BREAK");
|
67 |
return builder.toString();
|
68 |
} |
69 |
|
70 |
} |