Revision 2080 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/dataTypes/DataTypeUtils.java
DataTypeUtils.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.dataTypes; |
2 | 2 |
|
3 |
import java.util.Locale; |
|
3 | 4 |
import org.gvsig.tools.ToolsLocator; |
5 |
import org.gvsig.tools.dataTypes.CoercionContextLocale; |
|
6 |
import org.gvsig.tools.dataTypes.CoercionContextDecimal; |
|
4 | 7 |
|
5 | 8 |
/** |
6 | 9 |
* |
... | ... | |
8 | 11 |
*/ |
9 | 12 |
public class DataTypeUtils { |
10 | 13 |
|
14 |
private static CoercionContextLocale COERCE_CONTEXT_DEFAULT_LOCALE ; |
|
15 |
private static CoercionContextDecimal COERCE_CONTEXT_DEFAULT_DECIMAL ; |
|
16 |
|
|
11 | 17 |
protected DataTypeUtils() { |
12 | 18 |
|
13 | 19 |
} |
20 |
|
|
21 |
public static CoercionContextLocale coerceContextLocale(Locale locale) { |
|
22 |
return new CoercionContextLocaleImpl(locale); |
|
23 |
} |
|
14 | 24 |
|
25 |
public static CoercionContextLocale coerceContextDefaultLocale() { |
|
26 |
if( COERCE_CONTEXT_DEFAULT_LOCALE==null || |
|
27 |
Locale.getDefault()!=COERCE_CONTEXT_DEFAULT_LOCALE.locale() ) { |
|
28 |
COERCE_CONTEXT_DEFAULT_LOCALE = new CoercionContextLocaleImpl(Locale.getDefault()); |
|
29 |
} |
|
30 |
return COERCE_CONTEXT_DEFAULT_LOCALE; |
|
31 |
} |
|
32 |
|
|
33 |
public static CoercionContextDecimal coerceContextDefaultDecimal() { |
|
34 |
if( COERCE_CONTEXT_DEFAULT_DECIMAL==null || |
|
35 |
Locale.getDefault()!=COERCE_CONTEXT_DEFAULT_DECIMAL.locale() ) { |
|
36 |
COERCE_CONTEXT_DEFAULT_DECIMAL = new CoercionContextDecimalImpl( |
|
37 |
Locale.getDefault() |
|
38 |
); |
|
39 |
} |
|
40 |
return COERCE_CONTEXT_DEFAULT_DECIMAL; |
|
41 |
} |
|
42 |
|
|
43 |
public static CoercionContextDecimal coerceContextDecimal(Locale locale) { |
|
44 |
if( COERCE_CONTEXT_DEFAULT_DECIMAL!=null || |
|
45 |
locale==COERCE_CONTEXT_DEFAULT_DECIMAL.locale() ) { |
|
46 |
return COERCE_CONTEXT_DEFAULT_DECIMAL; |
|
47 |
} |
|
48 |
return new CoercionContextDecimalImpl(locale); |
|
49 |
} |
|
50 |
|
|
51 |
public static CoercionContextDecimal coerceContextDecimal(Locale locale, int precision, int scale, int roundMode) { |
|
52 |
return new CoercionContextDecimalImpl(locale,precision, scale, roundMode); |
|
53 |
} |
|
54 |
|
|
15 | 55 |
public static Object coerce(int type, Object value, Object defaultValue) { |
16 | 56 |
DataTypesManager manager = ToolsLocator.getDataTypesManager(); |
17 | 57 |
DataType dataType = manager.get(type); |
Also available in: Unified diff