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 / BaseFormatter.java @ 44767
History | View | Annotate | Download (1.37 KB)
1 | 44763 | jjdelcerro | package org.gvsig.expressionevaluator.spi.formatter.value; |
---|---|---|---|
2 | 44198 | jjdelcerro | |
3 | import org.gvsig.expressionevaluator.ExpressionBuilder; |
||
4 | import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
||
5 | import org.gvsig.expressionevaluator.Formatter; |
||
6 | |||
7 | /**
|
||
8 | *
|
||
9 | * @author jjdelcerro
|
||
10 | */
|
||
11 | 44763 | jjdelcerro | public class BaseFormatter implements Formatter<Value> { |
12 | 44198 | jjdelcerro | |
13 | private final Formatter<ExpressionBuilder.Value>[] formatters; |
||
14 | |||
15 | 44767 | jjdelcerro | public BaseFormatter() {
|
16 | this(null); |
||
17 | } |
||
18 | |||
19 | 44763 | jjdelcerro | public BaseFormatter(Formatter<Value> formatter) { |
20 | 44767 | jjdelcerro | if( formatter==null || ExpressionBuilder.EMPTY_FORMATTER==formatter ) { |
21 | formatter = this;
|
||
22 | } |
||
23 | 44198 | jjdelcerro | this.formatters = new Formatter[]{ |
24 | 44767 | jjdelcerro | new Time(formatter), |
25 | new Date(formatter), |
||
26 | new Timestamp(formatter), |
||
27 | new Extract(formatter),
|
||
28 | new Getattr(formatter),
|
||
29 | new Tuple(formatter)
|
||
30 | 44198 | jjdelcerro | }; |
31 | } |
||
32 | |||
33 | @Override
|
||
34 | public boolean canApply(Value value) { |
||
35 | for (Formatter<Value> formatter : formatters) { |
||
36 | if (formatter.canApply(value)) {
|
||
37 | return true; |
||
38 | } |
||
39 | } |
||
40 | return false; |
||
41 | } |
||
42 | |||
43 | @Override
|
||
44 | public String format(Value value) { |
||
45 | for (Formatter<Value> formatter : formatters) { |
||
46 | if (formatter.canApply(value)) {
|
||
47 | return formatter.format(value);
|
||
48 | } |
||
49 | } |
||
50 | return value.toString(this); |
||
51 | } |
||
52 | |||
53 | } |