package org.nl.acs.opc;


import java.util.Arrays;
import java.util.Objects;

/**
 * @author 20220102CG\noblelift
 */
public class ObjectUtl {
    private ObjectUtl() {
    }

    public static boolean isEquals(Object a, Object b) {
        if (a == null && b == null) {
            return true;
        } else if (a != null && b != null) {
            if (a.getClass().isArray()) {
                if (a instanceof boolean[]) {
                    return Arrays.equals((boolean[]) ((boolean[]) a), (boolean[]) ((boolean[]) b));
                } else if (a instanceof byte[]) {
                    return Arrays.equals((byte[]) ((byte[]) a), (byte[]) ((byte[]) b));
                } else if (a instanceof int[]) {
                    return Arrays.equals((int[]) ((int[]) a), (int[]) ((int[]) b));
                } else if (a instanceof long[]) {
                    return Arrays.equals((long[]) ((long[]) a), (long[]) ((long[]) b));
                } else if (a instanceof double[]) {
                    return Arrays.equals((double[]) ((double[]) a), (double[]) ((double[]) b));
                } else if (a instanceof short[]) {
                    return Arrays.equals((short[]) ((short[]) a), (short[]) ((short[]) b));
                } else if (a instanceof char[]) {
                    return Arrays.equals((char[]) ((char[]) a), (char[]) ((char[]) b));
                } else if (a instanceof float[]) {
                    return Arrays.equals((float[]) ((float[]) a), (float[]) ((float[]) b));
                } else if (a instanceof Object[]) {
                    return Arrays.equals((Object[]) ((Object[]) a), (Object[]) ((Object[]) b));
                } else {
                    throw new RuntimeException("未实现");
                }
            } else {
                return Objects.equals(a, b);
            }
        } else {
            return false;
        }
    }

    public static boolean isTrue(Boolean boolean_) {
        return boolean_ != null && isEquals(boolean_, true);
    }

    public static boolean isTrue(Boolean targetBoolean, boolean defaultBoolean) {
        return targetBoolean == null ? defaultBoolean : targetBoolean;
    }

    public static boolean isFalse(Boolean boolean_) {
        return boolean_ != null && isEquals(boolean_, false);
    }


    public static boolean isObject(Class<?> clazz) {
        if (clazz == null) {
            return false;
        } else if (clazz.getClass().isArray()) {
            return false;
        } else {
            return Object.class.isAssignableFrom(clazz);
        }
    }
}