com.iohao.game.common.kit.adapter.HuAssert Maven / Gradle / Ivy
package com.iohao.game.common.kit.adapter;
import java.util.function.Supplier;
/**
* @author 渔民小镇
* @date 2023-01-19
*/
class HuAssert {
public static T notNull(T object, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
return notNull(object, () -> new IllegalArgumentException(HuStrUtil.format(errorMsgTemplate, params)));
}
public static T notEmpty(T text) throws IllegalArgumentException {
return notEmpty(text, "[Assertion failed] - this String argument must have length; it must not be null or empty");
}
public static T notEmpty(T text, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
return notEmpty(text, () -> new IllegalArgumentException(HuStrUtil.format(errorMsgTemplate, params)));
}
public static T notEmpty(T text, Supplier errorSupplier) throws X {
if (HuStrUtil.isEmpty(text)) {
throw errorSupplier.get();
}
return text;
}
public static T notNull(T object, Supplier errorSupplier) throws X {
if (null == object) {
throw errorSupplier.get();
}
return object;
}
public static void isFalse(boolean expression, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
isFalse(expression, () -> new IllegalArgumentException(HuStrUtil.format(errorMsgTemplate, params)));
}
public static void isFalse(boolean expression, Supplier errorSupplier) throws X {
if (expression) {
throw errorSupplier.get();
}
}
}