package com.usoft.fin.grpc.utils;

import org.apache.commons.lang3.StringUtils;

/**
 * 参数校验
 *
 * @author: wangcanyi
 * @date: 2018-07-31 17:57
 */
public class VerifyParamsUtil {

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

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

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