Helper.java
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.example.demo.util;
import org.springframework.lang.Nullable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Map;
public class Helper {
    /**
     * Object转BigDecimal类型-MRZ-2018年5月14日09:56:26
     *
     * @param value 要转的object类型
     * @return 转成的BigDecimal类型数据
     */
    static public  BigDecimal getBigDecimal(Object value) {
        BigDecimal ret = null;
        if (value != null) {
            if (value instanceof BigDecimal) {
                ret = (BigDecimal) value;
            } else if (value instanceof String) {
                ret = new BigDecimal((String) value);
            } else if (value instanceof BigInteger) {
                ret = new BigDecimal((BigInteger) value);
            } else if (value instanceof Number) {
                ret = new BigDecimal(((Number) value).doubleValue());
            } else {
                throw new ClassCastException("Not possible to coerce [" + value + "] from class " + value.getClass() + " into a BigDecimal.");
            }
        }
        return ret;
    }
    /**
     * 判断map是否包含key,包含返回KEY值,不包含返回NULL
     * @param map
     * @param key
     * @return
     */
    @Nullable static public Object CheckMapKey(Map map, String key){
        boolean contains = map.containsKey(key);    //判断是否包含指定的键值
        if (contains) {         //如果条件为真
            return map.get(key);
        } else {
            return null;
        }
    }
}