package com.usoft.credit.util;

import com.usoft.credit.exception.CreditRuntimeException;
import org.apache.commons.lang3.StringUtils;

/**
 * 参数校验
 */
public abstract class VerifyParamsUtil {

	/**
	 * 对象是否为空
	 *
	 * @param object  对象
	 * @param message 错误消息
	 * @throws CreditRuntimeException
	 */
	public static void notNull(Object object, String message) throws CreditRuntimeException {
		if (object == null) {
			throw new CreditRuntimeException(-1, message);
		}
	}

	/**
	 * 是否有值
	 *
	 * @param text    文本
	 * @param message 错误消息
	 * @throws CreditRuntimeException
	 */
	public static void hasText(String text, String message) throws CreditRuntimeException {
		if (StringUtils.isBlank(text)) {
			throw new CreditRuntimeException(-1, message);
		}
	}

	/**
	 * 表达式是否正确
	 *
	 * @param expression 表达式
	 * @param message    错误消息
	 * @throws CreditRuntimeException
	 */
	public static void isTrue(boolean expression, String message) throws CreditRuntimeException {
		if (!expression) {
			throw new CreditRuntimeException(-1, message);
		}
	}
}
