package com.jy.framework.utils;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.jy.framework.exception.ServiceException;

public class AssertUtil {

    /**
     * 断言不为空
     */
    public static void notEmpty(Object value, String errStr, Object... params) {
        if (ObjectUtil.isEmpty(value)) {
            throw new ServiceException(StrUtil.format(errStr, params));
        }
    }

    /**
     * 断言为空
     */
    public static void isNull(Object value, String errStr, Object... params) {
        if (ObjectUtil.isNotNull(value)) {
            throw new ServiceException(StrUtil.format(errStr, params));
        }
    }

    /**
     * 断言不为空
     */
    public static void notNull(Object value, String errStr, Object... params) {
        if (ObjectUtil.isNull(value)) {
            throw new ServiceException(StrUtil.format(errStr, params));
        }
    }

    /**
     * 断言不为空
     */
    public static void notBlank(String value, String errStr, Object... params) {
        if (StrUtil.isBlank(value)) {
            throw new ServiceException(StrUtil.format(errStr, params));
        }
    }

    /**
     * 断言为真
     */
    public static void eqTrue(boolean value, String errStr, Object... params) {
        if (Boolean.FALSE.equals(value)) {
            throw new ServiceException(StrUtil.format(errStr, params));
        }
    }

    /**
     * 断言为假
     */
    public static void eqFalse(boolean value, String errStr, Object... params) {
        if (Boolean.TRUE.equals(value)) {
            throw new ServiceException(StrUtil.format(errStr, params));
        }
    }

    /**
     * 断言对象相等
     */
    public static void equals(Object obj1, Object obj2, String errStr, Object... params) {
        if (ObjectUtil.notEqual(obj1, obj2)) {
            throw new ServiceException(StrUtil.format(errStr, params));
        }
    }

    /**
     * 断言对象相等
     */
    public static void notEqual(Object obj1, Object obj2, String errStr, Object... params) {
        if (ObjectUtil.equal(obj1, obj2)) {
            throw new ServiceException(StrUtil.format(errStr, params));
        }
    }

}
