Compare commits
9 Commits
8b63eb6fe4
...
1.0.0-RC2
Author | SHA1 | Date | |
---|---|---|---|
2977c9a7fb | |||
09d596b599 | |||
b3ef6deebe | |||
f86232c404 | |||
d0785d35e8 | |||
a315edf88f | |||
b6d47f0d00 | |||
12a5740dd6 | |||
654ecd8c63 |
@@ -8,7 +8,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-validator-parent</artifactId>
|
<artifactId>plusone-validator-parent</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-RC2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>plusone-validator</artifactId>
|
<artifactId>plusone-validator</artifactId>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<url>http://zhouxy.xyz</url>
|
<url>http://zhouxy.xyz</url>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
Plusone Validator 是一个校验库,用于构建校验规则对对象(尤其是入参)进行校验。API 参考自 .NET 的 FluentValidation。
|
Plusone Validator 是一个校验库,使用 lambda 表达式(包括方法引用)和流式 API 构建校验规则,对对象进行校验。
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-commons</artifactId>
|
<artifactId>plusone-commons</artifactId>
|
||||||
<version>1.1.0-SNAPSHOT</version>
|
<version>1.1.0-RC1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
@@ -24,11 +24,13 @@ import xyz.zhouxy.plusone.commons.util.ArrayTools;
|
|||||||
import xyz.zhouxy.plusone.commons.util.AssertTools;
|
import xyz.zhouxy.plusone.commons.util.AssertTools;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 针对数组类型的属性校验器
|
* 数组类型属性的校验器
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 内置数组相关的校验规则。
|
* 用于构建校验数组类型属性的规则链。
|
||||||
*
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
|
* @param <E> 数组元素的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class ArrayPropertyValidator<T, E>
|
public class ArrayPropertyValidator<T, E>
|
||||||
@@ -45,7 +47,7 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否非空
|
* 添加一条校验属性的规则,校验属性是否非空
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final ArrayPropertyValidator<T, E> notEmpty() {
|
public final ArrayPropertyValidator<T, E> notEmpty() {
|
||||||
return withRule(Conditions.notEmpty(), "The input must not be empty.");
|
return withRule(Conditions.notEmpty(), "The input must not be empty.");
|
||||||
@@ -55,7 +57,7 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
* 添加一条校验属性的规则,校验属性是否非空
|
* 添加一条校验属性的规则,校验属性是否非空
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final ArrayPropertyValidator<T, E> notEmpty(
|
public final ArrayPropertyValidator<T, E> notEmpty(
|
||||||
final String errorMessage) {
|
final String errorMessage) {
|
||||||
@@ -67,7 +69,7 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> notEmpty(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> notEmpty(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -79,7 +81,7 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> notEmpty(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> notEmpty(
|
||||||
final Function<E[], X> exceptionFunction) {
|
final Function<E[], X> exceptionFunction) {
|
||||||
@@ -97,7 +99,7 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final ArrayPropertyValidator<T, E> isEmpty() {
|
public final ArrayPropertyValidator<T, E> isEmpty() {
|
||||||
return withRule(Conditions.isEmpty(), "The input must be empty.");
|
return withRule(Conditions.isEmpty(), "The input must be empty.");
|
||||||
@@ -107,7 +109,7 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final ArrayPropertyValidator<T, E> isEmpty(
|
public final ArrayPropertyValidator<T, E> isEmpty(
|
||||||
final String errorMessage) {
|
final String errorMessage) {
|
||||||
@@ -117,8 +119,9 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> isEmpty(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> isEmpty(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -128,8 +131,9 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> isEmpty(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> isEmpty(
|
||||||
final Function<E[], X> exceptionFunction) {
|
final Function<E[], X> exceptionFunction) {
|
||||||
@@ -145,10 +149,10 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
* @param condition 校验规则
|
* @param condition 校验条件
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final ArrayPropertyValidator<T, E> allMatch(final Predicate<E> condition) {
|
public final ArrayPropertyValidator<T, E> allMatch(final Predicate<E> condition) {
|
||||||
return withRule(c -> {
|
return withRule(c -> {
|
||||||
@@ -161,11 +165,11 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
* @param condition 校验规则
|
* @param condition 校验条件
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final ArrayPropertyValidator<T, E> allMatch(
|
public final ArrayPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final String errorMessage) {
|
final Predicate<E> condition, final String errorMessage) {
|
||||||
@@ -179,11 +183,12 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
* @param condition 校验规则
|
* @param <X> 自定义异常类型
|
||||||
|
* @param condition 校验条件
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> allMatch(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final Supplier<X> exceptionSupplier) {
|
final Predicate<E> condition, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -197,11 +202,12 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
* @param condition 校验规则
|
* @param <X> 自定义异常类型
|
||||||
|
* @param condition 校验条件
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> allMatch(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final Function<E, X> exceptionFunction) {
|
final Predicate<E> condition, final Function<E, X> exceptionFunction) {
|
||||||
@@ -225,9 +231,9 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
||||||
*
|
*
|
||||||
* @param length 指定长度
|
* @param length 预期长度
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final ArrayPropertyValidator<T, E> length(
|
public final ArrayPropertyValidator<T, E> length(
|
||||||
final int length, final String errorMessage) {
|
final int length, final String errorMessage) {
|
||||||
@@ -237,10 +243,10 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param length 指定长度
|
* @param length 预期长度
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> length(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> length(
|
||||||
final int length, final Supplier<X> exceptionSupplier) {
|
final int length, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -250,10 +256,10 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param length 指定长度
|
* @param length 预期长度
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> length(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> length(
|
||||||
final int length, final Function<E[], X> exceptionFunction) {
|
final int length, final Function<E[], X> exceptionFunction) {
|
||||||
@@ -263,10 +269,10 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性的长度范围
|
* 添加一条校验属性的规则,校验属性的长度范围
|
||||||
*
|
*
|
||||||
* @param min 最小长度
|
* @param min 最小长度(包含)
|
||||||
* @param max 最大长度
|
* @param max 最大长度(包含)
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final ArrayPropertyValidator<T, E> length(
|
public final ArrayPropertyValidator<T, E> length(
|
||||||
final int min, final int max, final String errorMessage) {
|
final int min, final int max, final String errorMessage) {
|
||||||
@@ -276,10 +282,11 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性的长度范围
|
* 添加一条校验属性的规则,校验属性的长度范围
|
||||||
*
|
*
|
||||||
* @param min 最小长度
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大长度
|
* @param min 最小长度(包含)
|
||||||
|
* @param max 最大长度(包含)
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> length(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> length(
|
||||||
final int min, final int max, final Supplier<X> exceptionSupplier) {
|
final int min, final int max, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -289,10 +296,11 @@ public class ArrayPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性的长度范围
|
* 添加一条校验属性的规则,校验属性的长度范围
|
||||||
*
|
*
|
||||||
* @param min 最小长度
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大长度
|
* @param min 最小长度(包含)
|
||||||
|
* @param max 最大长度(包含)
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> length(
|
public final <X extends RuntimeException> ArrayPropertyValidator<T, E> length(
|
||||||
final int min, final int max, final Function<E[], X> exceptionFunction) {
|
final int min, final int max, final Function<E[], X> exceptionFunction) {
|
||||||
|
@@ -23,14 +23,11 @@ import java.util.function.Supplier;
|
|||||||
import com.google.common.collect.Range;
|
import com.google.common.collect.Range;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 针对 {@code Comparable} 类型的属性校验器基类
|
* {@code Comparable} 类型属性的校验器的基类
|
||||||
*
|
*
|
||||||
* <p>
|
* @param <T> 待校验对象的类型
|
||||||
* 内置了判断属性是否在给定区间内的校验规则。
|
* @param <TProperty> 待校验属性的类型,必须实现 {@code Comparable} 接口
|
||||||
*
|
* @param <TPropertyValidator> 具体校验器类型,用于支持链式调用
|
||||||
* @param <T> 待校验对象类型
|
|
||||||
* @param <TProperty> 属性类型
|
|
||||||
* @param <TPropertyValidator> 当前属性校验器类型,用于链式调用
|
|
||||||
* @see Range
|
* @see Range
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
@@ -45,53 +42,59 @@ public abstract class BaseComparablePropertyValidator<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否在给定的区间之内
|
* 添加一条校验属性的规则,校验属性的取值范围。
|
||||||
*
|
*
|
||||||
* @param range 区间
|
* @param range 区间
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator inRange(final Range<TProperty> range) {
|
public final TPropertyValidator inRange(final Range<TProperty> range) {
|
||||||
return withRule(Conditions.inRange(range), value -> ValidationException.withMessage(
|
return withRule(Conditions.inRange(range), value -> ValidationException.withMessage(
|
||||||
"The input must in the interval %s. You entered %s.", range, value));
|
"The input must in the interval %s. You entered %s.", range, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否在给定的区间之内
|
* 添加一条校验属性的规则,校验属性的取值范围。
|
||||||
*
|
*
|
||||||
* @param range 区间
|
* @param range 区间
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 自定义错误消息模板
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator inRange(
|
public final TPropertyValidator inRange(
|
||||||
final Range<TProperty> range, final String errorMessage) {
|
final Range<TProperty> range, final String errorMessage) {
|
||||||
return withRule(Conditions.inRange(range), errorMessage);
|
return withRule(Conditions.inRange(range), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否在给定的区间之内
|
* 添加一条校验属性的规则,校验属性的取值范围。
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param range 区间
|
* @param range 区间
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator inRange(
|
public final <X extends RuntimeException> TPropertyValidator inRange(
|
||||||
final Range<TProperty> range, final Supplier<X> exceptionSupplier) {
|
final Range<TProperty> range, final Supplier<X> exceptionSupplier) {
|
||||||
return withRule(Conditions.inRange(range), exceptionSupplier);
|
return withRule(Conditions.inRange(range), exceptionSupplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否在给定的区间之内
|
* 添加一条校验属性的规则,校验属性的取值范围。
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param range 区间
|
* @param range 区间
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator inRange(
|
public final <X extends RuntimeException> TPropertyValidator inRange(
|
||||||
final Range<TProperty> range, final Function<TProperty, X> exceptionFunction) {
|
final Range<TProperty> range, final Function<TProperty, X> exceptionFunction) {
|
||||||
return withRule(Conditions.inRange(range), exceptionFunction);
|
return withRule(Conditions.inRange(range), exceptionFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验条件的实现
|
||||||
|
*/
|
||||||
private static class Conditions {
|
private static class Conditions {
|
||||||
|
|
||||||
private static <TProperty extends Comparable<TProperty>> Predicate<TProperty> inRange(
|
private static <TProperty extends Comparable<TProperty>> Predicate<TProperty> inRange(
|
||||||
final Range<TProperty> range) {
|
final Range<TProperty> range) {
|
||||||
return value -> value == null || range.contains(value);
|
return value -> value == null || range.contains(value);
|
||||||
|
@@ -28,9 +28,11 @@ import java.util.function.Supplier;
|
|||||||
* 属性校验器。包含针对属性的校验规则。
|
* 属性校验器。包含针对属性的校验规则。
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* <i>内置基础的校验规则。</i>
|
* 用于构建针对特定属性的校验规则链,支持通过链式调用添加多种校验规则。
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
|
* @param <TProperty> 待校验属性的类型
|
||||||
|
* @param <TPropertyValidator> 具体校验器类型,用于支持链式调用
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public abstract class BasePropertyValidator<
|
public abstract class BasePropertyValidator<
|
||||||
@@ -47,11 +49,12 @@ public abstract class BasePropertyValidator<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则
|
* 添加一条校验属性的规则,当条件不满足时抛出异常。
|
||||||
*
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
|
* @throws ValidationException 校验失败时抛出的异常
|
||||||
*/
|
*/
|
||||||
protected final TPropertyValidator withRule(
|
protected final TPropertyValidator withRule(
|
||||||
final Predicate<? super TProperty> condition,
|
final Predicate<? super TProperty> condition,
|
||||||
@@ -67,9 +70,10 @@ public abstract class BasePropertyValidator<
|
|||||||
* 添加一条校验属性的规则
|
* 添加一条校验属性的规则
|
||||||
*
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param errorMessageTemplate 错误信息模版
|
* @param errorMessageTemplate 异常信息模板
|
||||||
* @param errorMessageArgs 错误信息参数
|
* @param errorMessageArgs 异常信息参数
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
|
* @throws ValidationException 校验失败时抛出的异常
|
||||||
*/
|
*/
|
||||||
protected final TPropertyValidator withRule(
|
protected final TPropertyValidator withRule(
|
||||||
final Predicate<? super TProperty> condition,
|
final Predicate<? super TProperty> condition,
|
||||||
@@ -84,9 +88,10 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则
|
* 添加一条校验属性的规则
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
protected final <X extends RuntimeException> TPropertyValidator withRule(
|
protected final <X extends RuntimeException> TPropertyValidator withRule(
|
||||||
final Predicate<? super TProperty> condition,
|
final Predicate<? super TProperty> condition,
|
||||||
@@ -99,11 +104,12 @@ public abstract class BasePropertyValidator<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则
|
* 添加一条校验属性的规则,当条件不满足时抛出自定义异常。可以根据当前属性的值创建异常。
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
protected final <X extends RuntimeException> TPropertyValidator withRule(
|
protected final <X extends RuntimeException> TPropertyValidator withRule(
|
||||||
final Predicate<? super TProperty> condition,
|
final Predicate<? super TProperty> condition,
|
||||||
@@ -118,8 +124,8 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则
|
* 添加一条校验属性的规则
|
||||||
*
|
*
|
||||||
* @param rule 校验规则
|
* @param rule 自定义校验规则
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
protected final TPropertyValidator withRule(Consumer<? super TProperty> rule) {
|
protected final TPropertyValidator withRule(Consumer<? super TProperty> rule) {
|
||||||
this.consumers.add(rule);
|
this.consumers.add(rule);
|
||||||
@@ -150,7 +156,7 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否不为空
|
* 添加一条校验属性的规则,校验属性是否不为空
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator notNull() {
|
public final TPropertyValidator notNull() {
|
||||||
return withRule(Objects::nonNull, "The input must not be null.");
|
return withRule(Objects::nonNull, "The input must not be null.");
|
||||||
@@ -160,7 +166,7 @@ public abstract class BasePropertyValidator<
|
|||||||
* 添加一条校验属性的规则,校验属性是否不为空
|
* 添加一条校验属性的规则,校验属性是否不为空
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator notNull(final String errorMessage) {
|
public final TPropertyValidator notNull(final String errorMessage) {
|
||||||
return withRule(Objects::nonNull, errorMessage);
|
return withRule(Objects::nonNull, errorMessage);
|
||||||
@@ -171,7 +177,7 @@ public abstract class BasePropertyValidator<
|
|||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator notNull(
|
public final <X extends RuntimeException> TPropertyValidator notNull(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -183,7 +189,7 @@ public abstract class BasePropertyValidator<
|
|||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator notNull(
|
public final <X extends RuntimeException> TPropertyValidator notNull(
|
||||||
final Function<TProperty, X> exceptionFunction) {
|
final Function<TProperty, X> exceptionFunction) {
|
||||||
@@ -201,7 +207,7 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator isNull() {
|
public final TPropertyValidator isNull() {
|
||||||
return withRule(Objects::isNull, "The input must be null.");
|
return withRule(Objects::isNull, "The input must be null.");
|
||||||
@@ -211,7 +217,7 @@ public abstract class BasePropertyValidator<
|
|||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator isNull(final String errorMessage) {
|
public final TPropertyValidator isNull(final String errorMessage) {
|
||||||
return withRule(Objects::isNull, errorMessage);
|
return withRule(Objects::isNull, errorMessage);
|
||||||
@@ -222,7 +228,7 @@ public abstract class BasePropertyValidator<
|
|||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator isNull(
|
public final <X extends RuntimeException> TPropertyValidator isNull(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -234,7 +240,7 @@ public abstract class BasePropertyValidator<
|
|||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator isNull(
|
public final <X extends RuntimeException> TPropertyValidator isNull(
|
||||||
final Function<TProperty, X> exceptionFunction) {
|
final Function<TProperty, X> exceptionFunction) {
|
||||||
@@ -252,50 +258,50 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
* @param that 给定值
|
* @param obj 用于比较的对象
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator equal(Object that) {
|
public final TPropertyValidator equal(Object obj) {
|
||||||
return withRule(Conditions.equal(that),
|
return withRule(Conditions.equal(obj),
|
||||||
"The input must be equal to '%s'.", that);
|
"The input must be equal to '%s'.", obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
* @param that 给定值
|
* @param obj 用于比较的对象
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator equal(
|
public final TPropertyValidator equal(
|
||||||
final Object that, final String errorMessage) {
|
final Object obj, final String errorMessage) {
|
||||||
return withRule(Conditions.equal(that), errorMessage);
|
return withRule(Conditions.equal(obj), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param that 给定值
|
* @param obj 用于比较的对象
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator equal(
|
public final <X extends RuntimeException> TPropertyValidator equal(
|
||||||
final Object that, final Supplier<X> exceptionSupplier) {
|
final Object obj, final Supplier<X> exceptionSupplier) {
|
||||||
return withRule(Conditions.equal(that), exceptionSupplier);
|
return withRule(Conditions.equal(obj), exceptionSupplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param that 给定值
|
* @param obj 用于比较的对象
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator equal(
|
public final <X extends RuntimeException> TPropertyValidator equal(
|
||||||
final Object that, final Function<TProperty, X> exceptionFunction) {
|
final Object obj, final Function<TProperty, X> exceptionFunction) {
|
||||||
return withRule(Conditions.equal(that), exceptionFunction);
|
return withRule(Conditions.equal(obj), exceptionFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
@@ -309,49 +315,49 @@ public abstract class BasePropertyValidator<
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
* @param that 给定值
|
* @param obj 用于比较的对象
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator notEqual(final Object that) {
|
public final TPropertyValidator notEqual(final Object obj) {
|
||||||
return withRule(Conditions.notEqual(that),
|
return withRule(Conditions.notEqual(obj),
|
||||||
"The input must not equal '%s'.", that);
|
"The input must not equal '%s'.", obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
* @param that 给定值
|
* @param obj 用于比较的对象
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator notEqual(final Object that, final String errorMessage) {
|
public final TPropertyValidator notEqual(final Object obj, final String errorMessage) {
|
||||||
return withRule(Conditions.notEqual(that), errorMessage);
|
return withRule(Conditions.notEqual(obj), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param that 给定值
|
* @param obj 用于比较的对象
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator notEqual(
|
public final <X extends RuntimeException> TPropertyValidator notEqual(
|
||||||
final Object that, final Supplier<X> exceptionSupplier) {
|
final Object obj, final Supplier<X> exceptionSupplier) {
|
||||||
return withRule(Conditions.notEqual(that), exceptionSupplier);
|
return withRule(Conditions.notEqual(obj), exceptionSupplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否等于给定值
|
* 添加一条校验属性的规则,校验属性是否等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param that 给定值
|
* @param obj 用于比较的对象
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator notEqual(
|
public final <X extends RuntimeException> TPropertyValidator notEqual(
|
||||||
final Object that, final Function<TProperty, X> exceptionFunction) {
|
final Object obj, final Function<TProperty, X> exceptionFunction) {
|
||||||
return withRule(Conditions.notEqual(that), exceptionFunction);
|
return withRule(Conditions.notEqual(obj), exceptionFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
@@ -366,7 +372,7 @@ public abstract class BasePropertyValidator<
|
|||||||
* 添加一条校验属性的规则,校验属性是否满足给定的条件
|
* 添加一条校验属性的规则,校验属性是否满足给定的条件
|
||||||
*
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator must(final Predicate<? super TProperty> condition) {
|
public final TPropertyValidator must(final Predicate<? super TProperty> condition) {
|
||||||
return withRule(condition,
|
return withRule(condition,
|
||||||
@@ -378,7 +384,7 @@ public abstract class BasePropertyValidator<
|
|||||||
*
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final TPropertyValidator must(
|
public final TPropertyValidator must(
|
||||||
final Predicate<? super TProperty> condition,
|
final Predicate<? super TProperty> condition,
|
||||||
@@ -392,7 +398,7 @@ public abstract class BasePropertyValidator<
|
|||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验规则
|
* @param condition 校验规则
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator must(
|
public final <X extends RuntimeException> TPropertyValidator must(
|
||||||
final Predicate<? super TProperty> condition,
|
final Predicate<? super TProperty> condition,
|
||||||
@@ -406,7 +412,7 @@ public abstract class BasePropertyValidator<
|
|||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验规则
|
* @param condition 校验规则
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> TPropertyValidator must(
|
public final <X extends RuntimeException> TPropertyValidator must(
|
||||||
final Predicate<? super TProperty> condition,
|
final Predicate<? super TProperty> condition,
|
||||||
@@ -422,6 +428,9 @@ public abstract class BasePropertyValidator<
|
|||||||
// #region - conditions
|
// #region - conditions
|
||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 常用校验条件的实现
|
||||||
|
*/
|
||||||
private static class Conditions {
|
private static class Conditions {
|
||||||
|
|
||||||
private static <TProperty> Predicate<TProperty> equal(Object obj) {
|
private static <TProperty> Predicate<TProperty> equal(Object obj) {
|
||||||
|
@@ -19,6 +19,7 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -28,22 +29,19 @@ import java.util.function.Supplier;
|
|||||||
import xyz.zhouxy.plusone.validator.function.*;
|
import xyz.zhouxy.plusone.validator.function.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验器的基类
|
* 校验器基类
|
||||||
*
|
|
||||||
* <p>
|
* <p>
|
||||||
* 通过继承 {@code BaseValidator},可以自定义一个针对特定类型的校验器,包含对该类型的校验逻辑。
|
* 子类可通过添加不同的校验规则,构建完整的校验逻辑,用于校验对象。
|
||||||
*
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public abstract class BaseValidator<T> implements IValidator<T> {
|
public abstract class BaseValidator<T> implements IValidator<T> {
|
||||||
|
|
||||||
/**
|
|
||||||
* 规则集合
|
|
||||||
*/
|
|
||||||
private final List<Consumer<? super T>> rules = new ArrayList<>();
|
private final List<Consumer<? super T>> rules = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个校验规则
|
* 添加一条用于校验整个对象的规则
|
||||||
*
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
@@ -53,7 +51,7 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个校验规则
|
* 添加一条用于校验整个对象的规则
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
@@ -65,7 +63,7 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个校验规则
|
* 添加一条用于校验整个对象的规则
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
@@ -81,19 +79,21 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个校验规则
|
* 添加一条用于校验整个对象的规则
|
||||||
*
|
*
|
||||||
* @param rule 校验规则。内部包含断言条件,如果条件不满足,则抛出异常。
|
* @param rule 自定义校验规则
|
||||||
*/
|
*/
|
||||||
protected final void withRule(Consumer<? super T> rule) {
|
protected final void withRule(Consumer<? super T> rule) {
|
||||||
this.rules.add(rule);
|
this.rules.add(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个属性校验器
|
* 添加一个通用的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 属性获取函数
|
* @param <R> 属性类型
|
||||||
* @return 属性校验器
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code ObjectPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final <R> ObjectPropertyValidator<T, R> ruleFor(Function<T, R> getter) {
|
protected final <R> ObjectPropertyValidator<T, R> ruleFor(Function<T, R> getter) {
|
||||||
ObjectPropertyValidator<T, R> validator = new ObjectPropertyValidator<>(getter);
|
ObjectPropertyValidator<T, R> validator = new ObjectPropertyValidator<>(getter);
|
||||||
@@ -102,11 +102,12 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Comparable} 属性的校验器
|
* 添加一个用于校验 {@code Comparable} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param <R> 属性类型
|
* @param <R> 属性类型
|
||||||
* @param getter 属性获取函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code ComparablePropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final <R extends Comparable<R>> ComparablePropertyValidator<T, R> ruleForComparable(
|
protected final <R extends Comparable<R>> ComparablePropertyValidator<T, R> ruleForComparable(
|
||||||
Function<T, R> getter) {
|
Function<T, R> getter) {
|
||||||
@@ -116,10 +117,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Integer} 属性的校验器
|
* 添加一个用于校验 {@code Integer} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 属性获取函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code IntPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final IntPropertyValidator<T> ruleForInt(Function<T, Integer> getter) {
|
protected final IntPropertyValidator<T> ruleForInt(Function<T, Integer> getter) {
|
||||||
IntPropertyValidator<T> validator = new IntPropertyValidator<>(getter);
|
IntPropertyValidator<T> validator = new IntPropertyValidator<>(getter);
|
||||||
@@ -128,10 +130,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Integer} 属性的校验器
|
* 添加一个用于校验 {@code Integer} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 属性获取函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code IntPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final IntPropertyValidator<T> ruleFor(ToIntegerFunction<T> getter) {
|
protected final IntPropertyValidator<T> ruleFor(ToIntegerFunction<T> getter) {
|
||||||
IntPropertyValidator<T> validator = new IntPropertyValidator<>(getter);
|
IntPropertyValidator<T> validator = new IntPropertyValidator<>(getter);
|
||||||
@@ -140,10 +143,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Long} 属性的校验器
|
* 添加一个用于校验 {@code Long} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 属性获取函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code LongPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final LongPropertyValidator<T> ruleForLong(Function<T, Long> getter) {
|
protected final LongPropertyValidator<T> ruleForLong(Function<T, Long> getter) {
|
||||||
LongPropertyValidator<T> validator = new LongPropertyValidator<>(getter);
|
LongPropertyValidator<T> validator = new LongPropertyValidator<>(getter);
|
||||||
@@ -152,10 +156,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Long} 属性的校验器
|
* 添加一个用于校验 {@code Long} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 属性获取函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code LongPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final LongPropertyValidator<T> ruleFor(ToLongObjectFunction<T> getter) {
|
protected final LongPropertyValidator<T> ruleFor(ToLongObjectFunction<T> getter) {
|
||||||
LongPropertyValidator<T> validator = new LongPropertyValidator<>(getter);
|
LongPropertyValidator<T> validator = new LongPropertyValidator<>(getter);
|
||||||
@@ -164,10 +169,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Double} 属性的校验器
|
* 添加一个用于校验 {@code Double} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 属性获取函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code DoublePropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final DoublePropertyValidator<T> ruleForDouble(Function<T, Double> getter) {
|
protected final DoublePropertyValidator<T> ruleForDouble(Function<T, Double> getter) {
|
||||||
DoublePropertyValidator<T> validator = new DoublePropertyValidator<>(getter);
|
DoublePropertyValidator<T> validator = new DoublePropertyValidator<>(getter);
|
||||||
@@ -176,10 +182,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Double} 属性的校验器
|
* 添加一个用于校验 {@code Double} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 属性获取函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code DoublePropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final DoublePropertyValidator<T> ruleFor(ToDoubleObjectFunction<T> getter) {
|
protected final DoublePropertyValidator<T> ruleFor(ToDoubleObjectFunction<T> getter) {
|
||||||
DoublePropertyValidator<T> validator = new DoublePropertyValidator<>(getter);
|
DoublePropertyValidator<T> validator = new DoublePropertyValidator<>(getter);
|
||||||
@@ -188,10 +195,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Boolean} 属性的校验器
|
* 添加一个用于校验 {@code Boolean} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 属性获取函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code BoolPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final BoolPropertyValidator<T> ruleForBool(Function<T, Boolean> getter) {
|
protected final BoolPropertyValidator<T> ruleForBool(Function<T, Boolean> getter) {
|
||||||
BoolPropertyValidator<T> validator = new BoolPropertyValidator<>(getter);
|
BoolPropertyValidator<T> validator = new BoolPropertyValidator<>(getter);
|
||||||
@@ -200,10 +208,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Boolean} 属性的校验器
|
* 添加一个用于校验 {@code Boolean} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 属性获取函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code BoolPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final BoolPropertyValidator<T> ruleFor(ToBoolObjectFunction<T> getter) {
|
protected final BoolPropertyValidator<T> ruleFor(ToBoolObjectFunction<T> getter) {
|
||||||
BoolPropertyValidator<T> validator = new BoolPropertyValidator<>(getter);
|
BoolPropertyValidator<T> validator = new BoolPropertyValidator<>(getter);
|
||||||
@@ -212,10 +221,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code String} 属性的校验器
|
* 添加一个用于校验 {@code String} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 获取属性值的函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code StringPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final StringPropertyValidator<T> ruleForString(Function<T, String> getter) {
|
protected final StringPropertyValidator<T> ruleForString(Function<T, String> getter) {
|
||||||
StringPropertyValidator<T> validator = new StringPropertyValidator<>(getter);
|
StringPropertyValidator<T> validator = new StringPropertyValidator<>(getter);
|
||||||
@@ -224,10 +234,11 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code String} 属性的校验器
|
* 添加一个用于校验 {@code String} 类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 获取属性值的函数
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
* @return 属性校验器
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code StringPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final StringPropertyValidator<T> ruleFor(ToStringFunction<T> getter) {
|
protected final StringPropertyValidator<T> ruleFor(ToStringFunction<T> getter) {
|
||||||
StringPropertyValidator<T> validator = new StringPropertyValidator<>(getter);
|
StringPropertyValidator<T> validator = new StringPropertyValidator<>(getter);
|
||||||
@@ -236,10 +247,12 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对 {@code Collection} 属性的校验器
|
* 添加一个用于校验集合类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 获取属性值的函数
|
* @param <E> 集合元素类型
|
||||||
* @return 集合属性校验器
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code CollectionPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final <E> CollectionPropertyValidator<T, E> ruleForCollection(Function<T, Collection<E>> getter) {
|
protected final <E> CollectionPropertyValidator<T, E> ruleForCollection(Function<T, Collection<E>> getter) {
|
||||||
CollectionPropertyValidator<T, E> validator = new CollectionPropertyValidator<>(getter);
|
CollectionPropertyValidator<T, E> validator = new CollectionPropertyValidator<>(getter);
|
||||||
@@ -248,10 +261,12 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对数组属性的校验器
|
* 添加一个用于校验数组类型的属性校验器
|
||||||
*
|
*
|
||||||
* @param getter 获取属性值的函数
|
* @param <E> 数组元素类型
|
||||||
* @return 集合属性校验器
|
* @param getter 用于从目标对象获取属性值的函数式接口。
|
||||||
|
* 示例:{@code Person::getName}。
|
||||||
|
* @return {@code ArrayPropertyValidator}。用于添加针对该属性的校验规则。
|
||||||
*/
|
*/
|
||||||
protected final <E> ArrayPropertyValidator<T, E> ruleForArray(Function<T, E[]> getter) {
|
protected final <E> ArrayPropertyValidator<T, E> ruleForArray(Function<T, E[]> getter) {
|
||||||
ArrayPropertyValidator<T, E> validator = new ArrayPropertyValidator<>(getter);
|
ArrayPropertyValidator<T, E> validator = new ArrayPropertyValidator<>(getter);
|
||||||
@@ -261,17 +276,39 @@ public abstract class BaseValidator<T> implements IValidator<T> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个针对二元组的校验器
|
* 添加一个针对二元组的校验器
|
||||||
|
*
|
||||||
* @param <V1> 第一个元素的类型
|
* @param <V1> 第一个元素的类型
|
||||||
* @param <V2> 第二个元素的类型
|
* @param <V2> 第二个元素的类型
|
||||||
* @param getter 获取属性值的函数
|
* @param getter 根据对象构造一个二元组,通常是两个属性的值。
|
||||||
* @return 二元组校验器
|
* @return {@code PairPropertyValidator}。用于添加针对该二元组的校验规则。
|
||||||
|
*
|
||||||
|
* @deprecated 请使用 {@link #ruleFor(Function, Function)} 代替。
|
||||||
*/
|
*/
|
||||||
protected final <V1, V2> PairPropertyValidator<T, V1, V2> ruleForPair(Function<T, Entry<V1, V2>> getter) {
|
@Deprecated
|
||||||
|
protected final <V1, V2> PairPropertyValidator<T, V1, V2> ruleForPair( // NOSONAR
|
||||||
|
Function<T, Entry<V1, V2>> getter) {
|
||||||
PairPropertyValidator<T, V1, V2> validator = new PairPropertyValidator<>(getter);
|
PairPropertyValidator<T, V1, V2> validator = new PairPropertyValidator<>(getter);
|
||||||
this.rules.add(validator::validate);
|
this.rules.add(validator::validate);
|
||||||
return validator;
|
return validator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加一个针对二元组的校验器
|
||||||
|
*
|
||||||
|
* @param <V1> 第1个元素的类型
|
||||||
|
* @param <V2> 第2个元素的类型
|
||||||
|
* @param v1Getter 用于从目标对象获取第1个元素的函数式接口。示例:{@code Person::getName1}。
|
||||||
|
* @param v2Getter 用于从目标对象获取第2个元素的函数式接口。示例:{@code Person::getName2}。
|
||||||
|
* @return {@code PairPropertyValidator}。用于添加针对该二元组的校验规则。
|
||||||
|
*/
|
||||||
|
protected final <V1, V2> PairPropertyValidator<T, V1, V2> ruleFor(
|
||||||
|
Function<T, V1> v1Getter, Function<T, V2> v2Getter) {
|
||||||
|
PairPropertyValidator<T, V1, V2> validator = new PairPropertyValidator<>(
|
||||||
|
t -> new SimpleImmutableEntry<>(v1Getter.apply(t), v2Getter.apply(t)));
|
||||||
|
this.rules.add(validator::validate);
|
||||||
|
return validator;
|
||||||
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void validate(T obj) {
|
public void validate(T obj) {
|
||||||
|
@@ -21,12 +21,12 @@ import java.util.function.Predicate;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 针对 {@code Boolean} 类型的属性校验器
|
* {@code Boolean} 类型属性的校验器
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 内置了判断 Boolean 值是否为 true 或 false 的校验规则。
|
* 用于构建校验 {@code Boolean} 类型属性的规则链。
|
||||||
* </p>
|
|
||||||
*
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class BoolPropertyValidator<T>
|
public class BoolPropertyValidator<T>
|
||||||
@@ -39,30 +39,30 @@ public class BoolPropertyValidator<T>
|
|||||||
// ====== isTrueValue ======
|
// ====== isTrueValue ======
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条判断属性值是否为 {@code true} 的校验规则
|
* 添加一条校验属性的规则,校验属性是否为 {@code true}
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final BoolPropertyValidator<T> isTrueValue() {
|
public final BoolPropertyValidator<T> isTrueValue() {
|
||||||
return withRule(Conditions.isTrueValue(), "The input must be true.");
|
return withRule(Conditions.isTrueValue(), "The input must be true.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条判断属性值是否为 {@code true} 的校验规则
|
* 添加一条校验属性的规则,校验属性是否为 {@code true}
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final BoolPropertyValidator<T> isTrueValue(final String errorMessage) {
|
public final BoolPropertyValidator<T> isTrueValue(final String errorMessage) {
|
||||||
return withRule(Conditions.isTrueValue(), errorMessage);
|
return withRule(Conditions.isTrueValue(), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条判断属性值是否为 {@code true} 的校验规则
|
* 添加一条校验属性的规则,校验属性是否为 {@code true}
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> BoolPropertyValidator<T> isTrueValue(
|
public final <X extends RuntimeException> BoolPropertyValidator<T> isTrueValue(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -70,44 +70,44 @@ public class BoolPropertyValidator<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条判断属性值是否为 {@code true} 的校验规则
|
* 添加一条校验属性的规则,校验属性是否为 {@code true}
|
||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> BoolPropertyValidator<T> isTrueValue(
|
public final <X extends RuntimeException> BoolPropertyValidator<T> isTrueValue(
|
||||||
Function<Boolean, X> exceptionFunction) {
|
final Function<Boolean, X> exceptionFunction) {
|
||||||
return withRule(Conditions.isTrueValue(), exceptionFunction);
|
return withRule(Conditions.isTrueValue(), exceptionFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====== isFalseValue ======
|
// ====== isFalseValue ======
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条判断属性值是否为 {@code false} 的校验规则
|
* 添加一条校验属性的规则,校验属性是否为 {@code false}
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final BoolPropertyValidator<T> isFalseValue() {
|
public final BoolPropertyValidator<T> isFalseValue() {
|
||||||
return withRule(Conditions.isFalseValue(), "The input must be false.");
|
return withRule(Conditions.isFalseValue(), "The input must be false.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条判断属性值是否为 {@code false} 的校验规则
|
* 添加一条校验属性的规则,校验属性是否为 {@code false}
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final BoolPropertyValidator<T> isFalseValue(final String errorMessage) {
|
public final BoolPropertyValidator<T> isFalseValue(final String errorMessage) {
|
||||||
return withRule(Conditions.isFalseValue(), errorMessage);
|
return withRule(Conditions.isFalseValue(), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条判断属性值是否为 {@code false} 的校验规则
|
* 添加一条校验属性的规则,校验属性是否为 {@code false}
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> BoolPropertyValidator<T> isFalseValue(
|
public final <X extends RuntimeException> BoolPropertyValidator<T> isFalseValue(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -115,11 +115,11 @@ public class BoolPropertyValidator<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条判断属性值是否为 {@code false} 的校验规则
|
* 添加一条校验属性的规则,校验属性是否为 {@code false}
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> BoolPropertyValidator<T> isFalseValue(
|
public final <X extends RuntimeException> BoolPropertyValidator<T> isFalseValue(
|
||||||
final Function<Boolean, X> exceptionFunction) {
|
final Function<Boolean, X> exceptionFunction) {
|
||||||
|
@@ -25,11 +25,13 @@ import xyz.zhouxy.plusone.commons.collection.CollectionTools;
|
|||||||
import xyz.zhouxy.plusone.commons.util.AssertTools;
|
import xyz.zhouxy.plusone.commons.util.AssertTools;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 针对集合类型的属性校验器
|
* 集合类型属性的校验器
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 内置集合相关的校验规则。
|
* 用于构建校验集合类型属性的规则链。
|
||||||
*
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
|
* @param <E> 集合元素的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class CollectionPropertyValidator<T, E>
|
public class CollectionPropertyValidator<T, E>
|
||||||
@@ -46,7 +48,7 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否非空
|
* 添加一条校验属性的规则,校验属性是否非空
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> notEmpty() {
|
public final CollectionPropertyValidator<T, E> notEmpty() {
|
||||||
return withRule(Conditions.notEmpty(), "The input must not be empty.");
|
return withRule(Conditions.notEmpty(), "The input must not be empty.");
|
||||||
@@ -56,7 +58,7 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
* 添加一条校验属性的规则,校验属性是否非空
|
* 添加一条校验属性的规则,校验属性是否非空
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> notEmpty(final String errorMessage) {
|
public final CollectionPropertyValidator<T, E> notEmpty(final String errorMessage) {
|
||||||
return withRule(Conditions.notEmpty(), errorMessage);
|
return withRule(Conditions.notEmpty(), errorMessage);
|
||||||
@@ -67,7 +69,7 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> notEmpty(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> notEmpty(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -79,7 +81,7 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
*
|
*
|
||||||
* @param <X> 自定义异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> notEmpty(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> notEmpty(
|
||||||
final Function<Collection<E>, X> exceptionFunction) {
|
final Function<Collection<E>, X> exceptionFunction) {
|
||||||
@@ -97,7 +99,7 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> isEmpty() {
|
public final CollectionPropertyValidator<T, E> isEmpty() {
|
||||||
return withRule(Conditions.isEmpty(), "The input must be empty.");
|
return withRule(Conditions.isEmpty(), "The input must be empty.");
|
||||||
@@ -107,7 +109,7 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> isEmpty(
|
public final CollectionPropertyValidator<T, E> isEmpty(
|
||||||
final String errorMessage) {
|
final String errorMessage) {
|
||||||
@@ -117,8 +119,9 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> isEmpty(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> isEmpty(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -128,8 +131,9 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否为空
|
* 添加一条校验属性的规则,校验属性是否为空
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> isEmpty(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> isEmpty(
|
||||||
final Function<Collection<E>, X> exceptionFunction) {
|
final Function<Collection<E>, X> exceptionFunction) {
|
||||||
@@ -145,10 +149,10 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> allMatch(
|
public final CollectionPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition) {
|
final Predicate<E> condition) {
|
||||||
@@ -160,11 +164,10 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
* @param condition 校验条件
|
||||||
* @param condition 校验规则
|
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> allMatch(
|
public final CollectionPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final String errorMessage) {
|
final Predicate<E> condition, final String errorMessage) {
|
||||||
@@ -176,11 +179,12 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> allMatch(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final Supplier<X> exceptionSupplier) {
|
final Predicate<E> condition, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -192,11 +196,12 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验是否所有元素都满足条件
|
* 添加一条校验属性的规则,校验是否所有元素都满足指定条件
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> allMatch(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> allMatch(
|
||||||
final Predicate<E> condition, final Function<E, X> exceptionFunction) {
|
final Predicate<E> condition, final Function<E, X> exceptionFunction) {
|
||||||
@@ -216,11 +221,11 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性大小是否等于指定大小
|
* 添加一条校验属性的规则,校验集合大小
|
||||||
*
|
*
|
||||||
* @param size 指定大小
|
* @param size 预期集合大小
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> size(
|
public final CollectionPropertyValidator<T, E> size(
|
||||||
final int size, final String errorMessage) {
|
final int size, final String errorMessage) {
|
||||||
@@ -228,12 +233,12 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性大小是否等于指定大小
|
* 添加一条校验属性的规则,校验集合大小
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param size 指定大小
|
* @param size 预期集合大小
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> size(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> size(
|
||||||
final int size, final Supplier<X> exceptionSupplier) {
|
final int size, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -241,12 +246,12 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性大小是否等于指定大小
|
* 添加一条校验属性的规则,校验集合大小
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param size 指定大小
|
* @param size 预期集合大小
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> size(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> size(
|
||||||
final int size, final Function<Collection<E>, X> exceptionFunction) {
|
final int size, final Function<Collection<E>, X> exceptionFunction) {
|
||||||
@@ -254,12 +259,12 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性的大小范围
|
* 添加一条校验属性的规则,校验集合大小是否在指定范围内
|
||||||
*
|
*
|
||||||
* @param min 最小大小
|
* @param min 最小大小(包含)
|
||||||
* @param max 最大大小
|
* @param max 最大大小(包含)
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final CollectionPropertyValidator<T, E> size(
|
public final CollectionPropertyValidator<T, E> size(
|
||||||
final int min, final int max, final String errorMessage) {
|
final int min, final int max, final String errorMessage) {
|
||||||
@@ -267,12 +272,13 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性的大小范围
|
* 添加一条校验属性的规则,校验集合大小是否在指定范围内
|
||||||
*
|
*
|
||||||
* @param min 最小大小
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大大小
|
* @param min 最小大小(包含)
|
||||||
|
* @param max 最大大小(包含)
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> size(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> size(
|
||||||
final int min, final int max, final Supplier<X> exceptionSupplier) {
|
final int min, final int max, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -280,12 +286,13 @@ public class CollectionPropertyValidator<T, E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性的大小范围
|
* 添加一条校验属性的规则,校验集合大小是否在指定范围内
|
||||||
*
|
*
|
||||||
* @param min 最小大小
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大大小
|
* @param min 最小大小(包含)
|
||||||
|
* @param max 最大大小(包含)
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> size(
|
public final <X extends RuntimeException> CollectionPropertyValidator<T, E> size(
|
||||||
final int min, final int max, final Function<Collection<E>, X> exceptionFunction) {
|
final int min, final int max, final Function<Collection<E>, X> exceptionFunction) {
|
||||||
|
@@ -19,13 +19,10 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 针对 {@code Comparable} 类型的默认属性校验器
|
* {@code Comparable} 类型属性的校验器
|
||||||
*
|
*
|
||||||
* <p>
|
* @param <T> 待校验对象的类型
|
||||||
* 继承自 {@link BaseComparablePropertyValidator},内置了判断属性是否在给定区间内的校验规则。
|
* @param <TProperty> 待校验属性的类型,必须实现 {@code Comparable} 接口
|
||||||
*
|
|
||||||
* @param <T> 待校验对象类型
|
|
||||||
* @param <TProperty> 属性类型
|
|
||||||
* @see com.google.common.collect.Range
|
* @see com.google.common.collect.Range
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
|
@@ -21,11 +21,12 @@ import java.util.function.Predicate;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 浮点数属性校验器
|
* {@code Double} 类型属性的校验器
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 内置对 {@code Double} 类型常用的校验规则。
|
* 用于构建校验 {@code Double} 类型属性的规则链。
|
||||||
*
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class DoublePropertyValidator<T>
|
public class DoublePropertyValidator<T>
|
||||||
@@ -43,7 +44,7 @@ public class DoublePropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否大于给定值
|
* 添加一条校验属性的规则,校验属性是否大于给定值
|
||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> gt(final double min) {
|
public final DoublePropertyValidator<T> gt(final double min) {
|
||||||
return withRule(Conditions.greaterThan(min),
|
return withRule(Conditions.greaterThan(min),
|
||||||
@@ -55,7 +56,7 @@ public class DoublePropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> gt(
|
public final DoublePropertyValidator<T> gt(
|
||||||
final double min, final String errorMessage) {
|
final double min, final String errorMessage) {
|
||||||
@@ -65,10 +66,10 @@ public class DoublePropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于给定值
|
* 添加一条校验属性的规则,校验属性是否大于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> DoublePropertyValidator<T> gt(
|
public final <X extends RuntimeException> DoublePropertyValidator<T> gt(
|
||||||
final double min, final Supplier<X> exceptionSupplier) {
|
final double min, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -78,10 +79,10 @@ public class DoublePropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于给定值
|
* 添加一条校验属性的规则,校验属性是否大于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> DoublePropertyValidator<T> gt(
|
public final <X extends RuntimeException> DoublePropertyValidator<T> gt(
|
||||||
final double min, final Function<Double, X> exceptionFunction) {
|
final double min, final Function<Double, X> exceptionFunction) {
|
||||||
@@ -100,7 +101,7 @@ public class DoublePropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> ge(final double min) {
|
public final DoublePropertyValidator<T> ge(final double min) {
|
||||||
return withRule(Conditions.greaterThanOrEqualTo(min),
|
return withRule(Conditions.greaterThanOrEqualTo(min),
|
||||||
@@ -112,7 +113,7 @@ public class DoublePropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> ge(
|
public final DoublePropertyValidator<T> ge(
|
||||||
final double min, final String errorMessage) {
|
final double min, final String errorMessage) {
|
||||||
@@ -122,10 +123,10 @@ public class DoublePropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> DoublePropertyValidator<T> ge(
|
public final <X extends RuntimeException> DoublePropertyValidator<T> ge(
|
||||||
final double min, final Supplier<X> exceptionSupplier) {
|
final double min, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -135,10 +136,10 @@ public class DoublePropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> DoublePropertyValidator<T> ge(
|
public final <X extends RuntimeException> DoublePropertyValidator<T> ge(
|
||||||
final double min, final Function<Double, X> exceptionFunction) {
|
final double min, final Function<Double, X> exceptionFunction) {
|
||||||
@@ -157,7 +158,7 @@ public class DoublePropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否小于给定值
|
* 添加一条校验属性的规则,校验属性是否小于给定值
|
||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> lt(final double max) {
|
public final DoublePropertyValidator<T> lt(final double max) {
|
||||||
return withRule(Conditions.lessThan(max),
|
return withRule(Conditions.lessThan(max),
|
||||||
@@ -169,7 +170,7 @@ public class DoublePropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> lt(
|
public final DoublePropertyValidator<T> lt(
|
||||||
final double max, final String errorMessage) {
|
final double max, final String errorMessage) {
|
||||||
@@ -179,10 +180,10 @@ public class DoublePropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于给定值
|
* 添加一条校验属性的规则,校验属性是否小于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> DoublePropertyValidator<T> lt(
|
public final <X extends RuntimeException> DoublePropertyValidator<T> lt(
|
||||||
final double max, final Supplier<X> exceptionSupplier) {
|
final double max, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -192,10 +193,10 @@ public class DoublePropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于给定值
|
* 添加一条校验属性的规则,校验属性是否小于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> DoublePropertyValidator<T> lt(
|
public final <X extends RuntimeException> DoublePropertyValidator<T> lt(
|
||||||
final double max, final Function<Double, X> exceptionFunction) {
|
final double max, final Function<Double, X> exceptionFunction) {
|
||||||
@@ -214,7 +215,7 @@ public class DoublePropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> le(final double max) {
|
public final DoublePropertyValidator<T> le(final double max) {
|
||||||
return withRule(Conditions.lessThanOrEqualTo(max),
|
return withRule(Conditions.lessThanOrEqualTo(max),
|
||||||
@@ -226,7 +227,7 @@ public class DoublePropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final DoublePropertyValidator<T> le(
|
public final DoublePropertyValidator<T> le(
|
||||||
final double max, final String errorMessage) {
|
final double max, final String errorMessage) {
|
||||||
@@ -236,10 +237,10 @@ public class DoublePropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> DoublePropertyValidator<T> le(
|
public final <X extends RuntimeException> DoublePropertyValidator<T> le(
|
||||||
final double max, final Supplier<X> exceptionSupplier) {
|
final double max, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -249,10 +250,10 @@ public class DoublePropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> DoublePropertyValidator<T> le(
|
public final <X extends RuntimeException> DoublePropertyValidator<T> le(
|
||||||
final double max, final Function<Double, X> exceptionFunction) {
|
final double max, final Function<Double, X> exceptionFunction) {
|
||||||
|
@@ -18,14 +18,19 @@ package xyz.zhouxy.plusone.validator;
|
|||||||
/**
|
/**
|
||||||
* 校验器
|
* 校验器
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 用于定义对特定类型对象的校验规则
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public interface IValidator<T> {
|
public interface IValidator<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验对象
|
* 校验指定对象是否符合预定义规则
|
||||||
*
|
*
|
||||||
* @param obj
|
* @param obj 待校验的对象实例
|
||||||
*/
|
*/
|
||||||
void validate(T obj);
|
void validate(T obj);
|
||||||
}
|
}
|
||||||
|
@@ -17,15 +17,16 @@
|
|||||||
package xyz.zhouxy.plusone.validator;
|
package xyz.zhouxy.plusone.validator;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 整数属性校验器
|
* {@code Integer} 类型属性的校验器
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 内置对 {@code Integer} 类型常用的校验规则。
|
* 用于构建校验 {@code Integer} 类型属性的规则链。
|
||||||
*
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class IntPropertyValidator<T>
|
public class IntPropertyValidator<T>
|
||||||
@@ -43,9 +44,9 @@ public class IntPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否大于给定值
|
* 添加一条校验属性的规则,校验属性是否大于给定值
|
||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public IntPropertyValidator<T> gt(final int min) {
|
public final IntPropertyValidator<T> gt(final int min) {
|
||||||
return withRule(Conditions.greaterThan(min),
|
return withRule(Conditions.greaterThan(min),
|
||||||
"The input must be greater than '%d'.", min);
|
"The input must be greater than '%d'.", min);
|
||||||
}
|
}
|
||||||
@@ -55,9 +56,9 @@ public class IntPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public IntPropertyValidator<T> gt(
|
public final IntPropertyValidator<T> gt(
|
||||||
final int min, final String errorMessage) {
|
final int min, final String errorMessage) {
|
||||||
return withRule(Conditions.greaterThan(min), errorMessage);
|
return withRule(Conditions.greaterThan(min), errorMessage);
|
||||||
}
|
}
|
||||||
@@ -65,12 +66,12 @@ public class IntPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于给定值
|
* 添加一条校验属性的规则,校验属性是否大于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public <X extends RuntimeException> IntPropertyValidator<T> gt(
|
public final <X extends RuntimeException> IntPropertyValidator<T> gt(
|
||||||
final int min, final Supplier<X> exceptionSupplier) {
|
final int min, final Supplier<X> exceptionSupplier) {
|
||||||
return withRule(Conditions.greaterThan(min), exceptionSupplier);
|
return withRule(Conditions.greaterThan(min), exceptionSupplier);
|
||||||
}
|
}
|
||||||
@@ -78,12 +79,12 @@ public class IntPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于给定值
|
* 添加一条校验属性的规则,校验属性是否大于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public <X extends RuntimeException> IntPropertyValidator<T> gt(
|
public final <X extends RuntimeException> IntPropertyValidator<T> gt(
|
||||||
final int min, final Function<Integer, X> exceptionFunction) {
|
final int min, final Function<Integer, X> exceptionFunction) {
|
||||||
return withRule(Conditions.greaterThan(min), exceptionFunction);
|
return withRule(Conditions.greaterThan(min), exceptionFunction);
|
||||||
}
|
}
|
||||||
@@ -100,9 +101,9 @@ public class IntPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public IntPropertyValidator<T> ge(final int min) {
|
public final IntPropertyValidator<T> ge(final int min) {
|
||||||
return withRule(Conditions.greaterThanOrEqualTo(min),
|
return withRule(Conditions.greaterThanOrEqualTo(min),
|
||||||
"The input must be greater than or equal to '%d'.", min);
|
"The input must be greater than or equal to '%d'.", min);
|
||||||
}
|
}
|
||||||
@@ -112,21 +113,21 @@ public class IntPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public IntPropertyValidator<T> ge(final int min, final String errorMessage) {
|
public final IntPropertyValidator<T> ge(final int min, final String errorMessage) {
|
||||||
return withRule(Conditions.greaterThanOrEqualTo(min), errorMessage);
|
return withRule(Conditions.greaterThanOrEqualTo(min), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public <X extends RuntimeException> IntPropertyValidator<T> ge(
|
public final <X extends RuntimeException> IntPropertyValidator<T> ge(
|
||||||
final int min, final Supplier<X> exceptionSupplier) {
|
final int min, final Supplier<X> exceptionSupplier) {
|
||||||
return withRule(Conditions.greaterThanOrEqualTo(min), exceptionSupplier);
|
return withRule(Conditions.greaterThanOrEqualTo(min), exceptionSupplier);
|
||||||
}
|
}
|
||||||
@@ -134,12 +135,12 @@ public class IntPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public <X extends RuntimeException> IntPropertyValidator<T> ge(
|
public final <X extends RuntimeException> IntPropertyValidator<T> ge(
|
||||||
final int min, final Function<Integer, X> exceptionFunction) {
|
final int min, final Function<Integer, X> exceptionFunction) {
|
||||||
return withRule(Conditions.greaterThanOrEqualTo(min), exceptionFunction);
|
return withRule(Conditions.greaterThanOrEqualTo(min), exceptionFunction);
|
||||||
}
|
}
|
||||||
@@ -156,9 +157,9 @@ public class IntPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否小于给定值
|
* 添加一条校验属性的规则,校验属性是否小于给定值
|
||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public IntPropertyValidator<T> lt(final int max) {
|
public final IntPropertyValidator<T> lt(final int max) {
|
||||||
return withRule(Conditions.lessThan(max),
|
return withRule(Conditions.lessThan(max),
|
||||||
"The input must be less than '%d'.", max);
|
"The input must be less than '%d'.", max);
|
||||||
}
|
}
|
||||||
@@ -168,9 +169,9 @@ public class IntPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public IntPropertyValidator<T> lt(
|
public final IntPropertyValidator<T> lt(
|
||||||
final int max, final String errorMessage) {
|
final int max, final String errorMessage) {
|
||||||
return withRule(Conditions.lessThan(max), errorMessage);
|
return withRule(Conditions.lessThan(max), errorMessage);
|
||||||
}
|
}
|
||||||
@@ -178,12 +179,12 @@ public class IntPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于给定值
|
* 添加一条校验属性的规则,校验属性是否小于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public <X extends RuntimeException> IntPropertyValidator<T> lt(
|
public final <X extends RuntimeException> IntPropertyValidator<T> lt(
|
||||||
final int max, final Supplier<X> exceptionSupplier) {
|
final int max, final Supplier<X> exceptionSupplier) {
|
||||||
return withRule(Conditions.lessThan(max), exceptionSupplier);
|
return withRule(Conditions.lessThan(max), exceptionSupplier);
|
||||||
}
|
}
|
||||||
@@ -191,12 +192,12 @@ public class IntPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于给定值
|
* 添加一条校验属性的规则,校验属性是否小于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public <X extends RuntimeException> IntPropertyValidator<T> lt(
|
public final <X extends RuntimeException> IntPropertyValidator<T> lt(
|
||||||
final int max, final Function<Integer, X> exceptionFunction) {
|
final int max, final Function<Integer, X> exceptionFunction) {
|
||||||
return withRule(Conditions.lessThan(max), exceptionFunction);
|
return withRule(Conditions.lessThan(max), exceptionFunction);
|
||||||
}
|
}
|
||||||
@@ -213,9 +214,9 @@ public class IntPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public IntPropertyValidator<T> le(final int max) {
|
public final IntPropertyValidator<T> le(final int max) {
|
||||||
return withRule(Conditions.lessThanOrEqualTo(max),
|
return withRule(Conditions.lessThanOrEqualTo(max),
|
||||||
"The input must be less than or equal to '%d'.", max);
|
"The input must be less than or equal to '%d'.", max);
|
||||||
}
|
}
|
||||||
@@ -225,9 +226,9 @@ public class IntPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public IntPropertyValidator<T> le(
|
public final IntPropertyValidator<T> le(
|
||||||
final int max, final String errorMessage) {
|
final int max, final String errorMessage) {
|
||||||
return withRule(Conditions.lessThanOrEqualTo(max), errorMessage);
|
return withRule(Conditions.lessThanOrEqualTo(max), errorMessage);
|
||||||
}
|
}
|
||||||
@@ -235,12 +236,12 @@ public class IntPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public <X extends RuntimeException> IntPropertyValidator<T> le(
|
public final <X extends RuntimeException> IntPropertyValidator<T> le(
|
||||||
final int max, final Supplier<X> exceptionSupplier) {
|
final int max, final Supplier<X> exceptionSupplier) {
|
||||||
return withRule(Conditions.lessThanOrEqualTo(max), exceptionSupplier);
|
return withRule(Conditions.lessThanOrEqualTo(max), exceptionSupplier);
|
||||||
}
|
}
|
||||||
@@ -248,12 +249,12 @@ public class IntPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public <X extends RuntimeException> IntPropertyValidator<T> le(
|
public final <X extends RuntimeException> IntPropertyValidator<T> le(
|
||||||
final int max, final Function<Integer, X> exceptionFunction) {
|
final int max, final Function<Integer, X> exceptionFunction) {
|
||||||
return withRule(Conditions.lessThanOrEqualTo(max), exceptionFunction);
|
return withRule(Conditions.lessThanOrEqualTo(max), exceptionFunction);
|
||||||
}
|
}
|
||||||
|
@@ -21,11 +21,12 @@ import java.util.function.Predicate;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 长整数属性校验器
|
* {@code Long} 类型属性的校验器
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* 内置对 {@code Long} 类型常用的校验规则。
|
* 用于构建校验 {@code Long} 类型属性的规则链。
|
||||||
*
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class LongPropertyValidator<T>
|
public class LongPropertyValidator<T>
|
||||||
@@ -43,7 +44,7 @@ public class LongPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否大于给定值
|
* 添加一条校验属性的规则,校验属性是否大于给定值
|
||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final LongPropertyValidator<T> gt(final long min) {
|
public final LongPropertyValidator<T> gt(final long min) {
|
||||||
return withRule(Conditions.greaterThan(min),
|
return withRule(Conditions.greaterThan(min),
|
||||||
@@ -55,7 +56,7 @@ public class LongPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final LongPropertyValidator<T> gt(
|
public final LongPropertyValidator<T> gt(
|
||||||
final long min, final String errorMessage) {
|
final long min, final String errorMessage) {
|
||||||
@@ -65,10 +66,10 @@ public class LongPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于给定值
|
* 添加一条校验属性的规则,校验属性是否大于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> LongPropertyValidator<T> gt(
|
public final <X extends RuntimeException> LongPropertyValidator<T> gt(
|
||||||
final long min, final Supplier<X> exceptionSupplier) {
|
final long min, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -78,10 +79,10 @@ public class LongPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于给定值
|
* 添加一条校验属性的规则,校验属性是否大于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> LongPropertyValidator<T> gt(
|
public final <X extends RuntimeException> LongPropertyValidator<T> gt(
|
||||||
final long min, final Function<Long, X> exceptionFunction) {
|
final long min, final Function<Long, X> exceptionFunction) {
|
||||||
@@ -100,7 +101,7 @@ public class LongPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final LongPropertyValidator<T> ge(final long min) {
|
public final LongPropertyValidator<T> ge(final long min) {
|
||||||
return withRule(Conditions.greaterThanOrEqualTo(min),
|
return withRule(Conditions.greaterThanOrEqualTo(min),
|
||||||
@@ -112,20 +113,19 @@ public class LongPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final LongPropertyValidator<T> ge(
|
public final LongPropertyValidator<T> ge(final long min, final String errorMessage) {
|
||||||
final long min, final String errorMessage) {
|
|
||||||
return withRule(Conditions.greaterThanOrEqualTo(min), errorMessage);
|
return withRule(Conditions.greaterThanOrEqualTo(min), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> LongPropertyValidator<T> ge(
|
public final <X extends RuntimeException> LongPropertyValidator<T> ge(
|
||||||
final long min, final Supplier<X> exceptionSupplier) {
|
final long min, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -135,10 +135,10 @@ public class LongPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
* 添加一条校验属性的规则,校验属性是否大于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小值
|
* @param min 最小值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> LongPropertyValidator<T> ge(
|
public final <X extends RuntimeException> LongPropertyValidator<T> ge(
|
||||||
final long min, final Function<Long, X> exceptionFunction) {
|
final long min, final Function<Long, X> exceptionFunction) {
|
||||||
@@ -157,7 +157,7 @@ public class LongPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否小于给定值
|
* 添加一条校验属性的规则,校验属性是否小于给定值
|
||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final LongPropertyValidator<T> lt(final long max) {
|
public final LongPropertyValidator<T> lt(final long max) {
|
||||||
return withRule(Conditions.lessThan(max),
|
return withRule(Conditions.lessThan(max),
|
||||||
@@ -169,7 +169,7 @@ public class LongPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final LongPropertyValidator<T> lt(
|
public final LongPropertyValidator<T> lt(
|
||||||
final long max, final String errorMessage) {
|
final long max, final String errorMessage) {
|
||||||
@@ -179,10 +179,10 @@ public class LongPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于给定值
|
* 添加一条校验属性的规则,校验属性是否小于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> LongPropertyValidator<T> lt(
|
public final <X extends RuntimeException> LongPropertyValidator<T> lt(
|
||||||
final long max, final Supplier<X> exceptionSupplier) {
|
final long max, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -192,10 +192,10 @@ public class LongPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于给定值
|
* 添加一条校验属性的规则,校验属性是否小于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> LongPropertyValidator<T> lt(
|
public final <X extends RuntimeException> LongPropertyValidator<T> lt(
|
||||||
final long max, final Function<Long, X> exceptionFunction) {
|
final long max, final Function<Long, X> exceptionFunction) {
|
||||||
@@ -214,7 +214,7 @@ public class LongPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final LongPropertyValidator<T> le(final long max) {
|
public final LongPropertyValidator<T> le(final long max) {
|
||||||
return withRule(Conditions.lessThanOrEqualTo(max),
|
return withRule(Conditions.lessThanOrEqualTo(max),
|
||||||
@@ -226,7 +226,7 @@ public class LongPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final LongPropertyValidator<T> le(
|
public final LongPropertyValidator<T> le(
|
||||||
final long max, final String errorMessage) {
|
final long max, final String errorMessage) {
|
||||||
@@ -236,10 +236,10 @@ public class LongPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> LongPropertyValidator<T> le(
|
public final <X extends RuntimeException> LongPropertyValidator<T> le(
|
||||||
final long max, final Supplier<X> exceptionSupplier) {
|
final long max, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -249,10 +249,10 @@ public class LongPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
* 添加一条校验属性的规则,校验属性是否小于等于给定值
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param max 最大值
|
* @param max 最大值
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前验证器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> LongPropertyValidator<T> le(
|
public final <X extends RuntimeException> LongPropertyValidator<T> le(
|
||||||
final long max, final Function<Long, X> exceptionFunction) {
|
final long max, final Function<Long, X> exceptionFunction) {
|
||||||
|
@@ -16,11 +16,9 @@
|
|||||||
|
|
||||||
package xyz.zhouxy.plusone.validator;
|
package xyz.zhouxy.plusone.validator;
|
||||||
|
|
||||||
import java.util.AbstractMap.SimpleImmutableEntry;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -196,18 +194,19 @@ public abstract class MapValidator<K, V> extends BaseValidator<Map<K, V>> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一个属性校验器,对指定的两个 key 对应的 value 进行校验
|
* 添加一个属性校验器,对指定的两个 key 对应的 value 进行校验
|
||||||
* @param <V1> 第一个属性的类型
|
* @param <V1> 第1个属性的类型
|
||||||
* @param <V2> 第二个属性的类型
|
* @param <V2> 第2个属性的类型
|
||||||
* @param k1 第一个 key
|
* @param k1 第1个 key
|
||||||
* @param k2 第二个 key
|
* @param k2 第2个 key
|
||||||
* @return 属性校验器
|
* @return 属性校验器
|
||||||
*/
|
*/
|
||||||
protected final <V1 extends V, V2 extends V>
|
protected final <V1 extends V, V2 extends V>
|
||||||
PairPropertyValidator<Map<K, V>, V1, V2> ruleForPair(K k1, K k2) {
|
PairPropertyValidator<Map<K, V>, V1, V2> ruleForPair(K k1, K k2) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Function<Map<K, V>, Entry<V1, V2>> getter = m ->
|
final Function<Map<K, V>, V1> v1Getter = m -> (V1) m.get(k1);
|
||||||
new SimpleImmutableEntry<>((V1) m.get(k1), (V2) m.get(k2));
|
@SuppressWarnings("unchecked")
|
||||||
return ruleForPair(getter);
|
final Function<Map<K, V>, V2> v2Getter = m -> (V2) m.get(k2);
|
||||||
|
return ruleFor(v1Getter, v2Getter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
|
@@ -21,6 +21,8 @@ import java.util.function.Function;
|
|||||||
/**
|
/**
|
||||||
* 通用类型属性校验器。继承自 {@link BasePropertyValidator},包含针对属性的校验规则。
|
* 通用类型属性校验器。继承自 {@link BasePropertyValidator},包含针对属性的校验规则。
|
||||||
*
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
|
* @param <TProperty> 待校验属性的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class ObjectPropertyValidator<T, TProperty>
|
public class ObjectPropertyValidator<T, TProperty>
|
||||||
|
@@ -24,6 +24,9 @@ import java.util.function.Supplier;
|
|||||||
/**
|
/**
|
||||||
* 针对二元组的属性校验器
|
* 针对二元组的属性校验器
|
||||||
*
|
*
|
||||||
|
* @param <T> 被验证对象类型
|
||||||
|
* @param <V1> 第一个元素的类型
|
||||||
|
* @param <V2> 第二个元素的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class PairPropertyValidator<T, V1, V2>
|
public class PairPropertyValidator<T, V1, V2>
|
||||||
@@ -57,6 +60,7 @@ public class PairPropertyValidator<T, V1, V2>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验二元组是否满足给定的条件
|
* 添加一条校验属性的规则,校验二元组是否满足给定的条件
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 属性校验器
|
||||||
@@ -66,9 +70,10 @@ public class PairPropertyValidator<T, V1, V2>
|
|||||||
return must(pair -> condition.test(pair.getKey(), pair.getValue()), exceptionSupplier);
|
return must(pair -> condition.test(pair.getKey(), pair.getValue()), exceptionSupplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验二元组是否满足给定的条件
|
* 添加一条校验属性的规则,校验二元组是否满足给定的条件
|
||||||
*
|
*
|
||||||
|
* @param <X> 自定义异常类型
|
||||||
* @param condition 校验条件
|
* @param condition 校验条件
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 属性校验器
|
||||||
|
@@ -29,8 +29,12 @@ import xyz.zhouxy.plusone.commons.util.RegexTools;
|
|||||||
import xyz.zhouxy.plusone.commons.util.StringTools;
|
import xyz.zhouxy.plusone.commons.util.StringTools;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 针对文本类型的属性校验器。
|
* {@code String} 类型属性的校验器
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 用于构建校验 {@code String} 类型属性的规则链。
|
||||||
|
*
|
||||||
|
* @param <T> 待校验对象的类型
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
public class StringPropertyValidator<T>
|
public class StringPropertyValidator<T>
|
||||||
@@ -49,7 +53,7 @@ public class StringPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param pattern 正则表达式
|
* @param pattern 正则表达式
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> matches(
|
public final StringPropertyValidator<T> matches(
|
||||||
final Pattern pattern, final String errorMessage) {
|
final Pattern pattern, final String errorMessage) {
|
||||||
@@ -59,10 +63,10 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配正则表达式
|
* 添加一条校验属性的规则,校验属性是否匹配正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param pattern 正则表达式
|
* @param pattern 正则表达式
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public <X extends RuntimeException> StringPropertyValidator<T> matches(
|
public <X extends RuntimeException> StringPropertyValidator<T> matches(
|
||||||
final Pattern pattern, final Supplier<X> exceptionSupplier) {
|
final Pattern pattern, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -72,10 +76,10 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配正则表达式
|
* 添加一条校验属性的规则,校验属性是否匹配正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param pattern 正则表达式
|
* @param pattern 正则表达式
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> matches(
|
public final <X extends RuntimeException> StringPropertyValidator<T> matches(
|
||||||
final Pattern pattern, final Function<String, X> exceptionFunction) {
|
final Pattern pattern, final Function<String, X> exceptionFunction) {
|
||||||
@@ -91,11 +95,11 @@ public class StringPropertyValidator<T>
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的多个正则表达式的其中一个
|
* 添加一条校验属性的规则,校验属性是否匹配指定的任一正则表达式
|
||||||
*
|
*
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> matchesAny(
|
public final StringPropertyValidator<T> matchesAny(
|
||||||
final Pattern[] patterns, final String errorMessage) {
|
final Pattern[] patterns, final String errorMessage) {
|
||||||
@@ -103,12 +107,12 @@ public class StringPropertyValidator<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的多个正则表达式的其中一个
|
* 添加一条校验属性的规则,校验属性是否匹配指定的任一正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
|
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
|
||||||
final Pattern[] patterns, final Supplier<X> exceptionSupplier) {
|
final Pattern[] patterns, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -116,12 +120,12 @@ public class StringPropertyValidator<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的多个正则表达式的其中一个
|
* 添加一条校验属性的规则,校验属性是否匹配指定的任一正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
|
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
|
||||||
final Pattern[] patterns, final Function<String, X> exceptionFunction) {
|
final Pattern[] patterns, final Function<String, X> exceptionFunction) {
|
||||||
@@ -129,11 +133,11 @@ public class StringPropertyValidator<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的多个正则表达式的其中一个
|
* 添加一条校验属性的规则,校验属性是否匹配指定的任一正则表达式
|
||||||
*
|
*
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> matchesAny(
|
public final StringPropertyValidator<T> matchesAny(
|
||||||
final Collection<Pattern> patterns, final String errorMessage) {
|
final Collection<Pattern> patterns, final String errorMessage) {
|
||||||
@@ -141,12 +145,12 @@ public class StringPropertyValidator<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的多个正则表达式的其中一个
|
* 添加一条校验属性的规则,校验属性是否匹配指定的任一正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
|
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
|
||||||
final Collection<Pattern> patterns, final Supplier<X> exceptionSupplier) {
|
final Collection<Pattern> patterns, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -154,12 +158,12 @@ public class StringPropertyValidator<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的多个正则表达式的其中一个
|
* 添加一条校验属性的规则,校验属性是否匹配指定的任一正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
|
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
|
||||||
final Collection<Pattern> patterns, final Function<String, X> exceptionFunction) {
|
final Collection<Pattern> patterns, final Function<String, X> exceptionFunction) {
|
||||||
@@ -179,7 +183,7 @@ public class StringPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> matchesAll(
|
public final StringPropertyValidator<T> matchesAll(
|
||||||
final Pattern[] patterns, final String errorMessage) {
|
final Pattern[] patterns, final String errorMessage) {
|
||||||
@@ -189,10 +193,10 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的所有正则表达式
|
* 添加一条校验属性的规则,校验属性是否匹配指定的所有正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
||||||
final Pattern[] patterns, final Supplier<X> exceptionSupplier) {
|
final Pattern[] patterns, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -202,10 +206,10 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的所有正则表达式
|
* 添加一条校验属性的规则,校验属性是否匹配指定的所有正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
||||||
final Pattern[] patterns, final Function<String, X> exceptionFunction) {
|
final Pattern[] patterns, final Function<String, X> exceptionFunction) {
|
||||||
@@ -217,7 +221,7 @@ public class StringPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> matchesAll(
|
public final StringPropertyValidator<T> matchesAll(
|
||||||
final Collection<Pattern> patterns, final String errorMessage) {
|
final Collection<Pattern> patterns, final String errorMessage) {
|
||||||
@@ -227,10 +231,10 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的所有正则表达式
|
* 添加一条校验属性的规则,校验属性是否匹配指定的所有正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
||||||
final Collection<Pattern> patterns, final Supplier<X> exceptionSupplier) {
|
final Collection<Pattern> patterns, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -240,10 +244,10 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否匹配指定的所有正则表达式
|
* 添加一条校验属性的规则,校验属性是否匹配指定的所有正则表达式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param patterns 正则表达式
|
* @param patterns 正则表达式
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAll(
|
||||||
final Collection<Pattern> patterns, final Function<String, X> exceptionFunction) {
|
final Collection<Pattern> patterns, final Function<String, X> exceptionFunction) {
|
||||||
@@ -261,7 +265,7 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否不为空白字符串
|
* 添加一条校验属性的规则,校验属性是否不为空白字符串
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> notBlank() {
|
public final StringPropertyValidator<T> notBlank() {
|
||||||
return withRule(Conditions.notBlank(),
|
return withRule(Conditions.notBlank(),
|
||||||
@@ -272,7 +276,7 @@ public class StringPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验属性是否不为空白字符串
|
* 添加一条校验属性的规则,校验属性是否不为空白字符串
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> notBlank(final String errorMessage) {
|
public final StringPropertyValidator<T> notBlank(final String errorMessage) {
|
||||||
return withRule(Conditions.notBlank(), errorMessage);
|
return withRule(Conditions.notBlank(), errorMessage);
|
||||||
@@ -281,9 +285,9 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否不为空白字符串
|
* 添加一条校验属性的规则,校验属性是否不为空白字符串
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> notBlank(
|
public final <X extends RuntimeException> StringPropertyValidator<T> notBlank(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -293,9 +297,9 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否不为空白字符串
|
* 添加一条校验属性的规则,校验属性是否不为空白字符串
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> notBlank(
|
public final <X extends RuntimeException> StringPropertyValidator<T> notBlank(
|
||||||
final Function<String, X> exceptionFunction) {
|
final Function<String, X> exceptionFunction) {
|
||||||
@@ -311,9 +315,9 @@ public class StringPropertyValidator<T>
|
|||||||
// ================================
|
// ================================
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否是邮箱地址
|
* 添加一条校验属性的规则,校验属性是否满足邮箱格式
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> emailAddress() {
|
public final StringPropertyValidator<T> emailAddress() {
|
||||||
return withRule(Conditions.emailAddress(),
|
return withRule(Conditions.emailAddress(),
|
||||||
@@ -321,21 +325,21 @@ public class StringPropertyValidator<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否是邮箱地址
|
* 添加一条校验属性的规则,校验属性是否满足邮箱格式
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> emailAddress(final String errorMessage) {
|
public final StringPropertyValidator<T> emailAddress(final String errorMessage) {
|
||||||
return withRule(Conditions.emailAddress(), errorMessage);
|
return withRule(Conditions.emailAddress(), errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否是邮箱地址
|
* 添加一条校验属性的规则,校验属性是否满足邮箱格式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> emailAddress(
|
public final <X extends RuntimeException> StringPropertyValidator<T> emailAddress(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -343,11 +347,11 @@ public class StringPropertyValidator<T>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性是否是邮箱地址
|
* 添加一条校验属性的规则,校验属性是否满足邮箱格式
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> emailAddress(
|
public final <X extends RuntimeException> StringPropertyValidator<T> emailAddress(
|
||||||
final Function<String, X> exceptionFunction) {
|
final Function<String, X> exceptionFunction) {
|
||||||
@@ -365,7 +369,7 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验字符串属性是否不为空
|
* 添加一条校验属性的规则,校验字符串属性是否不为空
|
||||||
*
|
*
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> notEmpty() {
|
public final StringPropertyValidator<T> notEmpty() {
|
||||||
return withRule(Conditions.notEmpty(),
|
return withRule(Conditions.notEmpty(),
|
||||||
@@ -376,7 +380,7 @@ public class StringPropertyValidator<T>
|
|||||||
* 添加一条校验属性的规则,校验字符串属性是否不为空
|
* 添加一条校验属性的规则,校验字符串属性是否不为空
|
||||||
*
|
*
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> notEmpty(final String errorMessage) {
|
public final StringPropertyValidator<T> notEmpty(final String errorMessage) {
|
||||||
return withRule(Conditions.notEmpty(), errorMessage);
|
return withRule(Conditions.notEmpty(), errorMessage);
|
||||||
@@ -385,9 +389,9 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验字符串属性是否不为空
|
* 添加一条校验属性的规则,校验字符串属性是否不为空
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> notEmpty(
|
public final <X extends RuntimeException> StringPropertyValidator<T> notEmpty(
|
||||||
final Supplier<X> exceptionSupplier) {
|
final Supplier<X> exceptionSupplier) {
|
||||||
@@ -397,9 +401,9 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验字符串属性是否不为空
|
* 添加一条校验属性的规则,校验字符串属性是否不为空
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> notEmpty(
|
public final <X extends RuntimeException> StringPropertyValidator<T> notEmpty(
|
||||||
final Function<String, X> exceptionFunction) {
|
final Function<String, X> exceptionFunction) {
|
||||||
@@ -419,7 +423,7 @@ public class StringPropertyValidator<T>
|
|||||||
*
|
*
|
||||||
* @param length 指定长度
|
* @param length 指定长度
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> length(
|
public final StringPropertyValidator<T> length(
|
||||||
final int length, final String errorMessage) {
|
final int length, final String errorMessage) {
|
||||||
@@ -429,10 +433,10 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param length 指定长度
|
* @param length 指定长度
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> length(
|
public final <X extends RuntimeException> StringPropertyValidator<T> length(
|
||||||
final int length, final Supplier<X> exceptionSupplier) {
|
final int length, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -442,10 +446,10 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
* 添加一条校验属性的规则,校验属性长度是否等于指定长度
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param length 指定长度
|
* @param length 指定长度
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> length(
|
public final <X extends RuntimeException> StringPropertyValidator<T> length(
|
||||||
final int length, final Function<String, X> exceptionFunction) {
|
final int length, final Function<String, X> exceptionFunction) {
|
||||||
@@ -455,10 +459,10 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性的长度范围
|
* 添加一条校验属性的规则,校验属性的长度范围
|
||||||
*
|
*
|
||||||
* @param min 最小长度
|
* @param min 最小长度(包含)
|
||||||
* @param max 最大长度
|
* @param max 最大长度(包含)
|
||||||
* @param errorMessage 异常信息
|
* @param errorMessage 异常信息
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final StringPropertyValidator<T> length(
|
public final StringPropertyValidator<T> length(
|
||||||
final int min, final int max, final String errorMessage) {
|
final int min, final int max, final String errorMessage) {
|
||||||
@@ -468,11 +472,11 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性的长度范围
|
* 添加一条校验属性的规则,校验属性的长度范围
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小长度
|
* @param min 最小长度(包含)
|
||||||
* @param max 最大长度
|
* @param max 最大长度(包含)
|
||||||
* @param exceptionSupplier 自定义异常
|
* @param exceptionSupplier 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> length(
|
public final <X extends RuntimeException> StringPropertyValidator<T> length(
|
||||||
final int min, final int max, final Supplier<X> exceptionSupplier) {
|
final int min, final int max, final Supplier<X> exceptionSupplier) {
|
||||||
@@ -482,11 +486,11 @@ public class StringPropertyValidator<T>
|
|||||||
/**
|
/**
|
||||||
* 添加一条校验属性的规则,校验属性的长度范围
|
* 添加一条校验属性的规则,校验属性的长度范围
|
||||||
*
|
*
|
||||||
* @param <X> 异常类型
|
* @param <X> 自定义异常类型
|
||||||
* @param min 最小长度
|
* @param min 最小长度(包含)
|
||||||
* @param max 最大长度
|
* @param max 最大长度(包含)
|
||||||
* @param exceptionFunction 自定义异常
|
* @param exceptionFunction 自定义异常
|
||||||
* @return 属性校验器
|
* @return 当前校验器实例,用于链式调用
|
||||||
*/
|
*/
|
||||||
public final <X extends RuntimeException> StringPropertyValidator<T> length(
|
public final <X extends RuntimeException> StringPropertyValidator<T> length(
|
||||||
final int min, final int max, final Function<String, X> exceptionFunction) {
|
final int min, final int max, final Function<String, X> exceptionFunction) {
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
package xyz.zhouxy.plusone.validator;
|
package xyz.zhouxy.plusone.validator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证失败的异常
|
* 校验失败异常
|
||||||
*
|
*
|
||||||
* @author ZhouXY
|
* @author ZhouXY
|
||||||
*/
|
*/
|
||||||
@@ -39,51 +39,51 @@ public class ValidationException extends RuntimeException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个验证失败异常
|
* 创建 {@code ValidationException} 实例
|
||||||
*
|
*
|
||||||
* @return 异常
|
* @return {@code ValidationException} 实例
|
||||||
*/
|
*/
|
||||||
public static ValidationException withDefaultMessage() {
|
public static ValidationException withDefaultMessage() {
|
||||||
return new ValidationException(DEFAULT_MESSAGE);
|
return new ValidationException(DEFAULT_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个验证失败异常
|
* 创建 {@code ValidationException} 实例
|
||||||
*
|
*
|
||||||
* @param message 错误信息
|
* @param message 异常信息
|
||||||
* @return 异常
|
* @return {@code ValidationException} 实例
|
||||||
*/
|
*/
|
||||||
public static ValidationException withMessage(String message) {
|
public static ValidationException withMessage(String message) {
|
||||||
return new ValidationException(message);
|
return new ValidationException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个验证失败异常
|
* 创建 {@code ValidationException} 实例
|
||||||
*
|
*
|
||||||
* @param errorMessageTemplate 异常信息模版
|
* @param errorMessageTemplate 异常信息模板
|
||||||
* @param errorMessageArgs 异常信息参数
|
* @param errorMessageArgs 异常信息参数列表
|
||||||
* @return 异常
|
* @return {@code ValidationException} 实例
|
||||||
*/
|
*/
|
||||||
public static ValidationException withMessage(String errorMessageTemplate, Object... errorMessageArgs) {
|
public static ValidationException withMessage(String errorMessageTemplate, Object... errorMessageArgs) {
|
||||||
return new ValidationException(String.format(errorMessageTemplate, errorMessageArgs));
|
return new ValidationException(String.format(errorMessageTemplate, errorMessageArgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个验证失败异常
|
* 创建 {@code ValidationException} 实例
|
||||||
*
|
*
|
||||||
* @param cause 错误 cause
|
* @param cause 导致校验失败的根本异常
|
||||||
* @return 异常
|
* @return {@code ValidationException} 实例
|
||||||
*/
|
*/
|
||||||
public static ValidationException withCause(Throwable cause) {
|
public static ValidationException withCause(Throwable cause) {
|
||||||
return new ValidationException(cause);
|
return new ValidationException(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建一个验证失败异常
|
* 创建 {@code ValidationException} 实例
|
||||||
*
|
*
|
||||||
* @param message 错误信息
|
* @param message 异常信息
|
||||||
* @param cause 错误 cause
|
* @param cause 导致校验失败的根本异常
|
||||||
* @return 异常
|
* @return {@code ValidationException} 实例
|
||||||
*/
|
*/
|
||||||
public static ValidationException withMessageAndCause(String message, Throwable cause) {
|
public static ValidationException withMessageAndCause(String message, Throwable cause) {
|
||||||
return new ValidationException(message, cause);
|
return new ValidationException(message, cause);
|
||||||
|
@@ -31,6 +31,7 @@ import xyz.zhouxy.plusone.validator.BaseValidator;
|
|||||||
import xyz.zhouxy.plusone.validator.IValidator;
|
import xyz.zhouxy.plusone.validator.IValidator;
|
||||||
import xyz.zhouxy.plusone.validator.ValidationException;
|
import xyz.zhouxy.plusone.validator.ValidationException;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public class PairPropertyValidatorTests {
|
public class PairPropertyValidatorTests {
|
||||||
|
|
||||||
static final String MESSAGE = "Validation failed.";
|
static final String MESSAGE = "Validation failed.";
|
||||||
@@ -41,7 +42,9 @@ public class PairPropertyValidatorTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void must_validInput() {
|
void must_validInput() {
|
||||||
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
|
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "100");
|
||||||
|
|
||||||
|
IValidator<ExampleCommand> validator1 = new BaseValidator<ExampleCommand>() {
|
||||||
{
|
{
|
||||||
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
||||||
.must((str, intValue) -> Objects.equals(str, intValue.toString()))
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()))
|
||||||
@@ -51,69 +54,113 @@ public class PairPropertyValidatorTests {
|
|||||||
(str, intValue) -> ExampleException.withMessage("Validation failed: ('%s', %d).", str, intValue));
|
(str, intValue) -> ExampleException.withMessage("Validation failed: ('%s', %d).", str, intValue));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
assertDoesNotThrow(() -> validator1.validate(command));
|
||||||
|
|
||||||
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "100");
|
IValidator<ExampleCommand> validator2 = new BaseValidator<ExampleCommand>() {
|
||||||
assertDoesNotThrow(() -> validator.validate(command));
|
{
|
||||||
|
ruleFor(ExampleCommand::getStringProperty, ExampleCommand::getIntProperty)
|
||||||
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()))
|
||||||
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()), MESSAGE)
|
||||||
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()), () -> ExampleException.withMessage(MESSAGE))
|
||||||
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()),
|
||||||
|
(str, intValue) -> ExampleException.withMessage("Validation failed: ('%s', %d).", str, intValue));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
assertDoesNotThrow(() -> validator2.validate(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void must_default_invalidInput() {
|
void must_default_invalidInput() {
|
||||||
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
|
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "");
|
||||||
|
|
||||||
|
IValidator<ExampleCommand> validator1 = new BaseValidator<ExampleCommand>() {
|
||||||
{
|
{
|
||||||
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
||||||
.must((str, intValue) -> Objects.equals(str, intValue.toString()));
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
ValidationException e1 = assertThrows(ValidationException.class, () -> validator1.validate(command));
|
||||||
|
assertEquals("The specified condition was not met for the input.", e1.getMessage());
|
||||||
|
|
||||||
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "");
|
IValidator<ExampleCommand> validator2 = new BaseValidator<ExampleCommand>() {
|
||||||
|
{
|
||||||
ValidationException e = assertThrows(ValidationException.class, () -> validator.validate(command));
|
ruleFor(ExampleCommand::getStringProperty, ExampleCommand::getIntProperty)
|
||||||
assertEquals("The specified condition was not met for the input.", e.getMessage());
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ValidationException e2 = assertThrows(ValidationException.class, () -> validator2.validate(command));
|
||||||
|
assertEquals("The specified condition was not met for the input.", e2.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void must_message_invalidInput() {
|
void must_message_invalidInput() {
|
||||||
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
|
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "");
|
||||||
|
|
||||||
|
IValidator<ExampleCommand> validator1 = new BaseValidator<ExampleCommand>() {
|
||||||
{
|
{
|
||||||
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
||||||
.must((str, intValue) -> Objects.equals(str, intValue.toString()), MESSAGE);
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()), MESSAGE);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
ValidationException e1 = assertThrows(ValidationException.class, () -> validator1.validate(command));
|
||||||
|
assertEquals(MESSAGE, e1.getMessage());
|
||||||
|
|
||||||
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "");
|
IValidator<ExampleCommand> validator2 = new BaseValidator<ExampleCommand>() {
|
||||||
ValidationException e = assertThrows(ValidationException.class, () -> validator.validate(command));
|
{
|
||||||
assertEquals(MESSAGE, e.getMessage());
|
ruleFor(ExampleCommand::getStringProperty, ExampleCommand::getIntProperty)
|
||||||
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()), MESSAGE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ValidationException e2 = assertThrows(ValidationException.class, () -> validator2.validate(command));
|
||||||
|
assertEquals(MESSAGE, e2.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void must_exceptionSupplier_invalidInput() {
|
void must_exceptionSupplier_invalidInput() {
|
||||||
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
|
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "");
|
||||||
|
|
||||||
|
IValidator<ExampleCommand> validator1 = new BaseValidator<ExampleCommand>() {
|
||||||
{
|
{
|
||||||
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
||||||
.must((str, intValue) -> Objects.equals(str, intValue.toString()), () -> ExampleException.withMessage(MESSAGE));
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()), () -> ExampleException.withMessage(MESSAGE));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
ExampleException e1 = assertThrows(ExampleException.class, () -> validator1.validate(command));
|
||||||
|
assertEquals(MESSAGE, e1.getMessage());
|
||||||
|
|
||||||
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "");
|
IValidator<ExampleCommand> validator2 = new BaseValidator<ExampleCommand>() {
|
||||||
|
{
|
||||||
ExampleException e = assertThrows(ExampleException.class, () -> validator.validate(command));
|
ruleFor(ExampleCommand::getStringProperty, ExampleCommand::getIntProperty)
|
||||||
assertEquals(MESSAGE, e.getMessage());
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()), () -> ExampleException.withMessage(MESSAGE));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ExampleException e2 = assertThrows(ExampleException.class, () -> validator2.validate(command));
|
||||||
|
assertEquals(MESSAGE, e2.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void must_exceptionFunction_invalidInput() {
|
void must_exceptionFunction_invalidInput() {
|
||||||
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
|
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "");
|
||||||
|
|
||||||
|
IValidator<ExampleCommand> validator1 = new BaseValidator<ExampleCommand>() {
|
||||||
{
|
{
|
||||||
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
ruleForPair((ExampleCommand command) -> new SimpleImmutableEntry<String,Integer>(command.getStringProperty(), command.getIntProperty()))
|
||||||
.must((str, intValue) -> Objects.equals(str, intValue.toString()),
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()),
|
||||||
(str, intValue) -> ExampleException.withMessage("Validation failed: ('%s', %d).", str, intValue));
|
(str, intValue) -> ExampleException.withMessage("Validation failed: ('%s', %d).", str, intValue));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
ExampleException e1 = assertThrows(ExampleException.class, () -> validator1.validate(command));
|
||||||
|
assertEquals("Validation failed: ('', 100).", e1.getMessage());
|
||||||
|
|
||||||
ExampleCommand command = exampleCommandWithIntAndStringListProperty(100, "");
|
IValidator<ExampleCommand> validator2 = new BaseValidator<ExampleCommand>() {
|
||||||
|
{
|
||||||
ExampleException e = assertThrows(ExampleException.class, () -> validator.validate(command));
|
ruleFor(ExampleCommand::getStringProperty, ExampleCommand::getIntProperty)
|
||||||
assertEquals("Validation failed: ('', 100).", e.getMessage());
|
.must((str, intValue) -> Objects.equals(str, intValue.toString()),
|
||||||
|
(str, intValue) -> ExampleException.withMessage("Validation failed: ('%s', %d).", str, intValue));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ExampleException e2 = assertThrows(ExampleException.class, () -> validator2.validate(command));
|
||||||
|
assertEquals("Validation failed: ('', 100).", e2.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ================================
|
// ================================
|
||||||
|
@@ -19,6 +19,7 @@ package xyz.zhouxy.plusone.map.validator;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -58,7 +59,7 @@ class MapValidatorTests {
|
|||||||
params.put(ParamsValidator.STRING_PROPERTY2, "Foo");
|
params.put(ParamsValidator.STRING_PROPERTY2, "Foo");
|
||||||
assertAll(() -> {
|
assertAll(() -> {
|
||||||
Map<String, Object> validatedParams = validator.validateAndCopy(params);
|
Map<String, Object> validatedParams = validator.validateAndCopy(params);
|
||||||
assertEquals(ParamsValidator.keySet(), validatedParams.keySet());
|
assertEquals(ImmutableSet.copyOf(ParamsValidator.reservedProperties()), validatedParams.keySet());
|
||||||
|
|
||||||
assertEquals(true, validatedParams.get(ParamsValidator.BOOL_PROPERTY));
|
assertEquals(true, validatedParams.get(ParamsValidator.BOOL_PROPERTY));
|
||||||
assertEquals(Integer.MAX_VALUE, validatedParams.get(ParamsValidator.INT_PROPERTY));
|
assertEquals(Integer.MAX_VALUE, validatedParams.get(ParamsValidator.INT_PROPERTY));
|
||||||
@@ -103,11 +104,14 @@ class ParamsValidator extends MapValidator<String, Object> {
|
|||||||
public static final String OBJECT_PROPERTY = "objectProperty";
|
public static final String OBJECT_PROPERTY = "objectProperty";
|
||||||
public static final String STRING_LIST_PROPERTY = "stringListProperty";
|
public static final String STRING_LIST_PROPERTY = "stringListProperty";
|
||||||
|
|
||||||
|
private static final String[] RESERVED_PROPERTIES = {
|
||||||
|
BOOL_PROPERTY, INT_PROPERTY, LONG_PROPERTY, DOUBLE_PROPERTY, STRING_PROPERTY,
|
||||||
|
DATE_TIME_PROPERTY, OBJECT_PROPERTY, STRING_LIST_PROPERTY };
|
||||||
|
|
||||||
public static final ParamsValidator INSTANCE = new ParamsValidator();
|
public static final ParamsValidator INSTANCE = new ParamsValidator();
|
||||||
|
|
||||||
private ParamsValidator() {
|
private ParamsValidator() {
|
||||||
super(new String[] { BOOL_PROPERTY, INT_PROPERTY, LONG_PROPERTY, DOUBLE_PROPERTY, STRING_PROPERTY,
|
super(RESERVED_PROPERTIES);
|
||||||
DATE_TIME_PROPERTY, OBJECT_PROPERTY, STRING_LIST_PROPERTY });
|
|
||||||
ruleForBool(BOOL_PROPERTY)
|
ruleForBool(BOOL_PROPERTY)
|
||||||
.notNull();
|
.notNull();
|
||||||
ruleForInt(INT_PROPERTY)
|
ruleForInt(INT_PROPERTY)
|
||||||
@@ -130,8 +134,7 @@ class ParamsValidator extends MapValidator<String, Object> {
|
|||||||
"'stringProperty' must be equal to 'stringProperty2'.");
|
"'stringProperty' must be equal to 'stringProperty2'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> keySet() {
|
public static String[] reservedProperties() {
|
||||||
return ImmutableSet.of(BOOL_PROPERTY, INT_PROPERTY, LONG_PROPERTY, DOUBLE_PROPERTY, STRING_PROPERTY,
|
return Arrays.copyOf(RESERVED_PROPERTIES, RESERVED_PROPERTIES.length);
|
||||||
DATE_TIME_PROPERTY, OBJECT_PROPERTY, STRING_LIST_PROPERTY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
6
pom.xml
6
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-validator-parent</artifactId>
|
<artifactId>plusone-validator-parent</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-RC2</version>
|
||||||
|
|
||||||
<name>plusone-validator-parent</name>
|
<name>plusone-validator-parent</name>
|
||||||
<url>http://zhouxy.xyz</url>
|
<url>http://zhouxy.xyz</url>
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
Plusone Validator 是一个校验库,用于构建校验规则对对象(尤其是入参)进行校验。API 参考自 .NET 的 FluentValidation。
|
Plusone Validator 是一个校验库,使用 lambda 表达式(包括方法引用)和流式 API 构建校验规则,对对象进行校验。
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>xyz.zhouxy.plusone</groupId>
|
<groupId>xyz.zhouxy.plusone</groupId>
|
||||||
<artifactId>plusone-dependencies</artifactId>
|
<artifactId>plusone-dependencies</artifactId>
|
||||||
<version>1.1.0-SNAPSHOT</version>
|
<version>1.1.0-RC1</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
Reference in New Issue
Block a user