赞
踩
public class CustomHashMap<K, V> extends java.util.HashMap<K, V> {
private static final long serialVersionUID = 1864601112267440506L;
@SuppressWarnings({ "rawtypes", "unchecked" })
public static CustomHashMap convert(HashMap map){
CustomHashMap result = new CustomHashMap();
for(Object key : map.keySet()) {
result.put(key, map.get(key));
}
return result;
}
public String getString(K key){
Object object = get(key);
if(object != null){
return object.toString();
}
return null;
}
public String getString(K key, String defaultValue){
Object object = get(key);
if(object != null){
return object.toString();
}
return defaultValue;
}
public Boolean getBoolean(K key){
Object object = get(key);
if(object != null){
return (Boolean)object;
}
return false;
}
public int getInt(K key){
Object object = get(key);
if(object != null){
return NumberUtils.toInt(object.toString());
}
return 0;
}
public Integer getInteger(K key){
Object object = get(key);
if(object != null){
return NumberUtils.toInt(object.toString());
}
return null;
}
public BigInteger getBigInteger(K key){
Object object = get(key);
if(object != null){
return BigInteger.valueOf(Integer.valueOf(object.toString()));
}
return BigInteger.ZERO;
}
public BigDecimal getBigDecimal(K key) {
Object object = get(key);
if(object != null){
return BigDecimal.valueOf(Double.valueOf(object.toString()));
}
return BigDecimal.ZERO;
}
public Long getLong(K key){
Object object = get(key);
if(object != null){
return Long.valueOf(object.toString());
}
return null;
}
public Float getFloat(K key){
Object object = get(key);
if(object != null){
return Float.valueOf(object.toString());
}
return null;
}
public Double getDouble(K key){
Object object = get(key);
if(object != null){
return Double.valueOf(object.toString());
}
return null;
}
public Date getDate(K key) {
Object object = get(key);
if(object != null){
return (Date)object;
}
return null;
}
public Time getTime(K key) {
Object object = get(key);
if(object != null){
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
java.util.Date date = null;
try {
date = sdf.parse(object.toString());
return new Time(date.getTime());
} catch (ParseException e) {
return null;
}
}
return null;
}
@SuppressWarnings("unchecked")
public HashMap<Object, Object> getHashMap(K key) {
Object object = get(key);
if(object != null){
return (HashMap<Object, Object>)object;
}
return null;
}
@SuppressWarnings("unchecked")
public CustomHashMap<Object, Object> getCustomHashMap(K key) {
Object object = get(key);
if(object != null){
return (CustomHashMap<Object, Object>)object;
}
return null;
}
}
有什么需要改善的地方,希望大家指出来!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。