cn.tangjiabao.halodb.core.map.HaloGetMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of haloDb Show documentation
Show all versions of haloDb Show documentation
Orm whitch The highest development efficiency and Efficiency is the fastest
package cn.tangjiabao.halodb.core.map;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;
import cn.tangjiabao.halodb.utils.convert.ConvertUtils;
import cn.tangjiabao.halodb.utils.map.HashMap;
import cn.tangjiabao.halodb.utils.string.StringUtils;
/**
* 获取Map,扩展类型转化
* @author [email protected]
* @date 2015-1-12 上午10:51:33
*/
public class HaloGetMap extends HashMap implements Map {
/**
* @Fields serialVersionUID : TODO
*/
private static final long serialVersionUID = 8955941754407113803L;
public HaloGetMap() {
}
public HaloGetMap(Map map) {
if (null == map) {
map = new HaloGetMap();
}
for (Entry entry : map.entrySet()) {
this.set(entry.getKey(), entry.getValue());
}
}
public HaloGetMap set(String key, Object value) {
super.put(key, value);
return this;
}
public HaloGetMap put(String key, Object value) {
return this.set(key, value);
}
private String filterKey(String key) {
return key.replaceAll("3", "#");
}
public Object get(String key) {
key = filterKey(key);
if (key.indexOf("#") == -1) {
return super.get(key);
}
if (key.endsWith("#Integer")) {
key = StringUtils.substringBefore(key, "#Integer");
return getInteger(key);
}
if (key.endsWith("#Date")) {
key = StringUtils.substringBefore(key, "#Date");
return getDate(key);
}
if (key.endsWith("#Double")) {
key = StringUtils.substringBefore(key, "#Double");
return getDouble(key);
}
if (key.endsWith("#BigDecimal")) {
key = StringUtils.substringBefore(key, "#BigDecimal");
return getBigDecimal(key);
}
if (key.endsWith("#Float")) {
key = StringUtils.substringBefore(key, "#Float");
return getFloat(key);
}
if (key.endsWith("#Long")) {
key = StringUtils.substringBefore(key, "#Long");
return getLong(key);
}
if (key.endsWith("#Short")) {
key = StringUtils.substringBefore(key, "#Short");
return getShort(key);
}
if (key.endsWith("#String")) {
key = StringUtils.substringBefore(key, "#String");
return getString(key);
}
return super.get(key);
}
public Integer getInteger(String key) {
Object value = super.get(key);
return ConvertUtils.toInteger(value);
}
public Date getDate(String key) {
Object value = super.get(key);
return ConvertUtils.toDate(value);
}
public Boolean getBoolean(String key) {
Object value = super.get(key);
return ConvertUtils.toBoolean(value);
}
public BigDecimal getBigDecimal(String key) {
Object value = super.get(key);
return ConvertUtils.toBigDecimal(value);
}
public Double getDouble(String key) {
Object value = super.get(key);
return ConvertUtils.toDouble(value);
}
public Float getFloat(String key) {
Object value = super.get(key);
return ConvertUtils.toFloat(value);
}
public Short getShort(String key) {
Object value = super.get(key);
return ConvertUtils.toShort(value);
}
public Long getLong(String key) {
Object value = super.get(key);
return ConvertUtils.toLong(value);
}
public String getString(String key) {
Object value = super.get(key);
return ConvertUtils.toString(value);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy