diff --git a/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java b/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java index 3ff1d79..2adf9b9 100644 --- a/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java +++ b/src/main/java/xyz/zhouxy/plusone/validator/PropertyValidator.java @@ -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 { return thisObject(); } + // ===== state ===== + + public THIS state(Collection> conditions) { + return state(conditions, "无效的用户输入"); + } + + public THIS state(Collection> conditions, String errMsg) { + return state(conditions, convertExceptionCreator(errMsg)); + } + + public THIS state( + Collection> conditions, + Supplier exceptionCreator) { + return state(conditions, convertExceptionCreator(exceptionCreator)); + } + + public THIS state( + Collection> conditions, + Function exceptionCreator) { + for (Predicate condition : conditions) { + withRule(condition, exceptionCreator); + } + return thisObject(); + } + // ======================================================================== void validate(DTO obj) {