pull/1/head
ZhouXY108 2023-02-24 11:49:13 +08:00
parent db2678803b
commit 55089dbb25
1 changed files with 21 additions and 3 deletions

View File

@ -1,5 +1,6 @@
package xyz.zhouxy.plusone.validator;
import java.util.Collection;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
@ -58,18 +59,18 @@ public class StringValidator<DTO> extends PropertyValidator<DTO, String, StringV
return this;
}
public StringValidator<DTO> matchesOr(List<String> regexs, String errMsg) {
public StringValidator<DTO> matchesOr(List<Pattern> regexs, String errMsg) {
return matchesOr(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOr(
List<String> regexs,
List<Pattern> regexs,
Supplier<E> exceptionCreator) {
return matchesOr(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOr(
List<String> regexs,
List<Pattern> regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexUtil.matchesOr(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
return this;
@ -94,6 +95,23 @@ public class StringValidator<DTO> extends PropertyValidator<DTO, String, StringV
return this;
}
public StringValidator<DTO> matchesAnd(Collection<Pattern> regexs, String errMsg) {
return matchesAnd(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAnd(
Collection<Pattern> regexs,
Supplier<E> exceptionCreator) {
return matchesAnd(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAnd(
Collection<Pattern> regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexUtil.matchesAnd(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
return this;
}
// ===== notBlank =====
public StringValidator<DTO> notBlank() {