避免实体类空指针异常,并赋初值 可扩展


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;


import com.upward.hbnx.model.EChannel;


/**
 * 
 * @author xiaoyang 避免空指针
 * 避免实体类会报空指针的属性get方法,为其赋值
 * 
 */


public class InitBeanUtil {


private static InitBeanUtil init = null;
private final String START_SET = "set";
private final String START_GET = "get";
private final String START_IS = "is";
private final int START_THREE = 3; // "set"字符串长度 3


// 参数初始值---begin
private final String INIT_STRING = "";
private final int INIT_INT = 0;
private final double INIT_DOUBLE = 0.0;
private final float INIT_FLOAT = 0;
private final boolean INIT_BOOLEAN = true;
private final char INIT_CHAR = ' ';


private final BigDecimal INIT_BigDecimal = new BigDecimal("0.0");
private final Integer INIT_Integer = new Integer(0);
private final Double INIT_Double = new Double(0.0);
private final Float INIT_Float = new Float(0.0);
private final Boolean INIT_Boolean = new Boolean(true);
private final Character INIT_Character = new Character(' ');
private final java.sql.Date INIT_DateS = new java.sql.Date(
System.currentTimeMillis());
private final java.util.Date INIT_DateU = new java.util.Date(
System.currentTimeMillis());
private final java.sql.Timestamp INIT_Timestamp = new java.sql.Timestamp(
System.currentTimeMillis());
private final long INIT_Long = new Long(0);
@SuppressWarnings("rawtypes")
private final java.util.List INIT_List = new ArrayList();
// 参数初始值---end


// 参数类型---begin 封装类型给出完整名
private final String TYPE_String = "java.lang.String";
private final String TYPE_int = "int";
private final String TYPE_double = "double";
private final String TYPE_float = "float";
private final String TYPE_boolean = "boolean";
private final String TYPE_char = "char";
private final String TYPE_long = "long";
private final String TYPE_BigDecimal = "java.math.BigDecimal";
private final String TYPE_Integer = "java.lang.Integer";
private final String TYPE_Double = "java.lang.Double";
private final String TYPE_Float = "java.lang.Float";
private final String TYPE_Boolean = "java.lang.Boolean";
private final String TYPE_Character = "java.lang.Character";
private final String TYPE_DateS = "java.sql.Date";
private final String TYPE_DateU = "java.util.Date";
private final String TYPE_Timestamp = "java.sql.Timestamp";
private final String TYPE_List = "java.util.List";
// 参数类型---end
}
下载地址: http://download.csdn.net/detail/op_xiaoyang/6619893

你可能感兴趣的:(java)