/**
* @Description: 类型转化工具类
* @Date: 2019/2/20
*/
public class AdminConvertUtils extends ConvertUtils {
private static Logger logger = LoggerFactory.getLogger(AdminConvertUtils.class);
/**
* @Description: 将Object转化成Long
* @Param: [object]
* @Return: java.lang.Long
* @Date: 2019/2/20
*/
public static Long longConvert(Object object) {
//验证是否为无效字符串
if(isInvalid(object)) {
return null;
}
return (Long)(ConvertUtils.convert(object == null ? null : object.toString(), Long.class));
}
/**
* @Description: 将Object转换成String
* @Param: [object]
* @Return: java.lang.Long
* @Date: 2019/2/20
*/
public static String stringConvert(Object object) {
//验证是否为无效字符串
if(isInvalid(object)) {
return null;
}
return ConvertUtils.convert(object);
}
/**
* @Description: 将Object转换成Double
* @Param: [object]
* @Return: java.lang.Long
* @Date: 2019/2/20
*/
public static Double doubleConvert(Object object) {
//验证是否为无效字符串
if(isInvalid(object)) {
return null;
}
return (Double)(ConvertUtils.convert(object == null ? null : object.toString(), Double.class));
}
/**
* @Description: 将Object(时间字符串)转换成Long
* @Param: [object]
* @Return: java.lang.Long
* @Date: 2019/2/20
*/
public static Long dateToLongConvert(Object object) {
//验证是否为无效字符串
if(isInvalid(object)) {
return null;
}
return DateUtils.getSystemTimeDay(object.toString());
}
/**
* @Description: 将Object转化成Integer型
* @Param: [object]
* @Return: java.lang.Long
* @Date: 2019/2/20
*/
public static Integer intConvert(Object object) {
//验证是否为无效字符串
if(isInvalid(object)) {
return null;
}
if(StringUtils.isEmpty(object.toString())) {
return null;
}
return (Integer)(ConvertUtils.convert(object == null ? null : object.toString(), Integer.class));
}
/**
* @Description: 将Object转化成BigDecimal
* @Param: [object]
* @Return: java.math.BigDecimal
* @Date: 2019/2/21
*/
public static BigDecimal decimalConvert(Object object) {
//验证是否为无效字符串
if(isInvalid(object)) {
return null;
}
return (BigDecimal) (ConvertUtils.convert(object == null ? null : object.toString(), BigDecimal.class));
}
/**
* @Description: 验证是否为无效字符串
* @Param: [object]
* @Return: boolean
* @Date: 2019/2/20
*/
private static boolean isInvalid(Object object) {
if(object == null) {
logger.info("object:{}", "null");
return true;
}
logger.info("object:{}", object.toString());
if(object.toString().equalsIgnoreCase("null") || object.toString().equalsIgnoreCase("undefined")) {
return true;
}
return false;
}
public static void main(String[] arg) {
}
}
网友评论