您的位置:首页 > 其它

CheckUtil类 判断工具类 本次开发中总结的工具类

2014-02-08 15:27 232 查看
public class CheckUtil

{

    /**

     * 判断字符串为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean isEmpty(String str)

    {

        return null == str || str.trim().length()==0?true:false;

    }

    

    /**

     * 判断对象为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean isEmpty(Object obj)

    {

        return null == obj ? true : false;

    }

    /**

     * 判断集合类为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean isEmpty(Collection c)

    {

        return CollectionUtils.isEmpty(c);

    }

    

    /**

     * 判断Map为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean isEmpty(Map map)

    {

        

        return MapUtils.isEmpty(map);

    }

    /**

     * 判断数组为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean isEmpty(Object[] arr)

    {

        return ArrayUtils.isEmpty(arr);

    }

    

    

    /**

     * 判断集合不为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean notEmpty(Collection c)

    {

        

        return !isEmpty(c);

    }

    /**

     * 判断对象不为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean notEmpty(Object c)

    {

        

        return !isEmpty(c);

    }

    

    /**

     * 判断数组不为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean notEmpty(Object[] c)

    {

        

        return !isEmpty(c);

    }

    /**

     * 判断Map不为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean notEmpty(Map c)

    {

        

        return !isEmpty(c);

    }

    

    /**

     * 判断字符串不为空

     * <一句话功能简述>

     * <功能详细描述>

     * @author tangzhang 

     * @date 2013-11-9 下午3:58:10 

     * @param str

     * @return

     * @see [类、类#方法、类#成员]

     */

    public static boolean notEmpty(String c)

    {

        return !isEmpty(c);

    }

    public static boolean isMobile(String str)

    {

        Pattern p = Pattern.compile("^1[3|4|5|8][0-9]\\d{8}$");

        Matcher m = p.matcher(str);

        return m.matches();

    }

    public static boolean notMobile(String str)

    {

      

        return !isMobile(str);

    }

    public static boolean isEmail(String email)

    {

        if (StringUtils.isBlank(email))

            return false;

        email = email.toLowerCase();

       

        if(!isLimitEmail(email))

            return false;

        Pattern emailer = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");

        return emailer.matcher(email).matches();

    }

    private static boolean isLimitEmail(String email)

    {

        String[] emails = {"@163.com","@126.com","@sohu.com","@yeah.net","@gmail.com","@yahoo.cn","@qq.com","@sina.com.cn","@hotmail.com","@tom.cn","@live.cn"};

        for(String e : emails)

        {

            if(email.endsWith(e))

            {

                return true;

            }

        }

        return false;

    }

    public static  int getLength(String s)

    {

        s = s.replaceAll("[^\\x00-\\xff]", "**");

        int length = s.length();

        return length;

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息