MCPcopy Create free account
hub / github.com/SeanDragon/protools / Decimal

Class Decimal

common/src/main/java/pro/tools/data/decimal/Decimal.java:18–353  ·  view source on GitHub ↗

数值类型封装类 @author SeanDragon Create By 2017-04-13 14:22

Source from the content-addressed store, hash-verified

16 * Create By 2017-04-13 14:22
17 */
18public class Decimal extends Number implements Cloneable {
19
20 //region 全局变量
21
22 private BigDecimal bigDecimal;
23 private static volatile MathContext defaultMathContext = MathContext.DECIMAL128;
24 private final MathContext mathContext;
25
26 //endregion
27
28 /**
29 * region初始化模块
30 *
31 * @param initValue
32 */
33 public Decimal(Object initValue) {
34 this(initValue, defaultMathContext);
35 }
36
37 public Decimal(Object initValue, MathContext mathContext) {
38 this.mathContext = mathContext;
39 init(initValue);
40 }
41
42 public static MathContext getDefaultMathContext() {
43 return defaultMathContext;
44 }
45
46 public static void setDefaultMathContext(MathContext defaultMathContext) {
47 Decimal.defaultMathContext = defaultMathContext;
48 }
49
50 /**
51 * 便利生成方式,获取实例方法
52 *
53 * @param initValue
54 *
55 * @return
56 */
57 public static Decimal instance(Object initValue) {
58 return new Decimal(initValue);
59 }
60
61 //region 便利生成方式,获取实例方法
62
63 public static Decimal instance(Object initValue, MathContext mathContext) {
64 return new Decimal(initValue, mathContext);
65 }
66
67 private void init(Object initValue) {
68 if (initValue instanceof Decimal) {
69 Decimal value = (Decimal) initValue;
70 bigDecimal = ToolClone.clone(value.getBigDecimal());
71 } else if (initValue instanceof BigDecimal) {
72 bigDecimal = ToolClone.clone((BigDecimal) initValue);
73 } else if (initValue instanceof BigInteger) {
74 BigInteger value = (BigInteger) initValue;
75 bigDecimal = new BigDecimal(ToolClone.clone(value), mathContext);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected