Package org.miaixz.bus.core.lang
Class Assert
java.lang.Object
org.miaixz.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 errorMsgTemplate, 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 errorMsgTemplate, 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 errorMsgTemplate, 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 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抛出IllegalArgumentException异常static void断言是否为假,如果为true抛出IllegalArgumentException异常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抛出IllegalArgumentException异常static void断言是否为真,如果为false抛出IllegalArgumentException异常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,X extends Throwable>
T检查给定字符串是否为空白(null、空串或只包含空白符),为空抛出自定义异常。 并使用指定的函数获取错误信息返回static <T extends CharSequence,X extends Throwable>
TnotContain(CharSequence textToSearch, T substring, Supplier<X> errorSupplier) 断言给定字符串是否不被另一个字符串包含(即是否为子串),并使用指定的函数获取错误信息返回 如果非子串,返回子串,如果是子串,则抛出IllegalArgumentException异常。static StringnotContain(String textToSearch, String subString) 断言给定字符串是否不被另一个字符串包含(即是否为子串),即subString是否不是textToSearch的子串。 如果非子串,返回子串,如果是子串,则抛出IllegalArgumentException异常。static StringnotContain(String textToSearch, String subString, String errorMsgTemplate, Object... params) 断言给定字符串是否不被另一个字符串包含(即是否为子串) 如果非子串,返回子串,如果是子串,则抛出IllegalArgumentException异常。static <T extends CharSequence>
TnotEmpty(T text) 检查给定字符串是否为空,为空抛出IllegalArgumentExceptionstatic <T> T[]notEmpty(T[] array) 断言给定数组是否包含元素,数组必须不为null且至少包含一个元素static <T> T[]断言给定数组是否包含元素,数组必须不为null且至少包含一个元素static <T,X extends Throwable>
T[]断言给定数组是否包含元素,数组必须不为null且至少包含一个元素 并使用指定的函数获取错误信息返回static <T extends CharSequence>
T检查给定字符串是否为空,为空抛出IllegalArgumentExceptionstatic <T extends CharSequence,X extends Throwable>
T检查给定字符串是否为空,为空抛出自定义异常,并使用指定的函数获取错误信息返回。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 <X extends Throwable> void isTrue(boolean expression, Supplier<? 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);
- Parameters:
expression- 布尔值- Throws:
IllegalArgumentException- 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 IllegalArgumentException("relation message to return"); });- Type Parameters:
X- 异常类型- Parameters:
expression- 布尔值errorSupplier- 指定断言不通过时抛出的异常- Throws:
X- 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 not be negative");
- Parameters:
expression- 布尔值errorMsgTemplate- 错误抛出异常附带的消息模板,变量用{}代替params- 参数列表- Throws:
IllegalArgumentException- if expression isfalse
-
isFalse
断言是否为假,如果为true抛出IllegalArgumentException异常Assert.isFalse(i < 0);
- Parameters:
expression- 布尔值- Throws:
IllegalArgumentException- if expression isfalse
-
isNull
断言对象是否为null,如果不为null抛出指定类型异常 并使用指定的函数获取错误信息返回Assert.isNull(value, ()->{ // to query relation message return new IllegalArgumentException("relation message to return"); });- Type Parameters:
X- 异常类型- Parameters:
object- 被检查的对象errorSupplier- 错误抛出异常附带的消息生产接口- Throws:
X- 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:
IllegalArgumentException- if the object is notnull
-
notNull
断言对象是否不为null,如果为null抛出指定类型异常 并使用指定的函数获取错误信息返回Assert.notNull(clazz, ()->{ // to query relation message 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,X extends Throwable> T notEmpty(T text, Supplier<X> errorSupplier) throws X 检查给定字符串是否为空,为空抛出自定义异常,并使用指定的函数获取错误信息返回。Assert.notEmpty(name, ()->{ // to query relation message return new IllegalArgumentException("relation message to return"); });- Type Parameters:
T- 字符串类型X- 异常类型- Parameters:
text- 被检查字符串errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 非空字符串
- Throws:
X- 被检查字符串为空抛出此异常- 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- 被检查字符串为空- See Also:
-
notEmpty
检查给定字符串是否为空,为空抛出IllegalArgumentExceptionAssert.notEmpty(name);
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串- Returns:
- 被检查的字符串
- Throws:
IllegalArgumentException- 被检查字符串为空- See Also:
-
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 IllegalArgumentException("relation message to return"); });- Type Parameters:
T- 字符串类型X- 异常类型- Parameters:
text- 被检查字符串errorMsgSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 非空字符串
- Throws:
X- 被检查字符串为空白- 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);
- Type Parameters:
T- 字符串类型- Parameters:
text- 被检查字符串- Returns:
- 非空字符串
- Throws:
IllegalArgumentException- 被检查字符串为空白- See Also:
-
notContain
public static <T extends CharSequence,X extends Throwable> T notContain(CharSequence textToSearch, T substring, Supplier<X> errorSupplier) throws X 断言给定字符串是否不被另一个字符串包含(即是否为子串),并使用指定的函数获取错误信息返回 如果非子串,返回子串,如果是子串,则抛出IllegalArgumentException异常。Assert.notContain(name, "rod", ()->{ // to query relation message return new IllegalArgumentException("relation message to return "); });- Type Parameters:
T- 字符串类型X- 异常类型- Parameters:
textToSearch- 被搜索的字符串substring- 被检查的子串errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的子串
- Throws:
X- 非子串抛出异常- See Also:
-
notContain
public static String notContain(String textToSearch, String subString, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言给定字符串是否不被另一个字符串包含(即是否为子串) 如果非子串,返回子串,如果是子串,则抛出IllegalArgumentException异常。Assert.notContain(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 断言给定字符串是否不被另一个字符串包含(即是否为子串),即subString是否不是textToSearch的子串。 如果非子串,返回子串,如果是子串,则抛出IllegalArgumentException异常。Assert.notContain(name, "rod");
- Parameters:
textToSearch- 被搜索的字符串subString- 被检查的子串- Returns:
- 被检查的子串
- Throws:
IllegalArgumentException- 非子串抛出异常
-
notEmpty
断言给定数组是否包含元素,数组必须不为null且至少包含一个元素 并使用指定的函数获取错误信息返回Assert.notEmpty(array, ()->{ // to query relation message return new IllegalArgumentException("relation message to return"); });- Type Parameters:
T- 数组元素类型X- 异常类型- Parameters:
array- 被检查的数组errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的数组
- Throws:
X- if the object array isnullor has no elements- See Also:
-
notEmpty
public static <T> T[] notEmpty(T[] array, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言给定数组是否包含元素,数组必须不为null且至少包含一个元素Assert.notEmpty(array, "The array must have elements");
- Type Parameters:
T- 数组元素类型- 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");
- Type Parameters:
T- 数组元素类型- 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, ()->{ // to query relation message 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 not have 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 <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 IllegalArgumentException("relation message to return"); });- Type Parameters:
E- 集合元素类型T- 集合类型X- 异常类型- Parameters:
collection- 被检查的集合errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 非空集合
- Throws:
X- if the collection isnullor has no elements- See Also:
-
notEmpty
public static <E,T extends Iterable<E>> T notEmpty(T collection, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言给定集合非空Assert.notEmpty(collection, "Collection must have elements");
- Type Parameters:
E- 集合元素类型T- 集合类型- Parameters:
collection- 被检查的集合errorMsgTemplate- 异常时的消息模板params- 参数列表- Returns:
- 非空集合
- Throws:
IllegalArgumentException- if the collection isnullor has no elements
-
notEmpty
断言给定集合非空Assert.notEmpty(collection);
- Type Parameters:
E- 集合元素类型T- 集合类型- Parameters:
collection- 被检查的集合- Returns:
- 被检查集合
- Throws:
IllegalArgumentException- 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 IllegalArgumentException("relation message to return"); });- Type Parameters:
K- Key类型V- Value类型T- Map类型X- 异常类型- Parameters:
map- 被检查的MaperrorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 被检查的Map
- Throws:
X- if the map isnullor has no entries- See Also:
-
notEmpty
public static <K,V, T notEmptyT extends Map<K, V>> (T map, String errorMsgTemplate, Object... params) throws IllegalArgumentException 断言给定Map非空Assert.notEmpty(map, "Map must have entries");
- Type Parameters:
K- Key类型V- Value类型T- Map类型- 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类型T- Map类型- Parameters:
map- 被检查的Map- Returns:
- 被检查的Map
- Throws:
IllegalArgumentException- if the map isnullor has no entries
-
isInstanceOf
断言给定对象是否是给定类的实例Assert.instanceOf(Foo.class, foo);
- Type Parameters:
T- 被检查对象泛型类型- Parameters:
type- 被检查对象匹配的类型obj- 被检查对象- Returns:
- 被检查的对象
- Throws:
IllegalArgumentException- 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 IllegalArgumentException 断言给定对象是否是给定类的实例Assert.instanceOf(Foo.class, foo, "foo must be an instance of class Foo");
- Type Parameters:
T- 被检查对象泛型类型- Parameters:
type- 被检查对象匹配的类型obj- 被检查对象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)是否为true.Assert.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)是否为true.Assert.isAssignable(Number.class, myClass, "myClass must can be assignable to class Number");
- Parameters:
superType- 需要检查的父类或接口subType- 需要检查的子类errorMsgTemplate- 异常时的消息模板params- 参数列表- Throws:
IllegalArgumentException- 如果子类非继承父类,抛出此异常
-
state
public static void state(boolean expression, Supplier<String> errorMsgSupplier) throws IllegalStateException 检查boolean表达式,当检查结果为false时抛出IllegalStateException。 并使用指定的函数获取错误信息返回Assert.state(data == 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(data == null, "The data property must not already be initialized");
- Parameters:
expression- boolean 表达式errorMsgTemplate- 异常时的消息模板params- 参数列表- Throws:
IllegalStateException- 表达式为false抛出此异常
-
state
检查boolean表达式,当检查结果为false时抛出IllegalStateException。Assert.state(data == null);
- Parameters:
expression- boolean 表达式- Throws:
IllegalStateException- 表达式为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
public static <X extends Throwable> int checkBetween(int value, int min, int max, Supplier<? extends X> errorSupplier) throws X 检查值是否在指定范围内- Type Parameters:
X- 异常类型- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 经过检查后的值
- Throws:
X- if value is out of bound
-
checkBetween
public static int checkBetween(int value, int min, int max, String errorMsgTemplate, Object... params) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)errorMsgTemplate- 异常信息模板,类似于"aa{}bb{}cc"params- 异常信息参数,用于替换"{}"占位符- Returns:
- 经过检查后的值
-
checkBetween
public static int checkBetween(int value, int min, int max) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值
-
checkBetween
public static <X extends Throwable> long checkBetween(long value, long min, long max, Supplier<? extends X> errorSupplier) throws X 检查值是否在指定范围内- Type Parameters:
X- 异常类型- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 经过检查后的值
- Throws:
X- if value is out of bound
-
checkBetween
public static long checkBetween(long value, long min, long max, String errorMsgTemplate, Object... params) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)errorMsgTemplate- 异常信息模板,类似于"aa{}bb{}cc"params- 异常信息参数,用于替换"{}"占位符- Returns:
- 经过检查后的值
-
checkBetween
public static long checkBetween(long value, long min, long max) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值
-
checkBetween
public static <X extends Throwable> double checkBetween(double value, double min, double max, Supplier<? extends X> errorSupplier) throws X 检查值是否在指定范围内- Type Parameters:
X- 异常类型- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)errorSupplier- 错误抛出异常附带的消息生产接口- Returns:
- 经过检查后的值
- Throws:
X- if value is out of bound
-
checkBetween
public static double checkBetween(double value, double min, double max, String errorMsgTemplate, Object... params) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)errorMsgTemplate- 异常信息模板,类似于"aa{}bb{}cc"params- 异常信息参数,用于替换"{}"占位符- Returns:
- 经过检查后的值
-
checkBetween
public static double checkBetween(double value, double min, double max) 检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值
-
checkBetween
检查值是否在指定范围内- Parameters:
value- 值min- 最小值(包含)max- 最大值(包含)- Returns:
- 检查后的长度值
-
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
public static <X extends Throwable> void notEquals(Object obj1, Object obj2, Supplier<X> errorSupplier) throws X 断言两个对象是否不相等,如果两个对象相等,抛出指定类型异常,并使用指定的函数获取错误信息返回- Type Parameters:
X- 异常类型- Parameters:
obj1- 对象1obj2- 对象2errorSupplier- 错误抛出异常附带的消息生产接口- Throws:
X- obj1 must be not equals obj2
-
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
public static <X extends Throwable> void equals(Object obj1, Object obj2, Supplier<X> errorSupplier) throws X 断言两个对象是否相等,如果两个对象不相等,抛出指定类型异常,并使用指定的函数获取错误信息返回- Type Parameters:
X- 异常类型- Parameters:
obj1- 对象1obj2- 对象2errorSupplier- 错误抛出异常附带的消息生产接口- Throws:
X- obj1 must be equals obj2
-