package com.ghy.common.utils;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

/**
 * @Date: 2024-09-26 22:49
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 参数校验工具类
 */
public class ObjectVerifyUtils {

    public static boolean isEmpty(Collection<?> coll) {
        return coll == null || coll.isEmpty();
    }


    public static boolean isNotEmpty(Collection<?> coll) {
        return !isEmpty(coll);
    }


    public static boolean isNull(Object... objs) {
        Object[] var1 = objs;
        int var2 = objs.length;

        for(int var3 = 0; var3 < var2; ++var3) {
            Object obj = var1[var3];
            if (isEmpty(obj)) {
                return true;
            }
        }

        return false;
    }

    public static boolean isNotNull(Object... obj) {
        return !isNull(obj);
    }

    public static boolean isNotEmpty(Object obj) {
        return !isEmpty(obj);
    }

    public static boolean isEmpty(Object obj) {
        if (obj == null) {
            return true;
        } else if (obj.getClass().isArray()) {
            return Array.getLength(obj) == 0;
        } else if (obj instanceof CharSequence) {
            return ((CharSequence)obj).length() == 0;
        } else if (obj instanceof Collection) {
            return ((Collection)obj).isEmpty();
        } else if (obj instanceof Map) {
            return ((Map)obj).isEmpty();
        } else if (obj instanceof Iterable) {
            return !((Iterable)obj).iterator().hasNext();
        } else if (obj instanceof Iterator) {
            return !((Iterator)obj).hasNext();
        } else {
            return false;
        }
    }
}
