Package org.aoju.bus.core.lang
Class Assert
java.lang.Object
org.aoju.bus.core.lang.Assert
断言 断言某些对象或值是否符合规定,否则抛出异常 经常用于做变量检查
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecheckBetween(double value, double min, double max) 检查值是否在指定范围内static doublecheckBetween(double value, double min, double max, String template, Object... params) 检查值是否在指定范围内static <X extends Throwable>
doublecheckBetween(double value, double min, double max, Supplier<? extends X> errorSupplier) 检查值是否在指定范围内static intcheckBetween(int value, int min, int max) 检查值是否在指定范围内static intcheckBetween(int value, int min, int max, String template, Object... params) 检查值是否在指定范围内static <X extends Throwable>
intcheckBetween(int value, int min, int max, Supplier<? extends X> errorSupplier) 检查值是否在指定范围内static longcheckBetween(long value, long min, long max) 检查值是否在指定范围内static longcheckBetween(long value, long min, long max, String template, Object... params) 检查值是否在指定范围内static <X extends Throwable>
longcheckBetween(long value, long min, long max, Supplier<? extends X> errorSupplier) 检查值是否在指定范围内static NumbercheckBetween(Number value, Number min, Number max) 检查值是否在指定范围内static intcheckIndex(int index, int size) 检查下标(数组、集合、字符串)是否符合要求,下标必须满足:static intcheckIndex(int index, int size, String errorMsgTemplate, Object... params) 检查下标(数组、集合、字符串)是否符合要求,下标必须满足:static void断言两个对象是否相等,如果两个对象不相等 抛出IllegalArgumentException 异常static void断言两个对象是否相等,如果两个对象不相等 抛出IllegalArgumentException 异常static <X extends Throwable>
void断言两个对象是否相等,如果两个对象不相等,抛出指定类型异常,并使用指定的函数获取错误信息返回static void断言给定的字符串包含有效的文本内容.static voidisAssignable(Class<?> superType, Class<?> subType) superType.isAssignableFrom(subType)是否为truestatic voidisAssignable(Class<?> superType, Class<?> subType, String errorMsgTemplate, Object... params) superType.isAssignableFrom(subType)是否为truestatic voidisFalse(boolean expression) 断言是否为假,如果为true抛出IllegalArgumentException异常static void断言是否为假,如果为true抛出IllegalArgumentException异常static void断言是否为假,如果为true抛出IllegalArgumentException异常 并使用指定的函数获取错误信息返回static <T> TisInstanceOf(Class<?> type, T object) 断言给定对象是否是给定类的实例static <T> TisInstanceOf(Class<?> type, T object, String errorMsgTemplate, Object... params) 断言给定对象是否是给定类的实例static voidstatic voidstatic voidstatic voidisTrue(boolean expression) 断言是否为真,如果为false抛出IllegalArgumentException异常static void断言是否为真,如果为false抛出IllegalArgumentException异常static void断言是否为真,如果为false抛出异常 并使用指定的函数获取错误信息返回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 extends CharSequence>
TnotBlank(T text) 检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出IllegalArgumentExceptionstatic <T extends CharSequence>
T检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出IllegalArgumentExceptionstatic <T extends CharSequence>
T检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出IllegalArgumentException并使用指定的函数获取错误信息返回static StringnotContain(String textToSearch, String substring) 断言给定字符串是否不被另一个字符串包含(既是否为子串)static StringnotContain(String textToSearch, String substring, String errorMsgTemplate, Object... params) 断言给定字符串是否不被另一个字符串包含(既是否为子串)static StringnotContain(String textToSearch, String substring, Supplier<String> errorMsgSupplier) 断言给定字符串是否不被另一个字符串包含(即是否为子串) 并使用指定的函数获取错误信息返回static Object[]断言给定数组是否包含元素,数组必须不为null且至少包含一个元素static Object[]断言给定数组是否包含元素,数组必须不为null且至少包含一个元素static Object[]断言给定数组是否包含元素,数组必须不为null且至少包含一个元素 并使用指定的函数获取错误信息返回static <T> Collection<T> notEmpty(Collection<T> collection) 断言给定集合非空static <T> Collection<T> notEmpty(Collection<T> collection, String errorMsgTemplate, Object... params) 断言给定集合非空static <T> Collection<T> notEmpty(Collection<T> collection, Supplier<String> errorMsgSupplier) 断言给定集合非空 并使用指定的函数获取错误信息返回static <K,V> Map <K, V> 断言给定Map非空static <K,V> Map <K, V> 断言给定Map非空static <K,V> Map <K, V> 断言给定Map非空 并使用指定的函数获取错误信息返回static <T extends CharSequence>
TnotEmpty(T text) 检查给定字符串是否为空,为空抛出IllegalArgumentExceptionstatic <T extends CharSequence>
T检查给定字符串是否为空,为空抛出IllegalArgumentExceptionstatic <T extends CharSequence>
T检查给定字符串是否为空,为空抛出IllegalArgumentException并使用指定的函数获取错误信息返回static void断言两个对象是否不相等,如果两个对象相等 抛出IllegalArgumentException 异常static void断言两个对象是否不相等,如果两个对象相等 抛出IllegalArgumentException 异常static <X extends Throwable>
void断言两个对象是否不相等,如果两个对象相等,抛出指定类型异常,并使用指定的函数获取错误信息返回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
-
Assert
public Assert()
-
-
Method Details
-
isTrue
public static void isTrue(boolean expression, Supplier<String> errorMsgSupplier) throws IllegalArgumentException 断言是否为真,如果为false抛出异常 并使用指定的函数获取错误信息返回Assert.isTrue(i > 0, () -> { return "relation message to return"; });- Parameters:
expression- 布尔值errorMsgSupplier- 错误抛出异常附带的消息生产接口- Throws:
IllegalArgumentException- if expression isfalse
-
isTrue
public static <X extends Throwable> void isTrue(boolean expression, XSupplier<? extends X> supplier) throws X 断言是否为真,如果为false抛出给定的异常Assert.isTrue(i > 0, IllegalArgumentException::new);
- Type Parameters:
X- 异常类型- Parameters:
expression- 布尔值supplier- 指定断言不通过时抛出的异常- Throws:
X- if expression isfalse
-
isTrue
public static void isTrue(boolean expression, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言是否为真,如果为false抛出IllegalArgumentException异常Assert.isTrue(i > 0, "The value must be greater than zero");
- Parameters:
expression- 布尔值errorMsgTemplate- 错误抛出异常附带的消息模板,变量用{}代替params- 参数列表- Throws:
IllegalArgumentException- if expression isfalse
-
isTrue
断言是否为真,如果为false抛出IllegalArgumentException异常Assert.isTrue(i > 0, "The value must be greater than zero");
- Parameters:
expression- 布尔值- Throws:
IllegalArgumentException- if expression isfalse
-
isFalse
public static void isFalse(boolean expression, Supplier<String> errorMsgSupplier) throws IllegalArgumentException 断言是否为假,如果为true抛出IllegalArgumentException异常 并使用指定的函数获取错误信息返回Assert.isFalse(i > 0, () -> { return "relation message to return"; });- Parameters:
expression- 布尔值errorMsgSupplier- 错误抛出异常附带的消息生产接口- Throws:
IllegalArgumentException- if expression isfalse
-
isFalse
public static void isFalse(boolean expression, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言是否为假,如果为true抛出IllegalArgumentException异常Assert.isFalse(i < 0, "The value must be greater than zero");
- Parameters:
expression- 布尔值errorMsgTemplate- 错误抛出异常附带的消息模板,变量用{}代替params- 参数列表- Throws:
IllegalArgumentException- if expression isfalse
-
isFalse
断言是否为假,如果为true抛出IllegalArgumentException异常Assert.isFalse(i < 0);
- Parameters:
expression- 布尔值- Throws:
IllegalArgumentException- if expression isfalse
-
isNull
public static void isNull(Object object, Supplier<String> errorMsgSupplier) throws IllegalArgumentException 断言对象是否为null,如果不为null抛出IllegalArgumentException异常 并使用指定的函数获取错误信息返回Assert.isNull(value, () -> { return "relation message to return"; });- Parameters:
object- 被检查的对象errorMsgSupplier- 错误抛出异常附带的消息生产接口- Throws:
IllegalArgumentException- if the object is notnull
-
isNull
public static void isNull(Object object, String errorMsgTemplate, Object... params) throws IllegalArgumentException - Parameters:
object- 被检查的对象errorMsgTemplate- 消息模板,变量使用{}表示params- 参数列表- Throws:
IllegalArgumentException- if the object is notnull
-
isNull
- Parameters:
object- 被检查对象- Throws:
NullPointerException- if the object is notnull
-
notNull
断言对象是否不为null,如果为null抛出指定类型异常 并使用指定的函数获取错误信息返回Assert.notNull(clazz, () -> { return new IllegalArgumentException("relation message to return"); });- Type Parameters:
T- 被检查对象泛型类型X- 异常类型- Parameters:
object- 被检查对象errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查后的对象
- Throws:
X- if the object isnull
-
notNull
public static <T> T notNull(T object, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言对象是否不为null,如果为null抛出IllegalArgumentException异常 Assert that an object is notnull.Assert.notNull(clazz, "The class must not be null");
- Type Parameters:
T- 被检查对象泛型类型- Parameters:
object- 被检查对象errorMsgTemplate- 错误消息模板,变量使用{}表示params- 参数- Returns:
- 被检查后的对象
- Throws:
IllegalArgumentException- if the object isnull
-
notNull
- Type Parameters:
T- 被检查对象类型- Parameters:
object- 被检查对象- Returns:
- 非空对象
- Throws:
IllegalArgumentException- if the object isnull
-
notEmpty
public static <T extends CharSequence> T notEmpty(T text, Supplier<String> errorMsgSupplier) throws IllegalArgumentException 检查给定字符串是否为空,为空抛出IllegalArgumentException并使用指定的函数获取错误信息返回Assert.notEmpty(name, () -> { return "relation message to return"; });- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串errorMsgSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 非空字符串
- Throws:
IllegalArgumentException- 被检查字符串为空- See Also:
-
notEmpty
public static <T extends CharSequence> T notEmpty(T text, String errorMsgTemplate, Object... params) throws IllegalArgumentException 检查给定字符串是否为空,为空抛出IllegalArgumentExceptionAssert.notEmpty(name, "Name must not be empty");
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串errorMsgTemplate- 错误消息模板,变量使用{}表示params- 参数- Returns:
- 非空字符串
- Throws:
IllegalArgumentException- 被检查字符串为空
-
notEmpty
检查给定字符串是否为空,为空抛出IllegalArgumentExceptionAssert.notEmpty(name);
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串- Returns:
- 被检查的字符串
- Throws:
IllegalArgumentException- 被检查字符串为空
-
notBlank
public static <T extends CharSequence> T notBlank(T text, Supplier<String> errorMsgSupplier) throws IllegalArgumentException 检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出IllegalArgumentException并使用指定的函数获取错误信息返回Assert.notBlank(name, () -> { return "relation message to return"; });- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串errorMsgSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 非空字符串
- Throws:
IllegalArgumentException- 被检查字符串为空白- See Also:
-
notBlank
public static <T extends CharSequence> T notBlank(T text, String errorMsgTemplate, Object... params) throws IllegalArgumentException 检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出IllegalArgumentExceptionAssert.notBlank(name, "Name must not be blank");
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串errorMsgTemplate- 错误消息模板,变量使用{}表示params- 参数- Returns:
- 非空字符串
- Throws:
IllegalArgumentException- 被检查字符串为空白- See Also:
-
notBlank
检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出IllegalArgumentExceptionAssert.notBlank(name, "Name must not be blank");
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串- Returns:
- 非空字符串
- Throws:
IllegalArgumentException- 被检查字符串为空白
-
notContain
public static String notContain(String textToSearch, String substring, Supplier<String> errorMsgSupplier) throws IllegalArgumentException 断言给定字符串是否不被另一个字符串包含(即是否为子串) 并使用指定的函数获取错误信息返回Assert.doesNotContain(name, "rod", () -> { return "relation message to return"; });- Parameters:
textToSearch- 被搜索的字符串substring- 被检查的子串errorMsgSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的子串
- Throws:
IllegalArgumentException- 非子串抛出异常
-
notContain
public static String notContain(String textToSearch, String substring, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言给定字符串是否不被另一个字符串包含(既是否为子串)Assert.doesNotContain(name, "rod", "Name must not contain 'rod'");
- Parameters:
textToSearch- 被搜索的字符串substring- 被检查的子串errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的子串
- Throws:
IllegalArgumentException- 非子串抛出异常
-
notContain
public static String notContain(String textToSearch, String substring) throws IllegalArgumentException 断言给定字符串是否不被另一个字符串包含(既是否为子串)Assert.doesNotContain(name, "rod", "Name must not contain 'rod'");
- Parameters:
textToSearch- 被搜索的字符串substring- 被检查的子串- Returns:
- 被检查的子串
- Throws:
IllegalArgumentException- 非子串抛出异常
-
notEmpty
public static Object[] notEmpty(Object[] array, Supplier<String> errorMsgSupplier) throws IllegalArgumentException 断言给定数组是否包含元素,数组必须不为null且至少包含一个元素 并使用指定的函数获取错误信息返回Assert.notEmpty(array, () -> { return "relation message to return"; });- Parameters:
array- 被检查的数组errorMsgSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的数组
- Throws:
IllegalArgumentException- if the object array isnullor has no elements
-
notEmpty
public static Object[] notEmpty(Object[] array, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言给定数组是否包含元素,数组必须不为null且至少包含一个元素Assert.notEmpty(array, "The array must have elements");
- Parameters:
array- 被检查的数组errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的数组
- Throws:
IllegalArgumentException- if the object array isnullor has no elements
-
notEmpty
断言给定数组是否包含元素,数组必须不为null且至少包含一个元素Assert.notEmpty(array, "The array must have elements");
- Parameters:
array- 被检查的数组- Returns:
- 被检查的数组
- Throws:
IllegalArgumentException- 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, () -> { return new IllegalArgumentException("relation message to return "); });- Type Parameters:
T- 数组元素类型X- 异常类型- Parameters:
array- 被检查的数组errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的数组
- Throws:
X- if the object array contains anullelement- See Also:
-
noNullElements
public static <T> T[] noNullElements(T[] array, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言给定数组是否不包含null元素,如果数组为空或null将被认为不包含Assert.noNullElements(array, "The array must have non-null elements");
- Type Parameters:
T- 数组元素类型- Parameters:
array- 被检查的数组errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的数组
- Throws:
IllegalArgumentException- if the object array contains anullelement
-
noNullElements
断言给定数组是否不包含null元素,如果数组为空或null将被认为不包含Assert.noNullElements(array);
- Type Parameters:
T- 数组元素类型- Parameters:
array- 被检查的数组- Returns:
- 被检查的数组
- Throws:
IllegalArgumentException- if the object array contains anullelement
-
notEmpty
public static <T> Collection<T> notEmpty(Collection<T> collection, Supplier<String> errorMsgSupplier) throws IllegalArgumentException 断言给定集合非空 并使用指定的函数获取错误信息返回Assert.notEmpty(collection, () -> { return "relation message to return"; });- Type Parameters:
T- 集合元素类型- Parameters:
collection- 被检查的集合errorMsgSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 非空集合
- Throws:
IllegalArgumentException- if the collection isnullor has no elements
-
notEmpty
public static <T> Collection<T> notEmpty(Collection<T> collection, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言给定集合非空Assert.notEmpty(collection, "Collection must have elements");
- Type Parameters:
T- 集合元素类型- Parameters:
collection- 被检查的集合errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 非空集合
- Throws:
IllegalArgumentException- if the collection isnullor has no elements
-
notEmpty
断言给定集合非空Assert.notEmpty(collection);
- Type Parameters:
T- 集合元素类型- Parameters:
collection- 被检查的集合- Returns:
- 被检查集合
- Throws:
IllegalArgumentException- if the collection isnullor has no elements
-
notEmpty
public static <K,V> Map<K,V> notEmpty(Map<K, V> map, Supplier<String> errorMsgSupplier) throws IllegalArgumentException断言给定Map非空 并使用指定的函数获取错误信息返回Assert.notEmpty(map, () -> { return "relation message to return"; });- Type Parameters:
K- Key类型V- Value类型- Parameters:
map- 被检查的MaperrorMsgSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的Map
- Throws:
IllegalArgumentException- if the map isnullor has no entries
-
notEmpty
public static <K,V> Map<K,V> notEmpty(Map<K, V> map, String errorMsgTemplate, Object... params) throws IllegalArgumentException断言给定Map非空Assert.notEmpty(map, "Map must have entries");
- Type Parameters:
K- Key类型V- Value类型- Parameters:
map- 被检查的MaperrorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查的Map
- Throws:
IllegalArgumentException- if the map isnullor has no entries
-
notEmpty
断言给定Map非空Assert.notEmpty(map, "Map must have entries");
- Type Parameters:
K- Key类型V- Value类型- Parameters:
map- 被检查的Map- Returns:
- 被检查的Map
- Throws:
IllegalArgumentException- if the map isnullor has no entries
-
notEquals
断言两个对象是否不相等,如果两个对象相等 抛出IllegalArgumentException 异常Assert.notEquals(obj1, obj2);
- Parameters:
obj1- 对象1obj2- 对象2- Throws:
IllegalArgumentException- obj1 must be not equals obj2
-
notEquals
public static void notEquals(Object obj1, Object obj2, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言两个对象是否不相等,如果两个对象相等 抛出IllegalArgumentException 异常Assert.notEquals(obj1, obj2, "obj1 must be not equals obj2");
- Parameters:
obj1- 对象1obj2- 对象2errorMsgTemplate- 异常信息模板,类似于"aa{}bb{}cc"params- 异常信息参数,用于替换"{}"占位符- Throws:
IllegalArgumentException- obj1 must be not equals obj2
-
notEquals
-
equals
断言两个对象是否相等,如果两个对象不相等 抛出IllegalArgumentException 异常Assert.isEquals(obj1, obj2);
- Parameters:
obj1- 对象1obj2- 对象2- Throws:
IllegalArgumentException- obj1 must be equals obj2
-
equals
public static void equals(Object obj1, Object obj2, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言两个对象是否相等,如果两个对象不相等 抛出IllegalArgumentException 异常Assert.isEquals(obj1, obj2, "obj1 must be equals obj2");
- Parameters:
obj1- 对象1obj2- 对象2errorMsgTemplate- 异常信息模板,类似于"aa{}bb{}cc"params- 异常信息参数,用于替换"{}"占位符- Throws:
IllegalArgumentException- obj1 must be equals obj2
-
equals
-
isInstanceOf
断言给定对象是否是给定类的实例Assert.instanceOf(Foo.class, foo);
- Type Parameters:
T- 被检查对象泛型类型- Parameters:
type- 被检查对象匹配的类型object- 被检查对象- Returns:
- 被检查的对象
- Throws:
IllegalArgumentException- if the object is not an instance of clazz- See Also:
-
isInstanceOf
public static <T> T isInstanceOf(Class<?> type, T object, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言给定对象是否是给定类的实例Assert.instanceOf(Foo.class, foo);
- Type Parameters:
T- 被检查对象泛型类型- Parameters:
type- 被检查对象匹配的类型object- 被检查对象errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 被检查对象
- Throws:
IllegalArgumentException- if the object is not an instance of clazz- See Also:
-
isAssignable
public static void isAssignable(Class<?> superType, Class<?> subType) throws IllegalArgumentException superType.isAssignableFrom(subType)是否为trueAssert.isAssignable(Number.class, myClass);
- Parameters:
superType- 需要检查的父类或接口subType- 需要检查的子类- Throws:
IllegalArgumentException- 如果子类非继承父类,抛出此异常
-
isAssignable
public static void isAssignable(Class<?> superType, Class<?> subType, String errorMsgTemplate, Object... params) throws IllegalArgumentException superType.isAssignableFrom(subType)是否为trueAssert.isAssignable(Number.class, myClass);
- Parameters:
superType- 需要检查的父类或接口subType- 需要检查的子类errorMsgTemplate- 异常时的消息模板params- 参数列表- Throws:
IllegalArgumentException- 如果子类非继承父类,抛出此异常
-
state
public static void state(boolean expression, Supplier<String> errorMsgSupplier) throws IllegalStateException 检查boolean表达式,当检查结果为false时抛出IllegalStateException并使用指定的函数获取错误信息返回Assert.state(null == id, () -> { 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(null == id, "The id property must not already be initialized");
- Parameters:
expression- boolean 表达式errorMsgTemplate- 异常时的消息模板params- 参数列表- Throws:
IllegalStateException- if expression isfalse
-
state
检查boolean表达式,当检查结果为false时抛出IllegalStateException.Assert.state(null == id);
- Parameters:
expression- boolean 表达式- Throws:
IllegalStateException- 表达式为false抛出此异常
-
hasText
断言给定的字符串包含有效的文本内容.Assert.hasText(name, "'name' must not be empty");
- Parameters:
text- 被检查字符串message- 如果断言失败,要使用的异常消息- Throws:
IllegalArgumentException- 表达式为false抛出此异常
-
checkIndex
public static int checkIndex(int index, int size) throws IllegalArgumentException, IndexOutOfBoundsException 检查下标(数组、集合、字符串)是否符合要求,下标必须满足:0 ≤ index < size
- Parameters:
index- 下标size- 长度- Returns:
- 检查后的下标
- Throws:
IllegalArgumentException- 如果size < 0 抛出此异常IndexOutOfBoundsException- 如果index < 0或者 index ≥ size 抛出此异常
-
checkIndex
public static int checkIndex(int index, int size, String errorMsgTemplate, Object... params) throws IllegalArgumentException, IndexOutOfBoundsException 检查下标(数组、集合、字符串)是否符合要求,下标必须满足:0 ≤ index < size
- Parameters:
index- 下标size- 长度errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 检查后的下标
- Throws:
IllegalArgumentException- 如果size < 0 抛出此异常IndexOutOfBoundsException- 如果index < 0或者 index ≥ size 抛出此异常
-
checkBetween
-
checkBetween
-
checkBetween
public static int checkBetween(int value, int min, int max) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值
-
checkBetween
-
checkBetween
-
checkBetween
public static long checkBetween(long value, long min, long max) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值
-
checkBetween
-
checkBetween
-
checkBetween
public static double checkBetween(double value, double min, double max) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值
-
checkBetween
-