JAVA验证值是否为空

/**
     * 
     * 验证值是否是空
     * 
     * @param object    验证值
     * @return  验证值是否是空
     */
    public static boolean isEmpty(Object object)
    {
        boolean isEmpty = false;
        
        if(object == null)
        {
            isEmpty = true;
        }
        //验证字符串类型
        else if(object instanceof String)
        {
            String validatedObject = (String)object;
            if(validatedObject == null || "".equals(validatedObject.trim()))
            {
                isEmpty = true;
            }
        }
        // 验证集合类型
        else if(object instanceof Collection)
        {
            Collection validatedObject = (Collection)object;
            if(validatedObject == null || validatedObject.size() == 0 )
            {
                isEmpty = true;
            }
        }
        // 验证Map类型
        else if(object instanceof Map)
        {
            Map validatedObject = (Map)object;
            if(validatedObject == null || validatedObject.size() == 0 )
            {
                isEmpty = true;
            }
        }
        // 验证日期类型
        else if(object instanceof Date)
        {
            Date validatedObject = (Date)object;
            if(validatedObject == null)
            {
                isEmpty = true;
            }
        }
        // 验证日期类型
        else if(object instanceof Timestamp)
        {
            Timestamp validatedObject = (Timestamp)object;
            if(validatedObject == null)
            {
                isEmpty = true;
            }
        }
        // 验证Set类型
        else if(object instanceof Set)
        {
            Set validatedObject = (Set)object;
            if(validatedObject == null || validatedObject.size() == 0)
            {
                isEmpty = true;
            }
        }
        
        return isEmpty;
    }

你可能感兴趣的:(JAVA验证值是否为空)