Revision 45213
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/symboltable/SQLSymbolTable.java | ||
---|---|---|
63 | 63 |
import org.gvsig.expressionevaluator.impl.function.operator.SubstOperator; |
64 | 64 |
import org.gvsig.expressionevaluator.impl.function.predicate.IlikeOperator; |
65 | 65 |
import org.gvsig.expressionevaluator.impl.function.predicate.LikeOperator; |
66 |
import org.gvsig.expressionevaluator.impl.function.programming.IFFunction; |
|
66 | 67 |
import org.gvsig.expressionevaluator.impl.function.string.AsciiFunction; |
67 | 68 |
import org.gvsig.expressionevaluator.impl.function.string.CharFunction; |
68 | 69 |
import org.gvsig.expressionevaluator.impl.function.string.ConcatFunction; |
... | ... | |
194 | 195 |
this.addFunction(new ExtractFunction()); |
195 | 196 |
|
196 | 197 |
this.addFunction(new IIFFunction()); |
198 |
this.addFunction(new IFFunction()); |
|
197 | 199 |
this.addFunction(new IFNULLFunction()); |
198 | 200 |
this.addFunction(new FormatFunction()); |
199 | 201 |
|
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/IIFFunction.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.apache.commons.lang3.Range; |
4 | 4 |
import org.gvsig.expressionevaluator.Codes; |
5 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
5 | 6 |
import org.gvsig.expressionevaluator.Function; |
6 | 7 |
import org.gvsig.expressionevaluator.Interpreter; |
7 | 8 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
8 | 9 |
|
9 | 10 |
public class IIFFunction extends AbstractFunction { |
10 |
|
|
11 |
public static final String NAME = "IFF"; |
|
12 | 11 |
|
13 | 12 |
public IIFFunction() { |
14 | 13 |
super(Function.GROUP_BOOLEAN, |
15 |
NAME,
|
|
14 |
ExpressionBuilder.FUNCTION_IIF,
|
|
16 | 15 |
Range.between(2,3), |
17 |
"The IFF() function tests a specified numeric expression and returns one of two values, based on whether the expression tested was true or false.",
|
|
16 |
ExpressionBuilder.FUNCTION_IIF+"() function tests a specified numeric expression and returns one of two values, based on whether the expression tested was true or false.",
|
|
18 | 17 |
"IF {{condition}} THEN\n PASS\nELSE\n PASS;\nEND IF\n", |
19 | 18 |
null, |
20 | 19 |
"Object", |
... | ... | |
24 | 23 |
|
25 | 24 |
@Override |
26 | 25 |
public boolean useArgumentsInsteadObjects() { |
27 |
return true;
|
|
26 |
return false;
|
|
28 | 27 |
} |
29 | 28 |
|
30 | 29 |
@Override |
... | ... | |
34 | 33 |
|
35 | 34 |
@Override |
36 | 35 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
37 |
throw new UnsupportedOperationException("Not supported yet."); |
|
36 |
boolean condition = getBoolean(args, 0); |
|
37 |
|
|
38 |
if (condition) { |
|
39 |
return args[1]; |
|
40 |
} else { |
|
41 |
return args[2]; |
|
42 |
} |
|
43 |
|
|
38 | 44 |
} |
39 | 45 |
|
40 | 46 |
@Override |
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/IFFunction.java | ||
---|---|---|
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.ExpressionBuilder; |
|
6 |
import org.gvsig.expressionevaluator.Function; |
|
7 |
import org.gvsig.expressionevaluator.Interpreter; |
|
8 |
import org.gvsig.expressionevaluator.spi.AbstractFunction; |
|
9 |
|
|
10 |
public class IFFunction extends AbstractFunction { |
|
11 |
|
|
12 |
public IFFunction() { |
|
13 |
super(Function.GROUP_BOOLEAN, |
|
14 |
ExpressionBuilder.FUNCTION_IF, |
|
15 |
Range.between(2,3), |
|
16 |
ExpressionBuilder.FUNCTION_IF+"() function tests a specified numeric expression and returns one of two values, based on whether the expression tested was true or false.", |
|
17 |
"IF {{condition}} THEN\n PASS\nELSE\n PASS;\nEND IF\n", |
|
18 |
null, |
|
19 |
"Object", |
|
20 |
true |
|
21 |
); |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
public boolean useArgumentsInsteadObjects() { |
|
26 |
return true; |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
public boolean allowConstantFolding() { |
|
31 |
return false; |
|
32 |
} |
|
33 |
|
|
34 |
@Override |
|
35 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
36 |
throw new UnsupportedOperationException("Not supported yet."); |
|
37 |
} |
|
38 |
|
|
39 |
@Override |
|
40 |
public Object call(Interpreter interpreter, Codes args) throws Exception { |
|
41 |
Object value; |
|
42 |
boolean condition = getBoolean(interpreter, args, 0); |
|
43 |
if( condition ) { |
|
44 |
value = getObject(interpreter, args, 1); |
|
45 |
} else { |
|
46 |
if( args.size()>2 && args.get(2)!=null ) { |
|
47 |
value = getObject(interpreter, args, 2); |
|
48 |
} else { |
|
49 |
value = null; |
|
50 |
} |
|
51 |
} |
|
52 |
return value; |
|
53 |
} |
|
54 |
|
|
55 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestGrammarCompiler.java | ||
---|---|---|
135 | 135 |
|
136 | 136 |
Code code = compiler.compileExpression(source); |
137 | 137 |
link(code); |
138 |
assertEquals("IFF((\"V1\" = 11), LET('V2', 22))", code.toString());
|
|
138 |
assertEquals("IF((\"V1\" = 11), LET('V2', 22))", code.toString()); |
|
139 | 139 |
} |
140 | 140 |
|
141 | 141 |
public void testIfThenElse() { |
... | ... | |
145 | 145 |
|
146 | 146 |
Code code = compiler.compileExpression(source); |
147 | 147 |
link(code); |
148 |
assertEquals("IFF((\"V1\" = 11), LET('V2', 11), LET('V2', 22))", code.toString());
|
|
148 |
assertEquals("IF((\"V1\" = 11), LET('V2', 11), LET('V2', 22))", code.toString()); |
|
149 | 149 |
} |
150 | 150 |
|
151 | 151 |
public void testIfThenBlock() { |
... | ... | |
155 | 155 |
|
156 | 156 |
Code code = compiler.compileExpression(source); |
157 | 157 |
link(code); |
158 |
assertEquals("IFF((\"V1\" = 11), BLOCK(LET('V2', 22), LET('V1', 10)))", code.toString());
|
|
158 |
assertEquals("IF((\"V1\" = 11), BLOCK(LET('V2', 22), LET('V1', 10)))", code.toString()); |
|
159 | 159 |
} |
160 | 160 |
|
161 | 161 |
public void testWhile() { |
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.impl/src/test/java/org/gvsig/expressionevaluator/TestGrammarCompiler.java | ||
---|---|---|
111 | 111 |
|
112 | 112 |
Code code = compiler.compileExpression(source.toString()); |
113 | 113 |
link(code); |
114 |
checkEquals("testSelect2", "BLOCK(LET('X', 0), FOREACH('row', SELECT(TUPLE(), \"countries\", NULL, TUPLE(), TUPLE(), NULL), IFF((GETATTR(\"row\", 'LASTCENSUS') > 0), LET('X', (\"X\" + GETATTR(\"row\", 'LASTCENSUS'))))))", code.toString());
|
|
114 |
checkEquals("testSelect2", "BLOCK(LET('X', 0), FOREACH('row', SELECT(TUPLE(), \"countries\", NULL, TUPLE(), TUPLE(), NULL), IF((GETATTR(\"row\", 'LASTCENSUS') > 0), LET('X', (\"X\" + GETATTR(\"row\", 'LASTCENSUS'))))))", code.toString()); |
|
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
public void testSelect3() { |
... | ... | |
130 | 130 |
|
131 | 131 |
Code code = compiler.compileExpression(source.toString()); |
132 | 132 |
link(code); |
133 |
checkEquals("testSelect3", "BLOCK(LET('X', 0), FOREACH('row', SELECT(TUPLE(), \"countries\", NULL, TUPLE(), TUPLE(), NULL), IFF((GETATTR(\"row\", 'LASTCENSUS') > 0), LET('X', (\"X\" + GETATTR(\"row\", 'LASTCENSUS'))))))", code.toString());
|
|
133 |
checkEquals("testSelect3", "BLOCK(LET('X', 0), FOREACH('row', SELECT(TUPLE(), \"countries\", NULL, TUPLE(), TUPLE(), NULL), IF((GETATTR(\"row\", 'LASTCENSUS') > 0), LET('X', (\"X\" + GETATTR(\"row\", 'LASTCENSUS'))))))", code.toString()); |
|
134 | 134 |
} |
135 | 135 |
|
136 | 136 |
public void testSelectWhere() { |
Also available in: Unified diff