gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / dataTypes / CoercionContextDecimalImpl.java @ 2080
History | View | Annotate | Download (1.42 KB)
1 |
package org.gvsig.tools.dataTypes; |
---|---|
2 |
|
3 |
import java.math.BigDecimal; |
4 |
import java.math.MathContext; |
5 |
import java.math.RoundingMode; |
6 |
import java.util.Locale; |
7 |
|
8 |
/**
|
9 |
*
|
10 |
* @author jjdelcerro
|
11 |
*/
|
12 |
public class CoercionContextDecimalImpl |
13 |
extends CoercionContextLocaleImpl
|
14 |
implements CoercionContextDecimal {
|
15 |
|
16 |
final MathContext mathContext; |
17 |
final int scale; |
18 |
final int roundMode; |
19 |
|
20 |
public CoercionContextDecimalImpl(Locale locale, int precision, int scale, int roundMode) { |
21 |
super(locale==null? Locale.ENGLISH:locale); |
22 |
if( precision<1 ) { |
23 |
this.mathContext = MathContext.UNLIMITED; |
24 |
} else {
|
25 |
this.mathContext = new MathContext(precision, RoundingMode.valueOf(roundMode)); |
26 |
} |
27 |
this.scale = -1; |
28 |
this.roundMode = roundMode;
|
29 |
} |
30 |
|
31 |
public CoercionContextDecimalImpl(Locale locale, int precision, int scale) { |
32 |
this(locale, precision, scale, BigDecimal.ROUND_UNNECESSARY); |
33 |
} |
34 |
|
35 |
public CoercionContextDecimalImpl(Locale locale) { |
36 |
super(locale==null? Locale.ENGLISH:locale); |
37 |
this.mathContext = MathContext.UNLIMITED; |
38 |
this.scale = -1; |
39 |
this.roundMode = BigDecimal.ROUND_UNNECESSARY; |
40 |
} |
41 |
|
42 |
@Override
|
43 |
public MathContext getMathContext() { |
44 |
return this.mathContext; |
45 |
} |
46 |
|
47 |
@Override
|
48 |
public int precision() { |
49 |
return this.mathContext.getPrecision(); |
50 |
} |
51 |
|
52 |
@Override
|
53 |
public int scale() { |
54 |
return this.scale; |
55 |
} |
56 |
|
57 |
@Override
|
58 |
public int roundMode() { |
59 |
return this.roundMode; |
60 |
} |
61 |
|
62 |
} |