工具类

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;
    }
}

你可能感兴趣的:(工具类)