public class Assert extends Object
| 构造器和说明 |
|---|
Assert() |
| 限定符和类型 | 方法和说明 |
|---|---|
static double |
checkBetween(double value,
double min,
double max)
检查值是否在指定范围内
|
static double |
checkBetween(double value,
double min,
double max,
String errorMsgTemplate,
Object... params)
检查值是否在指定范围内
|
static <X extends Throwable> |
checkBetween(double value,
double min,
double max,
Supplier<? extends X> errorSupplier)
检查值是否在指定范围内
|
static int |
checkBetween(int value,
int min,
int max)
检查值是否在指定范围内
|
static int |
checkBetween(int value,
int min,
int max,
String errorMsgTemplate,
Object... params)
检查值是否在指定范围内
|
static <X extends Throwable> |
checkBetween(int value,
int min,
int max,
Supplier<? extends X> errorSupplier)
检查值是否在指定范围内
|
static long |
checkBetween(long value,
long min,
long max)
检查值是否在指定范围内
|
static long |
checkBetween(long value,
long min,
long max,
String errorMsgTemplate,
Object... params)
检查值是否在指定范围内
|
static <X extends Throwable> |
checkBetween(long value,
long min,
long max,
Supplier<? extends X> errorSupplier)
检查值是否在指定范围内
|
static Number |
checkBetween(Number value,
Number min,
Number max)
检查值是否在指定范围内
|
static int |
checkIndex(int index,
int size)
检查下标(数组、集合、字符串)是否符合要求,下标必须满足:
0 ≤ index < size
|
static int |
checkIndex(int index,
int size,
String errorMsgTemplate,
Object... params)
检查下标(数组、集合、字符串)是否符合要求,下标必须满足:
0 ≤ index < size
|
static void |
equals(Object obj1,
Object obj2)
断言两个对象是否相等,如果两个对象不相等 抛出BusinessException 异常
Assert.isEquals(obj1,obj2); |
static void |
equals(Object obj1,
Object obj2,
String errorMsgTemplate,
Object... params)
断言两个对象是否相等,如果两个对象不相等 抛出BusinessException 异常
Assert.isEquals(obj1,obj2,"obj1 must be equals obj2"); |
static <X extends Throwable> |
equals(Object obj1,
Object obj2,
Supplier<X> errorSupplier)
断言两个对象是否相等,如果两个对象不相等,抛出指定类型异常,并使用指定的函数获取错误信息返回
|
static void |
isAssignable(Class<?> superType,
Class<?> subType)
断言
superType.isAssignableFrom(subType) 是否为 true. |
static void |
isAssignable(Class<?> superType,
Class<?> subType,
String errorMsgTemplate,
Object... params)
断言
superType.isAssignableFrom(subType) 是否为 true. |
static void |
isFalse(boolean expression)
断言是否为假,如果为
true 抛出 BusinessException 异常Assert.isFalse(i < 0); |
static void |
isFalse(boolean expression,
ResultCode resultEnum) |
static void |
isFalse(boolean expression,
String errorMsgTemplate,
Object... params)
断言是否为假,如果为
true 抛出 BusinessException 异常Assert.isFalse(i < 0, "The value must not be negative"); |
static void |
isFalse(boolean expression,
String message,
String code) |
static <X extends Throwable> |
isFalse(boolean expression,
Supplier<X> errorSupplier)
断言是否为假,如果为
true 抛出指定类型异常并使用指定的函数获取错误信息返回
Assert.isFalse(i > 0, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
|
static <T> T |
isInstanceOf(Class<?> type,
T obj)
断言给定对象是否是给定类的实例
Assert.instanceOf(Foo.class, foo); |
static <T> T |
isInstanceOf(Class<?> type,
T obj,
String errorMsgTemplate,
Object... params)
断言给定对象是否是给定类的实例
Assert.instanceOf(Foo.class, foo, "foo must be an instance of class Foo"); |
static void |
isNull(Object object)
|
static void |
isNull(Object object,
ResultCode resultEnum) |
static void |
isNull(Object object,
String errorMsgTemplate,
Object... params)
|
static void |
isNull(Object object,
String message,
String code) |
static <X extends Throwable> |
isNull(Object object,
Supplier<X> errorSupplier)
断言对象是否为
null ,如果不为null 抛出指定类型异常
并使用指定的函数获取错误信息返回
Assert.isNull(value, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
|
static void |
isTrue(boolean expression)
断言是否为真,如果为
false 抛出 BusinessException 异常Assert.isTrue(i > 0); |
static void |
isTrue(boolean expression,
ResultCode resultEnum) |
static void |
isTrue(boolean expression,
String errorMsgTemplate,
Object... params)
断言是否为真,如果为
false 抛出 BusinessException 异常Assert.isTrue(i > 0, "The value must be greater than zero"); |
static void |
isTrue(boolean expression,
String message,
String code) |
static <X extends Throwable> |
isTrue(boolean expression,
Supplier<? extends X> supplier)
断言是否为真,如果为
false 抛出给定的异常Assert.isTrue(i > 0, BusinessException::new); |
static <T> T[] |
noNullElements(T[] array)
断言给定数组是否不包含
null元素,如果数组为空或 null将被认为不包含
Assert.noNullElements(array); |
static <T> T[] |
noNullElements(T[] array,
String errorMsgTemplate,
Object... params)
断言给定数组是否不包含
null元素,如果数组为空或 null将被认为不包含
Assert.noNullElements(array, "The array must not have null elements"); |
static <T,X extends Throwable> |
noNullElements(T[] array,
Supplier<X> errorSupplier)
断言给定数组是否不包含
null元素,如果数组为空或 null将被认为不包含
并使用指定的函数获取错误信息返回
Assert.noNullElements(array, ()->{
// to query relation message
return new BusinessException("relation message to return ");
});
|
static <T extends CharSequence> |
notBlank(T text)
检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出
BusinessException
Assert.notBlank(name); |
static <T extends CharSequence> |
notBlank(T text,
String errorMsgTemplate,
Object... params)
检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出
BusinessException
Assert.notBlank(name, "Name must not be blank"); |
static <T extends CharSequence,X extends Throwable> |
notBlank(T text,
Supplier<X> errorMsgSupplier)
检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出自定义异常。
|
static <T extends CharSequence,X extends Throwable> |
notContain(CharSequence textToSearch,
T substring,
Supplier<X> errorSupplier)
断言给定字符串是否不被另一个字符串包含(即是否为子串)
并使用指定的函数获取错误信息返回
Assert.notContain(name, "rod", ()->{
// to query relation message
return new BusinessException("relation message to return ");
});
|
static String |
notContain(String textToSearch,
String substring)
断言给定字符串是否不被另一个字符串包含(即是否为子串)
Assert.notContain(name, "rod"); |
static String |
notContain(String textToSearch,
String substring,
String errorMsgTemplate,
Object... params)
断言给定字符串是否不被另一个字符串包含(即是否为子串)
Assert.notContain(name, "rod", "Name must not contain 'rod'"); |
static <E,T extends Iterable<E>> |
notEmpty(T collection)
断言给定集合非空
Assert.notEmpty(collection); |
static <K,V,T extends Map<K,V>> |
notEmpty(T map)
断言给定Map非空
Assert.notEmpty(map, "Map must have entries"); |
static <T extends CharSequence> |
notEmpty(T text)
检查给定字符串是否为空,为空抛出
BusinessException
Assert.notEmpty(name); |
static <T> T[] |
notEmpty(T[] array)
断言给定数组是否包含元素,数组必须不为
null 且至少包含一个元素
Assert.notEmpty(array, "The array must have elements"); |
static <T> T[] |
notEmpty(T[] array,
String errorMsgTemplate,
Object... params)
断言给定数组是否包含元素,数组必须不为
null 且至少包含一个元素
Assert.notEmpty(array, "The array must have elements"); |
static <T,X extends Throwable> |
notEmpty(T[] array,
Supplier<X> errorSupplier)
断言给定数组是否包含元素,数组必须不为
null 且至少包含一个元素
并使用指定的函数获取错误信息返回
Assert.notEmpty(array, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
|
static <E,T extends Iterable<E>> |
notEmpty(T collection,
ResultCode resultEnum) |
static <E,T extends Iterable<E>> |
notEmpty(T collection,
String errorMsgTemplate,
Object... params)
断言给定集合非空
Assert.notEmpty(collection, "Collection must have elements"); |
static <K,V,T extends Map<K,V>> |
notEmpty(T map,
String errorMsgTemplate,
Object... params)
断言给定Map非空
Assert.notEmpty(map, "Map must have entries"); |
static <T extends CharSequence> |
notEmpty(T text,
String errorMsgTemplate,
Object... params)
检查给定字符串是否为空,为空抛出
BusinessException
Assert.notEmpty(name, "Name must not be empty"); |
static <E,T extends Iterable<E>> |
notEmpty(T collection,
String message,
String code) |
static <E,T extends Iterable<E>,X extends Throwable> |
notEmpty(T collection,
Supplier<X> errorSupplier)
断言给定集合非空
并使用指定的函数获取错误信息返回
Assert.notEmpty(collection, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
|
static <K,V,T extends Map<K,V>,X extends Throwable> |
notEmpty(T map,
Supplier<X> errorSupplier)
断言给定Map非空
并使用指定的函数获取错误信息返回
Assert.notEmpty(map, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
|
static <T extends CharSequence,X extends Throwable> |
notEmpty(T text,
Supplier<X> errorSupplier)
检查给定字符串是否为空,为空抛出自定义异常,并使用指定的函数获取错误信息返回。
|
static void |
notEquals(Object obj1,
Object obj2)
断言两个对象是否不相等,如果两个对象相等 抛出BusinessException 异常
Assert.notEquals(obj1,obj2); |
static void |
notEquals(Object obj1,
Object obj2,
String errorMsgTemplate,
Object... params)
断言两个对象是否不相等,如果两个对象相等 抛出BusinessException 异常
Assert.notEquals(obj1,obj2,"obj1 must be not equals obj2"); |
static <X extends Throwable> |
notEquals(Object obj1,
Object obj2,
Supplier<X> errorSupplier)
断言两个对象是否不相等,如果两个对象相等,抛出指定类型异常,并使用指定的函数获取错误信息返回
|
static <T> T |
notNull(T object)
|
static <T> T |
notNull(T object,
ResultCode resultEnum) |
static <T> T |
notNull(T object,
String errorMsgTemplate,
Object... params)
|
static <T> T |
notNull(T object,
String message,
String code) |
static <T,X extends Throwable> |
notNull(T object,
Supplier<X> errorSupplier)
断言对象是否不为
null ,如果为null 抛出指定类型异常
并使用指定的函数获取错误信息返回
Assert.notNull(clazz, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
|
static void |
state(boolean expression)
检查boolean表达式,当检查结果为false时抛出
IllegalStateException。 |
static void |
state(boolean expression,
String errorMsgTemplate,
Object... params)
检查boolean表达式,当检查结果为false时抛出
IllegalStateException。 |
static void |
state(boolean expression,
Supplier<String> errorMsgSupplier)
检查boolean表达式,当检查结果为false时抛出
IllegalStateException。 |
public static <X extends Throwable> void isTrue(boolean expression, Supplier<? extends X> supplier) throws X extends Throwable
false 抛出给定的异常Assert.isTrue(i > 0, BusinessException::new);
X - 异常类型expression - 布尔值supplier - 指定断言不通过时抛出的异常X - if expression is falseX extends Throwablepublic static void isTrue(boolean expression,
String errorMsgTemplate,
Object... params)
throws BusinessException
false 抛出 BusinessException 异常Assert.isTrue(i > 0, "The value must be greater than zero");
expression - 布尔值errorMsgTemplate - 错误抛出异常附带的消息模板,变量用{}代替params - 参数列表BusinessException - if expression is falsepublic static void isTrue(boolean expression,
String message,
String code)
throws BusinessException
public static void isTrue(boolean expression,
ResultCode resultEnum)
throws BusinessException
public static void isTrue(boolean expression)
throws BusinessException
false 抛出 BusinessException 异常Assert.isTrue(i > 0);
expression - 布尔值BusinessException - if expression is falsepublic static <X extends Throwable> void isFalse(boolean expression, Supplier<X> errorSupplier) throws X extends Throwable
true 抛出指定类型异常
Assert.isFalse(i > 0, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
X - 异常类型expression - 布尔值errorSupplier - 指定断言不通过时抛出的异常X - if expression is falseX extends Throwablepublic static void isFalse(boolean expression,
String errorMsgTemplate,
Object... params)
throws BusinessException
true 抛出 BusinessException 异常Assert.isFalse(i < 0, "The value must not be negative");
expression - 布尔值errorMsgTemplate - 错误抛出异常附带的消息模板,变量用{}代替params - 参数列表BusinessException - if expression is falsepublic static void isFalse(boolean expression,
String message,
String code)
throws BusinessException
public static void isFalse(boolean expression,
ResultCode resultEnum)
throws BusinessException
public static void isFalse(boolean expression)
throws BusinessException
true 抛出 BusinessException 异常Assert.isFalse(i < 0);
expression - 布尔值BusinessException - if expression is falsepublic static <X extends Throwable> void isNull(Object object, Supplier<X> errorSupplier) throws X extends Throwable
null ,如果不为null 抛出指定类型异常
并使用指定的函数获取错误信息返回
Assert.isNull(value, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
X - 异常类型object - 被检查的对象errorSupplier - 错误抛出异常附带的消息生产接口X - if the object is not nullX extends Throwablepublic static void isNull(Object object, String errorMsgTemplate, Object... params) throws BusinessException
object - 被检查的对象errorMsgTemplate - 消息模板,变量使用{}表示params - 参数列表BusinessException - if the object is not nullpublic static void isNull(Object object, String message, String code) throws BusinessException
public static void isNull(Object object, ResultCode resultEnum) throws BusinessException
public static void isNull(Object object) throws BusinessException
object - 被检查对象BusinessException - if the object is not nullpublic static <T,X extends Throwable> T notNull(T object, Supplier<X> errorSupplier) throws X extends Throwable
null ,如果为null 抛出指定类型异常
并使用指定的函数获取错误信息返回
Assert.notNull(clazz, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
T - 被检查对象泛型类型X - 异常类型object - 被检查对象errorSupplier - 错误抛出异常附带的消息生产接口X - if the object is nullX extends Throwablepublic static <T> T notNull(T object,
String errorMsgTemplate,
Object... params)
throws BusinessException
null ,如果为null 抛出BusinessException 异常 Assert that an object is not null .
Assert.notNull(clazz, "The class must not be null");
T - 被检查对象泛型类型object - 被检查对象errorMsgTemplate - 错误消息模板,变量使用{}表示params - 参数BusinessException - if the object is nullpublic static <T> T notNull(T object,
String message,
String code)
throws BusinessException
public static <T> T notNull(T object,
ResultCode resultEnum)
throws BusinessException
public static <T> T notNull(T object)
throws BusinessException
T - 被检查对象类型object - 被检查对象BusinessException - if the object is nullpublic static <T extends CharSequence,X extends Throwable> T notEmpty(T text, Supplier<X> errorSupplier) throws X extends Throwable
Assert.notEmpty(name, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
X - 异常类型T - 字符串类型text - 被检查字符串errorSupplier - 错误抛出异常附带的消息生产接口X - 被检查字符串为空抛出此异常X extends ThrowableStrValidator.isNotEmpty(CharSequence)public static <T extends CharSequence> T notEmpty(T text, String errorMsgTemplate, Object... params) throws BusinessException
BusinessException
Assert.notEmpty(name, "Name must not be empty");
T - 字符串类型text - 被检查字符串errorMsgTemplate - 错误消息模板,变量使用{}表示params - 参数BusinessException - 被检查字符串为空StrValidator.isNotEmpty(CharSequence)public static <T extends CharSequence> T notEmpty(T text) throws BusinessException
BusinessException
Assert.notEmpty(name);
T - 字符串类型text - 被检查字符串BusinessException - 被检查字符串为空StrValidator.isNotEmpty(CharSequence)public static <T extends CharSequence,X extends Throwable> T notBlank(T text, Supplier<X> errorMsgSupplier) throws X extends Throwable
Assert.notBlank(name, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
X - 异常类型T - 字符串类型text - 被检查字符串errorMsgSupplier - 错误抛出异常附带的消息生产接口X - 被检查字符串为空白X extends ThrowableStrValidator.isNotBlank(CharSequence)public static <T extends CharSequence> T notBlank(T text, String errorMsgTemplate, Object... params) throws BusinessException
BusinessException
Assert.notBlank(name, "Name must not be blank");
T - 字符串类型text - 被检查字符串errorMsgTemplate - 错误消息模板,变量使用{}表示params - 参数BusinessException - 被检查字符串为空白StrValidator.isNotBlank(CharSequence)public static <T extends CharSequence> T notBlank(T text) throws BusinessException
BusinessException
Assert.notBlank(name);
T - 字符串类型text - 被检查字符串BusinessException - 被检查字符串为空白StrValidator.isNotBlank(CharSequence)public static <T extends CharSequence,X extends Throwable> T notContain(CharSequence textToSearch, T substring, Supplier<X> errorSupplier) throws X extends Throwable
Assert.notContain(name, "rod", ()->{
// to query relation message
return new BusinessException("relation message to return ");
});
T - 字符串类型X - 异常类型textToSearch - 被搜索的字符串substring - 被检查的子串errorSupplier - 错误抛出异常附带的消息生产接口X - 非子串抛出异常X extends ThrowableCharSequenceUtil.contains(CharSequence, CharSequence)public static String notContain(String textToSearch, String substring, String errorMsgTemplate, Object... params) throws BusinessException
Assert.notContain(name, "rod", "Name must not contain 'rod'");
textToSearch - 被搜索的字符串substring - 被检查的子串errorMsgTemplate - 异常时的消息模板params - 参数列表BusinessException - 非子串抛出异常public static String notContain(String textToSearch, String substring) throws BusinessException
Assert.notContain(name, "rod");
textToSearch - 被搜索的字符串substring - 被检查的子串BusinessException - 非子串抛出异常public static <T,X extends Throwable> T[] notEmpty(T[] array, Supplier<X> errorSupplier) throws X extends Throwable
null 且至少包含一个元素
并使用指定的函数获取错误信息返回
Assert.notEmpty(array, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
T - 数组元素类型X - 异常类型array - 被检查的数组errorSupplier - 错误抛出异常附带的消息生产接口X - if the object array is null or has no elementsX extends ThrowableArrayUtil.isNotEmpty(Object[])public static <T> T[] notEmpty(T[] array,
String errorMsgTemplate,
Object... params)
throws BusinessException
null 且至少包含一个元素
Assert.notEmpty(array, "The array must have elements");
T - 数组元素类型array - 被检查的数组errorMsgTemplate - 异常时的消息模板params - 参数列表BusinessException - if the object array is null or has no elementspublic static <T> T[] notEmpty(T[] array)
throws BusinessException
null 且至少包含一个元素
Assert.notEmpty(array, "The array must have elements");
T - 数组元素类型array - 被检查的数组BusinessException - if the object array is null or has no elementspublic static <T,X extends Throwable> T[] noNullElements(T[] array, Supplier<X> errorSupplier) throws X extends Throwable
null元素,如果数组为空或 null将被认为不包含
并使用指定的函数获取错误信息返回
Assert.noNullElements(array, ()->{
// to query relation message
return new BusinessException("relation message to return ");
});
T - 数组元素类型X - 异常类型array - 被检查的数组errorSupplier - 错误抛出异常附带的消息生产接口X - if the object array contains a null elementX extends ThrowableArrayUtil.hasNull(Object[])public static <T> T[] noNullElements(T[] array,
String errorMsgTemplate,
Object... params)
throws BusinessException
null元素,如果数组为空或 null将被认为不包含
Assert.noNullElements(array, "The array must not have null elements");
T - 数组元素类型array - 被检查的数组errorMsgTemplate - 异常时的消息模板params - 参数列表BusinessException - if the object array contains a null elementpublic static <T> T[] noNullElements(T[] array)
throws BusinessException
null元素,如果数组为空或 null将被认为不包含
Assert.noNullElements(array);
T - 数组元素类型array - 被检查的数组BusinessException - if the object array contains a null elementpublic static <E,T extends Iterable<E>,X extends Throwable> T notEmpty(T collection, Supplier<X> errorSupplier) throws X extends Throwable
Assert.notEmpty(collection, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
E - 集合元素类型T - 集合类型X - 异常类型collection - 被检查的集合errorSupplier - 错误抛出异常附带的消息生产接口X - if the collection is null or has no elementsX extends ThrowableCollUtil.isNotEmpty(Iterable)public static <E,T extends Iterable<E>> T notEmpty(T collection, String errorMsgTemplate, Object... params) throws BusinessException
Assert.notEmpty(collection, "Collection must have elements");
E - 集合元素类型T - 集合类型collection - 被检查的集合errorMsgTemplate - 异常时的消息模板params - 参数列表BusinessException - if the collection is null or has no elementspublic static <E,T extends Iterable<E>> T notEmpty(T collection, String message, String code) throws BusinessException
public static <E,T extends Iterable<E>> T notEmpty(T collection, ResultCode resultEnum) throws BusinessException
public static <E,T extends Iterable<E>> T notEmpty(T collection) throws BusinessException
Assert.notEmpty(collection);
E - 集合元素类型T - 集合类型collection - 被检查的集合BusinessException - if the collection is null or has no elementspublic static <K,V,T extends Map<K,V>,X extends Throwable> T notEmpty(T map, Supplier<X> errorSupplier) throws X extends Throwable
Assert.notEmpty(map, ()->{
// to query relation message
return new BusinessException("relation message to return");
});
K - Key类型V - Value类型T - Map类型X - 异常类型map - 被检查的MaperrorSupplier - 错误抛出异常附带的消息生产接口X - if the map is null or has no entriesX extends ThrowableMapUtil.isNotEmpty(Map)public static <K,V,T extends Map<K,V>> T notEmpty(T map, String errorMsgTemplate, Object... params) throws BusinessException
Assert.notEmpty(map, "Map must have entries");
K - Key类型V - Value类型T - Map类型map - 被检查的MaperrorMsgTemplate - 异常时的消息模板params - 参数列表BusinessException - if the map is null or has no entriespublic static <K,V,T extends Map<K,V>> T notEmpty(T map) throws BusinessException
Assert.notEmpty(map, "Map must have entries");
K - Key类型V - Value类型T - Map类型map - 被检查的MapBusinessException - if the map is null or has no entriespublic static <T> T isInstanceOf(Class<?> type, T obj)
Assert.instanceOf(Foo.class, foo);
T - 被检查对象泛型类型type - 被检查对象匹配的类型obj - 被检查对象BusinessException - if the object is not an instance of clazzClass.isInstance(Object)public static <T> T isInstanceOf(Class<?> type, T obj, String errorMsgTemplate, Object... params) throws BusinessException
Assert.instanceOf(Foo.class, foo, "foo must be an instance of class Foo");
T - 被检查对象泛型类型type - 被检查对象匹配的类型obj - 被检查对象errorMsgTemplate - 异常时的消息模板params - 参数列表BusinessException - if the object is not an instance of clazzClass.isInstance(Object)public static void isAssignable(Class<?> superType, Class<?> subType) throws BusinessException
superType.isAssignableFrom(subType) 是否为 true.
Assert.isAssignable(Number.class, myClass);
superType - 需要检查的父类或接口subType - 需要检查的子类BusinessException - 如果子类非继承父类,抛出此异常public static void isAssignable(Class<?> superType, Class<?> subType, String errorMsgTemplate, Object... params) throws BusinessException
superType.isAssignableFrom(subType) 是否为 true.
Assert.isAssignable(Number.class, myClass, "myClass must can be assignable to class Number");
superType - 需要检查的父类或接口subType - 需要检查的子类errorMsgTemplate - 异常时的消息模板params - 参数列表BusinessException - 如果子类非继承父类,抛出此异常public static void state(boolean expression,
Supplier<String> errorMsgSupplier)
throws IllegalStateException
IllegalStateException。
并使用指定的函数获取错误信息返回
Assert.state(id == null, ()->{
// to query relation message
return "relation message to return ";
});
expression - boolean 表达式errorMsgSupplier - 错误抛出异常附带的消息生产接口IllegalStateException - 表达式为 false 抛出此异常public static void state(boolean expression,
String errorMsgTemplate,
Object... params)
throws IllegalStateException
IllegalStateException。
Assert.state(id == null, "The id property must not already be initialized");
expression - boolean 表达式errorMsgTemplate - 异常时的消息模板params - 参数列表IllegalStateException - 表达式为 false 抛出此异常public static void state(boolean expression)
throws IllegalStateException
IllegalStateException。
Assert.state(id == null);
expression - boolean 表达式IllegalStateException - 表达式为 false 抛出此异常public static int checkIndex(int index,
int size)
throws BusinessException,
IndexOutOfBoundsException
0 ≤ index < size
index - 下标size - 长度BusinessException - 如果size < 0 抛出此异常IndexOutOfBoundsException - 如果index < 0或者 index ≥ size 抛出此异常public static int checkIndex(int index,
int size,
String errorMsgTemplate,
Object... params)
throws BusinessException,
IndexOutOfBoundsException
0 ≤ index < size
index - 下标size - 长度errorMsgTemplate - 异常时的消息模板params - 参数列表BusinessException - 如果size < 0 抛出此异常IndexOutOfBoundsException - 如果index < 0或者 index ≥ size 抛出此异常public static <X extends Throwable> int checkBetween(int value, int min, int max, Supplier<? extends X> errorSupplier) throws X extends Throwable
X - 异常类型value - 值min - 最小值(包含)max - 最大值(包含)errorSupplier - 错误抛出异常附带的消息生产接口X - if value is out of boundX extends Throwablepublic static int checkBetween(int value,
int min,
int max,
String errorMsgTemplate,
Object... params)
value - 值min - 最小值(包含)max - 最大值(包含)errorMsgTemplate - 异常信息模板,类似于"aa{}bb{}cc"params - 异常信息参数,用于替换"{}"占位符public static int checkBetween(int value,
int min,
int max)
value - 值min - 最小值(包含)max - 最大值(包含)public static <X extends Throwable> long checkBetween(long value, long min, long max, Supplier<? extends X> errorSupplier) throws X extends Throwable
X - 异常类型value - 值min - 最小值(包含)max - 最大值(包含)errorSupplier - 错误抛出异常附带的消息生产接口X - if value is out of boundX extends Throwablepublic static long checkBetween(long value,
long min,
long max,
String errorMsgTemplate,
Object... params)
value - 值min - 最小值(包含)max - 最大值(包含)errorMsgTemplate - 异常信息模板,类似于"aa{}bb{}cc"params - 异常信息参数,用于替换"{}"占位符public static long checkBetween(long value,
long min,
long max)
value - 值min - 最小值(包含)max - 最大值(包含)public static <X extends Throwable> double checkBetween(double value, double min, double max, Supplier<? extends X> errorSupplier) throws X extends Throwable
X - 异常类型value - 值min - 最小值(包含)max - 最大值(包含)errorSupplier - 错误抛出异常附带的消息生产接口X - if value is out of boundX extends Throwablepublic static double checkBetween(double value,
double min,
double max,
String errorMsgTemplate,
Object... params)
value - 值min - 最小值(包含)max - 最大值(包含)errorMsgTemplate - 异常信息模板,类似于"aa{}bb{}cc"params - 异常信息参数,用于替换"{}"占位符public static double checkBetween(double value,
double min,
double max)
value - 值min - 最小值(包含)max - 最大值(包含)public static Number checkBetween(Number value, Number min, Number max)
value - 值min - 最小值(包含)max - 最大值(包含)public static void notEquals(Object obj1, Object obj2)
Assert.notEquals(obj1,obj2);
obj1 - 对象1obj2 - 对象2BusinessException - obj1 must be not equals obj2public static void notEquals(Object obj1, Object obj2, String errorMsgTemplate, Object... params) throws BusinessException
Assert.notEquals(obj1,obj2,"obj1 must be not equals obj2");
obj1 - 对象1obj2 - 对象2errorMsgTemplate - 异常信息模板,类似于"aa{}bb{}cc"params - 异常信息参数,用于替换"{}"占位符BusinessException - obj1 must be not equals obj2public static <X extends Throwable> void notEquals(Object obj1, Object obj2, Supplier<X> errorSupplier) throws X extends Throwable
X - 异常类型obj1 - 对象1obj2 - 对象2errorSupplier - 错误抛出异常附带的消息生产接口X - obj1 must be not equals obj2X extends Throwablepublic static void equals(Object obj1, Object obj2)
Assert.isEquals(obj1,obj2);
obj1 - 对象1obj2 - 对象2BusinessException - obj1 must be equals obj2public static void equals(Object obj1, Object obj2, String errorMsgTemplate, Object... params) throws BusinessException
Assert.isEquals(obj1,obj2,"obj1 must be equals obj2");
obj1 - 对象1obj2 - 对象2errorMsgTemplate - 异常信息模板,类似于"aa{}bb{}cc"params - 异常信息参数,用于替换"{}"占位符BusinessException - obj1 must be equals obj2public static <X extends Throwable> void equals(Object obj1, Object obj2, Supplier<X> errorSupplier) throws X extends Throwable
X - 异常类型obj1 - 对象1obj2 - 对象2errorSupplier - 错误抛出异常附带的消息生产接口X - obj1 must be equals obj2X extends ThrowableCopyright © 2023. All rights reserved.