对象将移动到字符串、双精度、长整型、整型和布尔工具类
package com.myframework.utils;
importorg.Apache.com mons.lang3. string utils;
公共财务类铸造util {
//*
publicstaticstringcaststring{
returncaststring(obj,'');
}
//*
publicstaticstringcaststring (zldqc,字符串默认值) {
返回Obj!=null? string.valueof(obj ) :默认值;
}
//*
publicstaticdoublecastdouble{
returncastdouble(obj,0 );
}
//*
publicstaticdoublecastdouble (zldqc,双默认值) {
双值=默认值;
if(obj==null ) {
返回值;
}
stringstrvalue=caststring(obj;
if (string utils.is not empty (strvalue ) ) )
try {
value=double.parse double (strvalue );
}catch(numberformatexceptione ) )
value=默认值;
}
}
返回值;
}
//*
publicstaticlongcastlong(zldqc ) {
返回语句(obj,0 );
}
//*
publicstaticlongcastlong(zldqc,长默认值) {
long value=默认值;
if(obj==null ) {
返回值;
}
stringstrvalue=caststring(obj;
if (string utils.is not empty (strvalue ) ) )
try {
value=long.parselong(strvalue );
}catch(numberformatexceptione ) )
value=默认值;
}
}
返回值;
}
//*
publicstaticintcastint(zldqc ) {
返回语句(obj,0 );
}
//*
publicstaticintcastint(zldqc,int默认值) {
int value=默认值;
if(obj==null ) {
返回值;
}
stringstrvalue=caststring(obj;
if (string utils.is not empty (strvalue ) ) )
try {
value=integer.parseint (strvalue );
}catch(numberformatexceptione ) )
value=默认值;
}
}
返回值;
}
//*
publicstaticbooleancastboolean {
返回语句(obj,false );
}
//*
publicstaticbooleancastboolean (zldqc,布尔默认值) {
boolean value=默认值;
if(obj!=空) {
value=boolean.parse boolean (caststring (obj );
}
返回值;
}
}