美文网首页
JAVA验证值是否为空

JAVA验证值是否为空

作者: 烟雨酱南 | 来源:发表于2021-07-14 11:21 被阅读0次
    /**
         * 
         * 验证值是否是空
         * 
         * @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验证值是否为空

          本文链接:https://www.haomeiwen.com/subject/whhypltx.html