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