Package top.tangyh.basic.utils
Class ArgumentAssert
java.lang.Object
top.tangyh.basic.utils.ArgumentAssert
断言
断言某些对象或值是否符合规定,否则抛出异常。经常用于做变量检查
断言某些对象或值是否符合规定,否则抛出异常。经常用于做变量检查
- Author:
- Looly
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecheckBetween(double value, double min, double max) 检查值是否在指定范围内static intcheckBetween(int value, int min, int max) 检查值是否在指定范围内static longcheckBetween(long value, long min, long max) 检查值是否在指定范围内static NumbercheckBetween(Number value, Number min, Number max) 检查值是否在指定范围内static LocalDateTimecheckGt(LocalDateTime value, LocalDateTime min, String... msg) 检查日志是否大于指定值static intcheckIndex(int index, int size) 检查下标(数组、集合、字符串)是否符合要求,下标必须满足:static intcheckIndex(int index, int size, String errorMsgTemplate, Object... params) 检查下标(数组、集合、字符串)是否符合要求,下标必须满足:static LocalDateTimecheckLt(LocalDateTime value, LocalDateTime max, String... msg) 检查日志是否小于指定值static <T> Tcontain(Collection<T> collection, T item) 断言给定值是否被另一个集合包含(即是否不为子串)static <T> Tcontain(Collection<T> collection, T item, String errorMsgTemplate, Object... params) 断言给定值是否被另一个集合包含(即是否不为子串)static <T,X extends Throwable>
Tcontain(Collection<T> collection, T item, Supplier<X> errorSupplier) 断言给定值是否被另一个集合包含(即是否不为子串)static void断言2个字符串是否相等,如果不等用指定错误码抛出异常static <X extends Throwable>
void断言2个字符串是否相等,如果 不相等 抛出给定的异常static voidisAssignable(Class<?> superType, Class<?> subType) 断言superType.isAssignableFrom(subType)是否为true.static voidisAssignable(Class<?> superType, Class<?> subType, String errorMsgTemplate, Object... params) 断言superType.isAssignableFrom(subType)是否为true.static voidisFalse(boolean expression) 断言是否为假,如果为true抛出ArgumentException异常static void断言是否为假,如果为true抛出ArgumentException异常static <X extends Throwable>
void断言是否为假,如果为true抛出指定类型异常
并使用指定的函数获取错误信息返回static <T> TisInstanceOf(Class<?> type, T obj) 断言给定对象是否是给定类的实例static <T> TisInstanceOf(Class<?> type, T obj, String errorMsgTemplate, Object... params) 断言给定对象是否是给定类的实例static voidstatic voidstatic <X extends Throwable>
void断言对象是否为null,如果不为null抛出指定类型异常 并使用指定的函数获取错误信息返回static voidisTrue(boolean expression) 断言是否为真,如果为false抛出ArgumentException异常static void断言是否为真,如果为false抛出ArgumentException异常static <X extends Throwable>
void断言是否为真,如果为false抛出给定的异常static <T> T[]noNullElements(T[] array) 断言给定数组是否不包含null元素,如果数组为空或null将被认为不包含static <T> T[]noNullElements(T[] array, String errorMsgTemplate, Object... params) 断言给定数组是否不包含null元素,如果数组为空或null将被认为不包含static <T,X extends Throwable>
T[]noNullElements(T[] array, Supplier<X> errorSupplier) 断言给定数组是否不包含null元素,如果数组为空或null将被认为不包含 并使用指定的函数获取错误信息返回static <T,E> T notAllNull(T object, E obj, String errorMsgTemplate, Object... params) 判断2个参数是否同时为空static <T,E> T notAnyNull(T object, E obj, String errorMsgTemplate, Object... params) 判断2个参数是否任意一个为空static <T extends CharSequence>
TnotBlank(T text) 检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出ArgumentExceptionstatic <T extends CharSequence>
T检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出ArgumentExceptionstatic <T extends CharSequence,X extends Throwable>
T检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出自定义异常。static <T extends CharSequence,X extends Throwable>
TnotContain(CharSequence textToSearch, T substring, Supplier<X> errorSupplier) 断言给定字符串是否不被另一个字符串包含(即是否为子串) 并使用指定的函数获取错误信息返回static StringnotContain(String textToSearch, String substring) 断言给定字符串是否不被另一个字符串包含(即是否为子串)static StringnotContain(String textToSearch, String substring, String errorMsgTemplate, Object... params) 断言给定字符串是否不被另一个字符串包含(即是否为子串)static <T> TnotContain(Collection<T> collection, T item) 断言给定值是否不被另一个集合包含(即是否为子串)static <T> TnotContain(Collection<T> collection, T item, String errorMsgTemplate, Object... params) 断言给定值是否不被另一个集合包含(即是否为子串)static <T,X extends Throwable>
TnotContain(Collection<T> collection, T item, Supplier<X> errorSupplier) 断言给定值是否不被另一个集合包含(即是否为子串)static <T extends CharSequence>
TnotEmpty(T text) 检查给定字符串是否为空,为空抛出ArgumentExceptionstatic <T> T[]notEmpty(T[] array) 断言给定数组是否包含元素,数组必须不为null且至少包含一个元素static <T> T[]断言给定数组是否包含元素,数组必须不为null且至少包含一个元素static <T,X extends Throwable>
T[]断言给定数组是否包含元素,数组必须不为null且至少包含一个元素 并使用指定的函数获取错误信息返回static <T extends CharSequence>
T检查给定字符串是否为空,为空抛出ArgumentExceptionstatic <T extends CharSequence,X extends Throwable>
T检查给定字符串是否为空,为空抛出自定义异常,并使用指定的函数获取错误信息返回。static <T> TnotNull(T object) static <T> Tstatic <T,X extends Throwable>
T断言对象是否不为null,如果为null抛出指定类型异常 并使用指定的函数获取错误信息返回static voidstate(boolean expression) 检查boolean表达式,当检查结果为false时抛出IllegalStateException。static void检查boolean表达式,当检查结果为false时抛出IllegalStateException。static void检查boolean表达式,当检查结果为false时抛出IllegalStateException。
-
Constructor Details
-
ArgumentAssert
public ArgumentAssert()
-
-
Method Details
-
isTrue
public static <X extends Throwable> void isTrue(boolean expression, Supplier<? extends X> supplier) throws X 断言是否为真,如果为false抛出给定的异常
Assert.isTrue(i > 0, ArgumentException::new);
- Type Parameters:
X- 异常类型- Parameters:
expression- 布尔值supplier- 指定断言不通过时抛出的异常- Throws:
X- if expression isfalse
-
isTrue
public static void isTrue(boolean expression, String errorMsgTemplate, Object... params) throws ArgumentException 断言是否为真,如果为false抛出ArgumentException异常
Assert.isTrue(i > 0, "The value must be greater than zero");
- Parameters:
expression- 布尔值errorMsgTemplate- 错误抛出异常附带的消息模板,变量用{}代替params- 参数列表- Throws:
ArgumentException- if expression isfalse
-
isTrue
断言是否为真,如果为false抛出ArgumentException异常
Assert.isTrue(i > 0, "The value must be greater than zero");
- Parameters:
expression- 布尔值- Throws:
ArgumentException- if expression isfalse
-
isFalse
public static <X extends Throwable> void isFalse(boolean expression, Supplier<X> errorSupplier) throws X 断言是否为假,如果为true抛出指定类型异常
并使用指定的函数获取错误信息返回Assert.isFalse(i > 0, ()->{ // to query relation message return new ArgumentException("relation message to return"); });- Type Parameters:
X- 异常类型- Parameters:
expression- 布尔值errorSupplier- 指定断言不通过时抛出的异常- Throws:
X- if expression isfalse- Since:
- 5.4.5
-
isFalse
public static void isFalse(boolean expression, String errorMsgTemplate, Object... params) throws ArgumentException 断言是否为假,如果为true抛出ArgumentException异常
Assert.isFalse(i < 0, "The value must be greater than zero");
- Parameters:
expression- 布尔值errorMsgTemplate- 错误抛出异常附带的消息模板,变量用{}代替params- 参数列表- Throws:
ArgumentException- if expression isfalse
-
isFalse
断言是否为假,如果为true抛出ArgumentException异常
Assert.isFalse(i < 0);
- Parameters:
expression- 布尔值- Throws:
ArgumentException- if expression isfalse
-
isNull
断言对象是否为null,如果不为null抛出指定类型异常 并使用指定的函数获取错误信息返回Assert.isNull(value, ()->{ // to query relation message return new ArgumentException("relation message to return"); });- Type Parameters:
X- 异常类型- Parameters:
object- 被检查的对象errorSupplier- 错误抛出异常附带的消息生产接口- Throws:
X- if the object is notnull- Since:
- 5.4.5
-
isNull
public static void isNull(Object object, String errorMsgTemplate, Object... params) throws ArgumentException - Parameters:
object- 被检查的对象errorMsgTemplate- 消息模板,变量使用{}表示params- 参数列表- Throws:
ArgumentException- if the object is notnull
-
isNull
- Parameters:
object- 被检查对象- Throws:
ArgumentException- if the object is notnull
-
notNull
断言对象是否不为null,如果为null抛出指定类型异常 并使用指定的函数获取错误信息返回Assert.notNull(clazz, ()->{ // to query relation message return new ArgumentException("relation message to return"); });- Type Parameters:
T- 被检查对象泛型类型X- 异常类型- Parameters:
object- 被检查对象errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查后的对象 t
- Throws:
X- if the object isnull- Since:
- 5.4.5
-
notNull
public static <T> T notNull(T object, String errorMsgTemplate, Object... params) throws ArgumentException 断言对象是否不为null,如果为null抛出ArgumentException异常 Assert that an object is notnull.Assert.notNull(clazz, "The class must not be null");
- Type Parameters:
T- 被检查对象泛型类型- Parameters:
object- 被检查对象errorMsgTemplate- 错误消息模板,变量使用{}表示params- 参数- Returns:
- 被检查后的对象 t
- Throws:
ArgumentException- if the object isnull
-
notAllNull
public static <T,E> T notAllNull(T object, E obj, String errorMsgTemplate, Object... params) throws ArgumentException 判断2个参数是否同时为空- Parameters:
object- 参数1obj- 参数2errorMsgTemplate- 错误消息模板,变量使用{}表示params- 参数- Throws:
ArgumentException- if the object isnull
-
notAnyNull
public static <T,E> T notAnyNull(T object, E obj, String errorMsgTemplate, Object... params) throws ArgumentException 判断2个参数是否任意一个为空- Parameters:
object- 参数1obj- 参数2errorMsgTemplate- 错误消息模板,变量使用{}表示params- 参数- Throws:
ArgumentException- if the object isnull
-
notNull
- Type Parameters:
T- 被检查对象类型- Parameters:
object- 被检查对象- Returns:
- 非空对象 t
- Throws:
ArgumentException- if the object isnull
-
notEmpty
public static <T extends CharSequence,X extends Throwable> T notEmpty(T text, Supplier<X> errorSupplier) throws X 检查给定字符串是否为空,为空抛出自定义异常,并使用指定的函数获取错误信息返回。Assert.notEmpty(name, ()->{ // to query relation message return new ArgumentException("relation message to return"); });- Type Parameters:
T- 字符串类型X- 异常类型- Parameters:
text- 被检查字符串errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 非空字符串 t
- Throws:
X- 被检查字符串为空抛出此异常- Since:
- 5.4.5
- See Also:
-
StrUtil#isNotEmpty(CharSequence)
-
notEmpty
public static <T extends CharSequence> T notEmpty(T text, String errorMsgTemplate, Object... params) throws ArgumentException 检查给定字符串是否为空,为空抛出ArgumentExceptionAssert.notEmpty(name, "Name must not be empty");
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串errorMsgTemplate- 错误消息模板,变量使用{}表示params- 参数- Returns:
- 非空字符串 t
- Throws:
ArgumentException- 被检查字符串为空- See Also:
-
StrUtil#isNotEmpty(CharSequence)
-
notEmpty
检查给定字符串是否为空,为空抛出ArgumentExceptionAssert.notEmpty(name);
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串- Returns:
- 被检查的字符串 t
- Throws:
ArgumentException- 被检查字符串为空- See Also:
-
StrUtil#isNotEmpty(CharSequence)
-
notBlank
public static <T extends CharSequence,X extends Throwable> T notBlank(T text, Supplier<X> errorMsgSupplier) throws X 检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出自定义异常。 并使用指定的函数获取错误信息返回Assert.notBlank(name, ()->{ // to query relation message return new ArgumentException("relation message to return"); });- Type Parameters:
T- 字符串类型X- 异常类型- Parameters:
text- 被检查字符串errorMsgSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 非空字符串 t
- Throws:
X- 被检查字符串为空白- See Also:
-
StrUtil#isNotBlank(CharSequence)
-
notBlank
public static <T extends CharSequence> T notBlank(T text, String errorMsgTemplate, Object... params) throws ArgumentException 检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出ArgumentExceptionAssert.notBlank(name, "Name must not be blank");
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串errorMsgTemplate- 错误消息模板,变量使用{}表示params- 参数- Returns:
- 非空字符串 t
- Throws:
ArgumentException- 被检查字符串为空白- See Also:
-
StrUtil#isNotBlank(CharSequence)
-
notBlank
检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出ArgumentExceptionAssert.notBlank(name, "Name must not be blank");
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串- Returns:
- 非空字符串 t
- Throws:
ArgumentException- 被检查字符串为空白- See Also:
-
StrUtil#isNotBlank(CharSequence)
-
notContain
public static <T extends CharSequence,X extends Throwable> T notContain(CharSequence textToSearch, T substring, Supplier<X> errorSupplier) throws X 断言给定字符串是否不被另一个字符串包含(即是否为子串) 并使用指定的函数获取错误信息返回Assert.notContain(name, "rod", ()->{ // to query relation message return new ArgumentException("relation message to return "); });- Type Parameters:
T- 字符串类型X- 异常类型- Parameters:
textToSearch- 被搜索的字符串substring- 被检查的子串errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的子串 t
- Throws:
X- 非子串抛出异常- Since:
- 5.4.5
- See Also:
-
StrUtil#contains(CharSequence, CharSequence)
-
notContain
public static String notContain(String textToSearch, String substring, String errorMsgTemplate, Object... params) throws ArgumentException 断言给定字符串是否不被另一个字符串包含(即是否为子串)Assert.notContain(name, "rod", "Name must not contain 'rod'");
- Parameters:
textToSearch- 被搜索的字符串substring- 被检查的子串errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的子串 string
- Throws:
ArgumentException- 非子串抛出异常
-
notContain
断言给定字符串是否不被另一个字符串包含(即是否为子串)Assert.notContain(name, "rod", "Name must not contain 'rod'");
- Parameters:
textToSearch- 被搜索的字符串substring- 被检查的子串- Returns:
- 被检查的子串 string
- Throws:
ArgumentException- 非子串抛出异常
-
contain
断言给定值是否被另一个集合包含(即是否不为子串)Assert.notContain(names, "张三", "name's 中必须包含 '张三'");
- Parameters:
collection- 被搜索的集合item- 被检查的值- Returns:
- 被检查的值 string
- Throws:
ArgumentException- 非子串抛出异常
-
contain
public static <T> T contain(Collection<T> collection, T item, String errorMsgTemplate, Object... params) throws ArgumentException 断言给定值是否被另一个集合包含(即是否不为子串)Assert.notContain(names, "张三", "name's 中必须包含 '张三'");
- Parameters:
collection- 被搜索的集合item- 被检查的值errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的值 string
- Throws:
ArgumentException- 非子串抛出异常
-
contain
public static <T,X extends Throwable> T contain(Collection<T> collection, T item, Supplier<X> errorSupplier) throws X 断言给定值是否被另一个集合包含(即是否不为子串)Assert.notContain(names, "张三", "name's 中必须包含 '张三'");
- Parameters:
collection- 被搜索的集合item- 被检查的值- Returns:
- 被检查的值 string
- Throws:
ArgumentException- 非子串抛出异常X extends Throwable
-
notContain
断言给定值是否不被另一个集合包含(即是否为子串)Assert.notContain(names, "张三", "name's 中不能包含 '张三'");
- Parameters:
collection- 被搜索的集合item- 被检查的值- Returns:
- 被检查的值 string
- Throws:
ArgumentException- 非子串抛出异常
-
notContain
public static <T> T notContain(Collection<T> collection, T item, String errorMsgTemplate, Object... params) throws ArgumentException 断言给定值是否不被另一个集合包含(即是否为子串)Assert.notContain(names, "张三", "name's 中不能包含 '张三'");
- Parameters:
collection- 被搜索的集合item- 被检查的值errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的值 string
- Throws:
ArgumentException- 非子串抛出异常
-
notContain
public static <T,X extends Throwable> T notContain(Collection<T> collection, T item, Supplier<X> errorSupplier) throws X 断言给定值是否不被另一个集合包含(即是否为子串)Assert.notContain(names, "张三", "name's 中不能包含 '张三'");
- Parameters:
collection- 被搜索的集合item- 被检查的值- Returns:
- 被检查的值 string
- Throws:
ArgumentException- 非子串抛出异常X extends Throwable
-
notEmpty
断言给定数组是否包含元素,数组必须不为null且至少包含一个元素 并使用指定的函数获取错误信息返回Assert.notEmpty(array, ()->{ // to query relation message return new ArgumentException("relation message to return"); });- Type Parameters:
T- 数组元素类型X- 异常类型- Parameters:
array- 被检查的数组errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的数组 t [ ]
- Throws:
X- if the object array isnullor has no elements- Since:
- 5.4.5
- See Also:
-
ArrayUtil#isNotEmpty(Object[])
-
notEmpty
public static <T> T[] notEmpty(T[] array, String errorMsgTemplate, Object... params) throws ArgumentException 断言给定数组是否包含元素,数组必须不为null且至少包含一个元素Assert.notEmpty(array, "The array must have elements");
- Type Parameters:
T- 数组元素类型- Parameters:
array- 被检查的数组errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的数组 t [ ]
- Throws:
ArgumentException- if the object array isnullor has no elements
-
notEmpty
断言给定数组是否包含元素,数组必须不为null且至少包含一个元素Assert.notEmpty(array, "The array must have elements");
- Type Parameters:
T- 数组元素类型- Parameters:
array- 被检查的数组- Returns:
- 被检查的数组 t [ ]
- Throws:
ArgumentException- if the object array isnullor has no elements
-
noNullElements
public static <T,X extends Throwable> T[] noNullElements(T[] array, Supplier<X> errorSupplier) throws X 断言给定数组是否不包含null元素,如果数组为空或null将被认为不包含 并使用指定的函数获取错误信息返回Assert.noNullElements(array, ()->{ // to query relation message return new ArgumentException("relation message to return "); });- Type Parameters:
T- 数组元素类型X- 异常类型- Parameters:
array- 被检查的数组errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的数组 t [ ]
- Throws:
X- if the object array contains anullelement- Since:
- 5.4.5
- See Also:
-
ArrayUtil#hasNull(Object[])
-
noNullElements
public static <T> T[] noNullElements(T[] array, String errorMsgTemplate, Object... params) throws ArgumentException 断言给定数组是否不包含null元素,如果数组为空或null将被认为不包含Assert.noNullElements(array, "The array must have non-null elements");
- Type Parameters:
T- 数组元素类型- Parameters:
array- 被检查的数组errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的数组 t [ ]
- Throws:
ArgumentException- if the object array contains anullelement
-
noNullElements
断言给定数组是否不包含null元素,如果数组为空或null将被认为不包含Assert.noNullElements(array);
- Type Parameters:
T- 数组元素类型- Parameters:
array- 被检查的数组- Returns:
- 被检查的数组 t [ ]
- Throws:
ArgumentException- if the object array contains anullelement
-
notEmpty
public static <E,T extends Iterable<E>, T notEmptyX extends Throwable> (T collection, Supplier<X> errorSupplier) throws X 断言给定集合非空 并使用指定的函数获取错误信息返回Assert.notEmpty(collection, ()->{ // to query relation message return new ArgumentException("relation message to return"); });- Type Parameters:
E- 集合元素类型T- 集合类型X- 异常类型- Parameters:
collection- 被检查的集合errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 非空集合 t
- Throws:
X- if the collection isnullor has no elements- Since:
- 5.4.5
- See Also:
-
CollUtil#isNotEmpty(Iterable)
-
notEmpty
public static <E,T extends Iterable<E>> T notEmpty(T collection, String errorMsgTemplate, Object... params) throws ArgumentException 断言给定集合非空Assert.notEmpty(collection, "Collection must have elements");
- Type Parameters:
E- 集合元素类型T- 集合类型- Parameters:
collection- 被检查的集合errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 非空集合 t
- Throws:
ArgumentException- if the collection isnullor has no elements
-
notEmpty
断言给定集合非空Assert.notEmpty(collection);
- Type Parameters:
E- 集合元素类型T- 集合类型- Parameters:
collection- 被检查的集合- Returns:
- 被检查集合 t
- Throws:
ArgumentException- if the collection isnullor has no elements
-
notEmpty
public static <K,V, T notEmptyT extends Map<K, V>, X extends Throwable> (T map, Supplier<X> errorSupplier) throws X 断言给定Map非空 并使用指定的函数获取错误信息返回Assert.notEmpty(map, ()->{ // to query relation message return new ArgumentException("relation message to return"); });- Type Parameters:
K- Key类型V- Value类型T- Map类型X- 异常类型- Parameters:
map- 被检查的MaperrorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的Map t
- Throws:
X- if the map isnullor has no entries- Since:
- 5.4.5
- See Also:
-
MapUtil#isNotEmpty(Map)
-
notEmpty
public static <K,V, T notEmptyT extends Map<K, V>> (T map, String errorMsgTemplate, Object... params) throws ArgumentException 断言给定Map非空Assert.notEmpty(map, "Map must have entries");
- Type Parameters:
K- Key类型V- Value类型T- Map类型- Parameters:
map- 被检查的MaperrorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的Map t
- Throws:
ArgumentException- if the map isnullor has no entries
-
notEmpty
断言给定Map非空Assert.notEmpty(map, "Map must have entries");
- Type Parameters:
K- Key类型V- Value类型T- Map类型- Parameters:
map- 被检查的Map- Returns:
- 被检查的Map t
- Throws:
ArgumentException- if the map isnullor has no entries
-
isInstanceOf
断言给定对象是否是给定类的实例Assert.instanceOf(Foo.class, foo);
- Type Parameters:
T- 被检查对象泛型类型- Parameters:
type- 被检查对象匹配的类型obj- 被检查对象- Returns:
- 被检查的对象 t
- Throws:
ArgumentException- if the object is not an instance of clazz- See Also:
-
isInstanceOf
public static <T> T isInstanceOf(Class<?> type, T obj, String errorMsgTemplate, Object... params) throws ArgumentException 断言给定对象是否是给定类的实例Assert.instanceOf(Foo.class, foo);
- Type Parameters:
T- 被检查对象泛型类型- Parameters:
type- 被检查对象匹配的类型obj- 被检查对象errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查对象 t
- Throws:
ArgumentException- if the object is not an instance of clazz- See Also:
-
isAssignable
断言superType.isAssignableFrom(subType)是否为true.Assert.isAssignable(Number.class, myClass);
- Parameters:
superType- 需要检查的父类或接口subType- 需要检查的子类- Throws:
ArgumentException- 如果子类非继承父类,抛出此异常
-
isAssignable
public static void isAssignable(Class<?> superType, Class<?> subType, String errorMsgTemplate, Object... params) throws ArgumentException 断言superType.isAssignableFrom(subType)是否为true.Assert.isAssignable(Number.class, myClass);
- Parameters:
superType- 需要检查的父类或接口subType- 需要检查的子类errorMsgTemplate- 异常时的消息模板params- 参数列表- Throws:
ArgumentException- 如果子类非继承父类,抛出此异常
-
state
public static void state(boolean expression, Supplier<String> errorMsgSupplier) throws IllegalStateException 检查boolean表达式,当检查结果为false时抛出IllegalStateException。 并使用指定的函数获取错误信息返回Assert.state(id == null, ()->{ // to query relation message return "relation message to return "; });- Parameters:
expression- boolean 表达式errorMsgSupplier- 错误抛出异常附带的消息生产接口- Throws:
IllegalStateException- 表达式为false抛出此异常
-
state
public static void state(boolean expression, String errorMsgTemplate, Object... params) throws IllegalStateException 检查boolean表达式,当检查结果为false时抛出IllegalStateException。Assert.state(id == null, "The id property must not already be initialized");
- Parameters:
expression- boolean 表达式errorMsgTemplate- 异常时的消息模板params- 参数列表- Throws:
IllegalStateException- 表达式为false抛出此异常
-
state
检查boolean表达式,当检查结果为false时抛出IllegalStateException。Assert.state(id == null);
- Parameters:
expression- boolean 表达式- Throws:
IllegalStateException- 表达式为false抛出此异常
-
checkIndex
public static int checkIndex(int index, int size) throws ArgumentException, IndexOutOfBoundsException 检查下标(数组、集合、字符串)是否符合要求,下标必须满足:0 ≤ index < size
- Parameters:
index- 下标size- 长度- Returns:
- 检查后的下标 int
- Throws:
ArgumentException- 如果size < 0 抛出此异常IndexOutOfBoundsException- 如果index < 0或者 index ≥ size 抛出此异常- Since:
- 4.1.9
-
checkIndex
public static int checkIndex(int index, int size, String errorMsgTemplate, Object... params) throws ArgumentException, IndexOutOfBoundsException 检查下标(数组、集合、字符串)是否符合要求,下标必须满足:0 ≤ index < size
- Parameters:
index- 下标size- 长度errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 检查后的下标 int
- Throws:
ArgumentException- 如果size < 0 抛出此异常IndexOutOfBoundsException- 如果index < 0或者 index ≥ size 抛出此异常- Since:
- 4.1.9
-
checkBetween
public static int checkBetween(int value, int min, int max) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值 int
- Since:
- 4.1.10
-
checkGt
检查日志是否大于指定值- Parameters:
value- 值min- 最小值(包含)- Returns:
- 检查后的长度值 int
- Since:
- 4.1.10
-
checkLt
检查日志是否小于指定值- Parameters:
value- 值max- 最大值(包含)- Returns:
- 检查后的长度值 int
- Since:
- 4.1.10
-
checkBetween
public static long checkBetween(long value, long min, long max) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值 long
- Since:
- 4.1.10
-
checkBetween
public static double checkBetween(double value, double min, double max) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值 double
- Since:
- 4.1.10
-
checkBetween
检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值 number
- Since:
- 4.1.10
-
equals
public static void equals(Object expected, Object actual, String errorMsgTemplate, Object... params) 断言2个字符串是否相等,如果不等用指定错误码抛出异常- Parameters:
expected- 预期的值actual- 需要比较的字符串expectederrorMsgTemplate- 错误抛出异常附带的消息模板,变量用{}代替params- 参数列表- Throws:
ArgumentException- if expression isfalse
-
equals
public static <X extends Throwable> void equals(Object expected, Object actual, Supplier<? extends X> supplier) throws X 断言2个字符串是否相等,如果 不相等 抛出给定的异常- Parameters:
expected- 预期的值actual- 需要比较的字符串supplier- 指定断言不通过时抛出的异常- Throws:
X- if expression isfalse
-