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;
}
}
hashMap 的扩展
最新推荐文章于 2025-06-03 15:03:10 发布