svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.expressionevaluator / org.gvsig.expressionevaluator.lib / org.gvsig.expressionevaluator.lib.api / src / main / java / org / gvsig / expressionevaluator / spi / formatter / value / Cast.java @ 47062
History | View | Annotate | Download (1.38 KB)
1 | 44763 | jjdelcerro | package org.gvsig.expressionevaluator.spi.formatter.value; |
---|---|---|---|
2 | 44198 | jjdelcerro | |
3 | 47062 | fdiaz | import java.util.List; |
4 | 44198 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
5 | import org.gvsig.expressionevaluator.ExpressionBuilder; |
||
6 | 47062 | fdiaz | import static org.gvsig.expressionevaluator.ExpressionBuilder.FUNCTION_CAST; |
7 | 44198 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
8 | import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
||
9 | import org.gvsig.expressionevaluator.Formatter; |
||
10 | |||
11 | /**
|
||
12 | *
|
||
13 | * @author jjdelcerro
|
||
14 | */
|
||
15 | 47062 | fdiaz | public class Cast implements Formatter<Value> { |
16 | 44198 | jjdelcerro | |
17 | private final Formatter<Value> formatter; |
||
18 | |||
19 | 47062 | fdiaz | public Cast(Formatter<Value> formatter) { |
20 | 44198 | jjdelcerro | this.formatter = formatter;
|
21 | } |
||
22 | @Override
|
||
23 | public boolean canApply(ExpressionBuilder.Value value) { |
||
24 | if (value instanceof ExpressionBuilder.Function) { |
||
25 | 47062 | fdiaz | return StringUtils.equalsIgnoreCase(FUNCTION_CAST, ((Function) value).name());
|
26 | 44198 | jjdelcerro | } |
27 | return false; |
||
28 | } |
||
29 | |||
30 | @Override
|
||
31 | 44748 | jjdelcerro | public String format(Value function0) { |
32 | Function function = (Function) function0; |
||
33 | 44750 | jjdelcerro | StringBuilder builder = new StringBuilder(); |
34 | 47062 | fdiaz | List<Value> args = function.parameters();
|
35 | builder.append("CAST(");
|
||
36 | builder.append(args.get(0).toString(formatter));
|
||
37 | builder.append(" AS ");
|
||
38 | builder.append(((ExpressionBuilder.Constant)args.get(1)).value());
|
||
39 | builder.append(")");
|
||
40 | 44750 | jjdelcerro | return builder.toString();
|
41 | 44198 | jjdelcerro | } |
42 | |||
43 | } |