svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.jdbc / src / main / java / org / gvsig / fmap / dal / store / jdbc2 / spi / expressionbuilder / formatters / Iff.java @ 46104
History | View | Annotate | Download (1.65 KB)
1 | 45605 | omartinez | package org.gvsig.fmap.dal.store.jdbc2.spi.expressionbuilder.formatters; |
---|---|---|---|
2 | 44198 | jjdelcerro | |
3 | import java.text.MessageFormat; |
||
4 | import java.util.List; |
||
5 | import org.apache.commons.lang3.StringUtils; |
||
6 | import org.gvsig.expressionevaluator.ExpressionBuilder; |
||
7 | 45183 | omartinez | import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_IIF; |
8 | 44198 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
9 | import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
||
10 | import org.gvsig.expressionevaluator.Formatter; |
||
11 | import org.gvsig.fmap.dal.SQLBuilder; |
||
12 | |||
13 | /**
|
||
14 | *
|
||
15 | * @author jjdelcerro
|
||
16 | */
|
||
17 | 46104 | omartinez | public class Iff implements Formatter<Value> { |
18 | 44198 | jjdelcerro | |
19 | private final Formatter<Value> formatter; |
||
20 | private final SQLBuilder builder; |
||
21 | |||
22 | 45183 | omartinez | public Iff(SQLBuilder builder, Formatter<Value> formatter) { |
23 | 44198 | jjdelcerro | this.builder = builder;
|
24 | this.formatter = formatter;
|
||
25 | } |
||
26 | |||
27 | @Override
|
||
28 | public boolean canApply(Value value) { |
||
29 | if (value instanceof Function) { |
||
30 | if (value instanceof ExpressionBuilder.Function) { |
||
31 | 45183 | omartinez | return StringUtils.equalsIgnoreCase(FUNCTION_IIF, ((Function) value).name());
|
32 | 44198 | jjdelcerro | } |
33 | } |
||
34 | return false; |
||
35 | } |
||
36 | |||
37 | @Override
|
||
38 | public String format(Value function) { |
||
39 | 44750 | jjdelcerro | List<Value> parameters = ((Function) function).parameters();
|
40 | String p1 = parameters.get(0).toString(formatter); |
||
41 | String p2 = parameters.get(1).toString(formatter); |
||
42 | String p3 = parameters.get(2).toString(formatter); |
||
43 | 45183 | omartinez | |
44 | 44198 | jjdelcerro | String r = MessageFormat.format( |
45 | 45183 | omartinez | "CASEWHEN ( {0} , {1} , {2} )",
|
46 | 44198 | jjdelcerro | p1, |
47 | p3, |
||
48 | p2 |
||
49 | ); |
||
50 | return r;
|
||
51 | } |
||
52 | |||
53 | } |