package com.hbbh.adapter.utils; import java.lang.reflect.Array; import java.util.Collection; import java.util.Map; /** *
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 2016/9/28
 *     desc  : 判空相关工具类
 * 
*/ public class EmptyUtils { private EmptyUtils() { throw new UnsupportedOperationException("u can't instantiate me..."); } /** * 判断对象是否为空 * * @param obj 对象 * @return {@code true}: 为空
{@code false}: 不为空 */ public static boolean isEmpty(Object obj) { if (obj == null) { return true; } if (obj instanceof String && obj.toString().length() == 0) { return true; } if (obj.getClass().isArray() && Array.getLength(obj) == 0) { return true; } if (obj instanceof Collection && ((Collection) obj).isEmpty()) { return true; } if (obj instanceof Map && ((Map) obj).isEmpty()) { return true; } return false; } /** * 判断对象是否非空 * * @param obj 对象 * @return {@code true}: 非空
{@code false}: 空 */ public static boolean isNotEmpty(Object obj) { return !isEmpty(obj); } }