hashMap 的扩展

public class SHashMap<K, V> implements Serializable,Cloneable {

    /**
     * hashMap工具类方便进行转换,改工具类具有所有HashMap的属性和方法
     */
    private static final long serialVersionUID = 1L;
    private HashMap<K, V> map;

    public SHashMap() {
        this.map = new HashMap();
    }

    public SHashMap(Map<K, V> map) {
        this.map = ((HashMap) map);
    }

    public void put(K key, V value) {
        this.map.put(key, value);
    }

    public void remove(K key) {
        this.map.remove(key);
    }

    public void removes(String keys) {
        if (!StringUtil.isNotNullStr(keys))
            return;
        String[] keyArr = keys.split(",");
        for (String key : keyArr)
            this.map.remove(key);
    }

    public V get(K key) {
        return this.map.get(key);
    }

    public boolean validKey(String key) {
        return  this.map.containsKey(key);
    }

    public Set<K> keySet() {
        return this.map.keySet();
    }

    public String getStr(String str) {
        String value =null;
        if (StringUtil.isNotNullStr(str)) {
            if (this.validKey(str)) {
                Object V = this.map.get(str);
                value =  !StringUtil.isValidObj(V) ? null : V.toString();
            }
        }else {
            value = null;
        }
        return value;
    }

    public Integer getInt(String str) {
        Integer value =null;
        if (StringUtil.isNotNullStr(str)) {
            if (this.validKey(str)) {
                Object V = this.map.get(str);
                value =  !StringUtil.isValidObj(V) ? null : Integer.parseInt(V.toString());
            }
        }else {
            value = null;
        }
        return value;
    }
    public BigDecimal getBig(String str) {
        BigDecimal value = new BigDecimal(0).setScale(2);
        if (StringUtil.isNotNullStr(str)) {
            if (this.validKey(str)) {
                Object V = this.map.get(str);
                value =  !StringUtil.isValidObj(V) ? null : BigDecimalHandler.get(Double.parseDouble(V.toString())).setScale(2);
            }
        }else {
            value = null;
        }
        return value;
    }

    @Override
    public SHashMap clone() throws CloneNotSupportedException {
        SHashMap target = new SHashMap();
         for(Iterator keyIt = this.keySet().iterator();keyIt.hasNext();){
             Object key = keyIt.next();
             target.put(key,this.get((K) key));
         }
        return  target;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值