Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
*
* @param expression 布尔值
* @throws IllegalArgumentException if expression is {@code false}
*/
public static void isFalse(boolean expression) throws IllegalArgumentException {
isFalse(expression, "[Assertion failed] - this expression must be false");
}
/**
* 断言对象是否为{@code null} ,如果不为{@code null} 抛出指定类型异常
* 并使用指定的函数获取错误信息返回
*
* Assert.isNull(value, ()->{
* // to query relation message
* return new IllegalArgumentException("relation message to return");
* });
*
*
* @param 异常类型
* @param object 被检查的对象
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @throws X if the object is not {@code null}
* @since 5.4.5
*/
public static void isNull(Object object, Supplier errorSupplier) throws X {
if (null != object) {
throw errorSupplier.get();
}
}
/**
* 断言对象是否为{@code null} ,如果不为{@code null} 抛出{@link IllegalArgumentException} 异常
*
*
* Assert.isNull(value, "The value must be null");
*
*
* @param object 被检查的对象
* @param errorMsgTemplate 消息模板,变量使用{}表示
* @param params 参数列表
* @throws IllegalArgumentException if the object is not {@code null}
*/
public static void isNull(Object object, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
isNull(object, () -> new IllegalArgumentException(StrUtil.format(errorMsgTemplate, params)));
}
/**
* 断言对象是否为{@code null} ,如果不为{@code null} 抛出{@link IllegalArgumentException} 异常
*
*
* Assert.isNull(value);
*
*
* @param object 被检查对象
* @throws IllegalArgumentException if the object is not {@code null}
*/
public static void isNull(Object object) throws IllegalArgumentException {
isNull(object, "[Assertion failed] - the object argument must be null");
}
// ----------------------------------------------------------------------------------------------------------- Check not null
/**
* 断言对象是否不为{@code null} ,如果为{@code null} 抛出指定类型异常
* 并使用指定的函数获取错误信息返回
*
* Assert.notNull(clazz, ()->{
* // to query relation message
* return new IllegalArgumentException("relation message to return");
* });
*
*
* @param 被检查对象泛型类型
* @param 异常类型
* @param object 被检查对象
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @return 被检查后的对象
* @throws X if the object is {@code null}
* @since 5.4.5
*/
public static T notNull(T object, Supplier errorSupplier) throws X {
if (null == object) {
throw errorSupplier.get();
}
return object;
}
/**
* 断言对象是否不为{@code null} ,如果为{@code null} 抛出{@link IllegalArgumentException} 异常 Assert that an object is not {@code null} .
*
*
* Assert.notNull(clazz, "The class must not be null");
*
*
* @param 被检查对象泛型类型
* @param object 被检查对象
* @param errorMsgTemplate 错误消息模板,变量使用{}表示
* @param params 参数
* @return 被检查后的对象
* @throws IllegalArgumentException if the object is {@code null}
*/
public static T notNull(T object, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
return notNull(object, () -> new IllegalArgumentException(StrUtil.format(errorMsgTemplate, params)));
}
/**
* 断言对象是否不为{@code null} ,如果为{@code null} 抛出{@link IllegalArgumentException} 异常
*
*
* Assert.notNull(clazz);
*
*
* @param 被检查对象类型
* @param object 被检查对象
* @return 非空对象
* @throws IllegalArgumentException if the object is {@code null}
*/
public static T notNull(T object) throws IllegalArgumentException {
return notNull(object, "[Assertion failed] - this argument is required; it must not be null");
}
// ----------------------------------------------------------------------------------------------------------- Check empty
/**
* 检查给定字符串是否为空,为空抛出自定义异常,并使用指定的函数获取错误信息返回。
*
* Assert.notEmpty(name, ()->{
* // to query relation message
* return new IllegalArgumentException("relation message to return");
* });
*
*
* @param 异常类型
* @param 字符串类型
* @param text 被检查字符串
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @return 非空字符串
* @throws X 被检查字符串为空抛出此异常
* @see StrUtil#isNotEmpty(CharSequence)
* @since 5.4.5
*/
public static T notEmpty(T text, Supplier errorSupplier) throws X {
if (StrUtil.isEmpty(text)) {
throw errorSupplier.get();
}
return text;
}
/**
* 检查给定字符串是否为空,为空抛出 {@link IllegalArgumentException}
*
*
* Assert.notEmpty(name, "Name must not be empty");
*
*
* @param 字符串类型
* @param text 被检查字符串
* @return 被检查的字符串
* @throws IllegalArgumentException 被检查字符串为空
* @see StrUtil#isNotEmpty(CharSequence)
*/
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");
}
/**
* 检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出自定义异常。
* 并使用指定的函数获取错误信息返回
*
* Assert.notBlank(name, ()->{
* // to query relation message
* return new IllegalArgumentException("relation message to return");
* });
*
*
* @param 异常类型
* @param 字符串类型
* @param text 被检查字符串
* @param errorMsgSupplier 错误抛出异常附带的消息生产接口
* @return 非空字符串
* @throws X 被检查字符串为空白
* @see StrUtil#isNotBlank(CharSequence)
*/
public static T notBlank(T text, Supplier errorMsgSupplier) throws X {
if (StrUtil.isBlank(text)) {
throw errorMsgSupplier.get();
}
return text;
}
/**
* 检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出 {@link IllegalArgumentException}
*
*
* Assert.notBlank(name, "Name must not be blank");
*
*
* @param 字符串类型
* @param text 被检查字符串
* @return 非空字符串
* @throws IllegalArgumentException 被检查字符串为空白
* @see StrUtil#isNotBlank(CharSequence)
*/
public static T notBlank(T text) throws IllegalArgumentException {
return notBlank(text, "[Assertion failed] - this String argument must have text; it must not be null, empty, or blank");
}
/**
* 断言给定字符串是否不被另一个字符串包含(即是否为子串)
* 并使用指定的函数获取错误信息返回
*
* Assert.notContain(name, "rod", ()->{
* // to query relation message
* return new IllegalArgumentException("relation message to return ");
* });
*
* Assert.notEmpty(array, ()->{
* // to query relation message
* return new IllegalArgumentException("relation message to return");
* });
*
*
* @param 数组元素类型
* @param 异常类型
* @param array 被检查的数组
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @return 被检查的数组
* @throws X if the object array is {@code null} or has no elements
* @see ArrayUtil#isNotEmpty(Object[])
* @since 5.4.5
*/
public static T[] notEmpty(T[] array, Supplier errorSupplier) throws X {
if (ArrayUtil.isEmpty(array)) {
throw errorSupplier.get();
}
return array;
}
/**
* 断言给定数组是否包含元素,数组必须不为 {@code null} 且至少包含一个元素
*
*
* Assert.notEmpty(array, "The array must have elements");
*
*
* @param 数组元素类型
* @param array 被检查的数组
* @param errorMsgTemplate 异常时的消息模板
* @param params 参数列表
* @return 被检查的数组
* @throws IllegalArgumentException if the object array is {@code null} or has no elements
*/
public static T[] notEmpty(T[] array, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
return notEmpty(array, () -> new IllegalArgumentException(StrUtil.format(errorMsgTemplate, params)));
}
/**
* 断言给定数组是否包含元素,数组必须不为 {@code null} 且至少包含一个元素
*
*
* Assert.notEmpty(array, "The array must have elements");
*
*
* @param 数组元素类型
* @param array 被检查的数组
* @return 被检查的数组
* @throws IllegalArgumentException if the object array is {@code null} or has no elements
*/
public static T[] notEmpty(T[] array) throws IllegalArgumentException {
return notEmpty(array, "[Assertion failed] - this array must not be empty: it must contain at least 1 element");
}
/**
* 断言给定数组是否不包含{@code null}元素,如果数组为空或 {@code null}将被认为不包含
* 并使用指定的函数获取错误信息返回
*
* Assert.noNullElements(array, ()->{
* // to query relation message
* return new IllegalArgumentException("relation message to return ");
* });
*
*
* @param 数组元素类型
* @param 异常类型
* @param array 被检查的数组
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @return 被检查的数组
* @throws X if the object array contains a {@code null} element
* @see ArrayUtil#hasNull(Object[])
* @since 5.4.5
*/
public static T[] noNullElements(T[] array, Supplier errorSupplier) throws X {
if (ArrayUtil.hasNull(array)) {
throw errorSupplier.get();
}
return array;
}
/**
* 断言给定数组是否不包含{@code null}元素,如果数组为空或 {@code null}将被认为不包含
*
*
* Assert.noNullElements(array, "The array must not have null elements");
*
*
* @param 数组元素类型
* @param array 被检查的数组
* @param errorMsgTemplate 异常时的消息模板
* @param params 参数列表
* @return 被检查的数组
* @throws IllegalArgumentException if the object array contains a {@code null} element
*/
public static T[] noNullElements(T[] array, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
return noNullElements(array, () -> new IllegalArgumentException(StrUtil.format(errorMsgTemplate, params)));
}
/**
* 断言给定数组是否不包含{@code null}元素,如果数组为空或 {@code null}将被认为不包含
*
*
* Assert.noNullElements(array);
*
*
* @param 数组元素类型
* @param array 被检查的数组
* @return 被检查的数组
* @throws IllegalArgumentException if the object array contains a {@code null} element
*/
public static T[] noNullElements(T[] array) throws IllegalArgumentException {
return noNullElements(array, "[Assertion failed] - this array must not contain any null elements");
}
/**
* 断言给定集合非空
* 并使用指定的函数获取错误信息返回
*
* Assert.notEmpty(collection, ()->{
* // to query relation message
* return new IllegalArgumentException("relation message to return");
* });
*
*
* @param 集合元素类型
* @param 集合类型
* @param 异常类型
* @param collection 被检查的集合
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @return 非空集合
* @throws X if the collection is {@code null} or has no elements
* @see CollUtil#isNotEmpty(Iterable)
* @since 5.4.5
*/
public static , X extends Throwable> T notEmpty(T collection, Supplier errorSupplier) throws X {
if (CollUtil.isEmpty(collection)) {
throw errorSupplier.get();
}
return collection;
}
/**
* 断言给定集合非空
*
*
* Assert.notEmpty(collection, "Collection must have elements");
*
*
* @param 集合元素类型
* @param 集合类型
* @param collection 被检查的集合
* @param errorMsgTemplate 异常时的消息模板
* @param params 参数列表
* @return 非空集合
* @throws IllegalArgumentException if the collection is {@code null} or has no elements
*/
public static > T notEmpty(T collection, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
return notEmpty(collection, () -> new IllegalArgumentException(StrUtil.format(errorMsgTemplate, params)));
}
/**
* 断言给定集合非空
*
*
* Assert.notEmpty(collection);
*
*
* @param 集合元素类型
* @param 集合类型
* @param collection 被检查的集合
* @return 被检查集合
* @throws IllegalArgumentException if the collection is {@code null} or has no elements
*/
public static > T notEmpty(T collection) throws IllegalArgumentException {
return notEmpty(collection, "[Assertion failed] - this collection must not be empty: it must contain at least 1 element");
}
/**
* 断言给定Map非空
* 并使用指定的函数获取错误信息返回
*
* Assert.notEmpty(map, ()->{
* // to query relation message
* return new IllegalArgumentException("relation message to return");
* });
*
*
* @param Key类型
* @param Value类型
* @param Map类型
* @param 异常类型
* @param map 被检查的Map
* @param errorSupplier 错误抛出异常附带的消息生产接口
* @return 被检查的Map
* @throws X if the map is {@code null} or has no entries
* @see MapUtil#isNotEmpty(Map)
* @since 5.4.5
*/
public static , X extends Throwable> T notEmpty(T map, Supplier errorSupplier) throws X {
if (MapUtil.isEmpty(map)) {
throw errorSupplier.get();
}
return map;
}
/**
* 断言给定Map非空
*
*
* Assert.notEmpty(map, "Map must have entries");
*
*
* @param Key类型
* @param Value类型
* @param Map类型
* @param map 被检查的Map
* @param errorMsgTemplate 异常时的消息模板
* @param params 参数列表
* @return 被检查的Map
* @throws IllegalArgumentException if the map is {@code null} or has no entries
*/
public static > T notEmpty(T map, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
return notEmpty(map, () -> new IllegalArgumentException(StrUtil.format(errorMsgTemplate, params)));
}
/**
* 断言给定Map非空
*
*
* Assert.notEmpty(map, "Map must have entries");
*
*
* @param Key类型
* @param Value类型
* @param Map类型
* @param map 被检查的Map
* @return 被检查的Map
* @throws IllegalArgumentException if the map is {@code null} or has no entries
*/
public static > T notEmpty(T map) throws IllegalArgumentException {
return notEmpty(map, "[Assertion failed] - this map must not be empty; it must contain at least one entry");
}
/**
* 断言给定对象是否是给定类的实例
*
*
* Assert.instanceOf(Foo.class, foo);
*
*
* @param 被检查对象泛型类型
* @param type 被检查对象匹配的类型
* @param obj 被检查对象
* @return 被检查的对象
* @throws IllegalArgumentException if the object is not an instance of clazz
* @see Class#isInstance(Object)
*/
public static T isInstanceOf(Class> type, T obj) {
return isInstanceOf(type, obj, "Object [{}] is not instanceof [{}]", obj, type);
}
/**
* 断言给定对象是否是给定类的实例
*
*
* Assert.instanceOf(Foo.class, foo, "foo must be an instance of class Foo");
*
*
* @param 被检查对象泛型类型
* @param type 被检查对象匹配的类型
* @param obj 被检查对象
* @param errorMsgTemplate 异常时的消息模板
* @param params 参数列表
* @return 被检查对象
* @throws IllegalArgumentException if the object is not an instance of clazz
* @see Class#isInstance(Object)
*/
public static T isInstanceOf(Class> type, T obj, String errorMsgTemplate, Object... params) throws IllegalArgumentException {
notNull(type, "Type to check against must not be null");
if (false == type.isInstance(obj)) {
throw new IllegalArgumentException(StrUtil.format(errorMsgTemplate, params));
}
return obj;
}
/**
* 断言 {@code superType.isAssignableFrom(subType)} 是否为 {@code true}.
*
*