工具类

import org.apache.commons.collections.MapUtils;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by ye.r.x on 2019/12/31.
 */
public class ObjectUtil {
    private ObjectUtil() {

    }

    /**
     * 判断是否所有入参都为null
     * @param os
     * @return
     */
    public static boolean isAllNull(Object... os) {
        for (Object o : os) {
            if (o == null) {
                continue;
            }
            if (o instanceof Collection) {
                Collection collection = (Collection) o;
                if (!CollectionUtils.isEmpty(collection)) {
                    return false;
                }
            }
            if (o instanceof Map) {
                Map map = (Map) o;
                if (MapUtils.isNotEmpty(map)) {
                    return false;
                }
            }
            // 数组操作
            if (o.getClass().isArray()) {
                final int length = Array.getLength(o);
                for (int i = 0; i < length; i++) {
                    final Object item = Array.get(o, i);
                    if (item != null) {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容