添加重载 state 方法。
parent
40f30f88a1
commit
c6e9994b68
|
@ -1,5 +1,6 @@
|
|||
package xyz.zhouxy.plusone.validator;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
@ -109,6 +110,31 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
|
|||
return thisObject();
|
||||
}
|
||||
|
||||
// ===== state =====
|
||||
|
||||
public THIS state(Collection<Predicate<PROPERTY>> conditions) {
|
||||
return state(conditions, "无效的用户输入");
|
||||
}
|
||||
|
||||
public THIS state(Collection<Predicate<PROPERTY>> conditions, String errMsg) {
|
||||
return state(conditions, convertExceptionCreator(errMsg));
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> THIS state(
|
||||
Collection<Predicate<PROPERTY>> conditions,
|
||||
Supplier<E> exceptionCreator) {
|
||||
return state(conditions, convertExceptionCreator(exceptionCreator));
|
||||
}
|
||||
|
||||
public <E extends RuntimeException> THIS state(
|
||||
Collection<Predicate<PROPERTY>> conditions,
|
||||
Function<PROPERTY, E> exceptionCreator) {
|
||||
for (Predicate<PROPERTY> condition : conditions) {
|
||||
withRule(condition, exceptionCreator);
|
||||
}
|
||||
return thisObject();
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
|
||||
void validate(DTO obj) {
|
||||
|
|
Loading…
Reference in New Issue