优化代码,修改方法名。

This commit is contained in:
2023-07-19 02:38:52 +08:00
parent 0e2b1ffd48
commit 7ae8a5b6d3
4 changed files with 55 additions and 57 deletions

View File

@@ -87,46 +87,46 @@ abstract class PropertyValidator<DTO, PROPERTY, THIS> {
return thisObject();
}
// ===== state =====
// ===== isTrue =====
public THIS state(Predicate<PROPERTY> condition) {
return state(condition, "无效的用户输入");
public THIS isTrue(Predicate<PROPERTY> condition) {
return isTrue(condition, "无效的用户输入");
}
public THIS state(Predicate<PROPERTY> condition, String errMsg) {
return state(condition, convertExceptionCreator(errMsg));
public THIS isTrue(Predicate<PROPERTY> condition, String errMsg) {
return isTrue(condition, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> THIS state(
public <E extends RuntimeException> THIS isTrue(
Predicate<PROPERTY> condition,
Supplier<E> exceptionCreator) {
return state(condition, convertExceptionCreator(exceptionCreator));
return isTrue(condition, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> THIS state(
public <E extends RuntimeException> THIS isTrue(
Predicate<PROPERTY> condition,
Function<PROPERTY, E> exceptionCreator) {
withRule(condition, exceptionCreator);
return thisObject();
}
// ===== state =====
// ===== isTrue =====
public THIS state(Collection<Predicate<PROPERTY>> conditions) {
return state(conditions, "无效的用户输入");
public THIS isTrue(Collection<Predicate<PROPERTY>> conditions) {
return isTrue(conditions, "无效的用户输入");
}
public THIS state(Collection<Predicate<PROPERTY>> conditions, String errMsg) {
return state(conditions, convertExceptionCreator(errMsg));
public THIS isTrue(Collection<Predicate<PROPERTY>> conditions, String errMsg) {
return isTrue(conditions, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> THIS state(
public <E extends RuntimeException> THIS isTrue(
Collection<Predicate<PROPERTY>> conditions,
Supplier<E> exceptionCreator) {
return state(conditions, convertExceptionCreator(exceptionCreator));
return isTrue(conditions, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> THIS state(
public <E extends RuntimeException> THIS isTrue(
Collection<Predicate<PROPERTY>> conditions,
Function<PROPERTY, E> exceptionCreator) {
for (Predicate<PROPERTY> condition : conditions) {

View File

@@ -40,75 +40,75 @@ public class StringValidator<DTO> extends PropertyValidator<DTO, String, StringV
return this;
}
// ===== matchesOr =====
// ===== matchesOne =====
public StringValidator<DTO> matchesOr(Pattern[] regexs, String errMsg) {
return matchesOr(regexs, convertExceptionCreator(errMsg));
public StringValidator<DTO> matchesOne(Pattern[] regexs, String errMsg) {
return matchesOne(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOr(
public <E extends RuntimeException> StringValidator<DTO> matchesOne(
Pattern[] regexs,
Supplier<E> exceptionCreator) {
return matchesOr(regexs, convertExceptionCreator(exceptionCreator));
return matchesOne(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOr(
public <E extends RuntimeException> StringValidator<DTO> matchesOne(
Pattern[] regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexUtil.matchesOr(input, regexs), exceptionCreator);
withRule(input -> RegexUtil.matchesOne(input, regexs), exceptionCreator);
return this;
}
public StringValidator<DTO> matchesOr(List<Pattern> regexs, String errMsg) {
return matchesOr(regexs, convertExceptionCreator(errMsg));
public StringValidator<DTO> matchesOne(List<Pattern> regexs, String errMsg) {
return matchesOne(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOr(
public <E extends RuntimeException> StringValidator<DTO> matchesOne(
List<Pattern> regexs,
Supplier<E> exceptionCreator) {
return matchesOr(regexs, convertExceptionCreator(exceptionCreator));
return matchesOne(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesOr(
public <E extends RuntimeException> StringValidator<DTO> matchesOne(
List<Pattern> regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexUtil.matchesOr(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
withRule(input -> RegexUtil.matchesOne(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
return this;
}
// ===== matchesAnd =====
// ===== matchesAll =====
public StringValidator<DTO> matchesAnd(Pattern[] regexs, String errMsg) {
return matchesAnd(regexs, convertExceptionCreator(errMsg));
public StringValidator<DTO> matchesAll(Pattern[] regexs, String errMsg) {
return matchesAll(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAnd(
public <E extends RuntimeException> StringValidator<DTO> matchesAll(
Pattern[] regexs,
Supplier<E> exceptionCreator) {
return matchesAnd(regexs, convertExceptionCreator(exceptionCreator));
return matchesAll(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAnd(
public <E extends RuntimeException> StringValidator<DTO> matchesAll(
Pattern[] regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexUtil.matchesAnd(input, regexs), exceptionCreator);
withRule(input -> RegexUtil.matchesAll(input, regexs), exceptionCreator);
return this;
}
public StringValidator<DTO> matchesAnd(Collection<Pattern> regexs, String errMsg) {
return matchesAnd(regexs, convertExceptionCreator(errMsg));
public StringValidator<DTO> matchesAll(Collection<Pattern> regexs, String errMsg) {
return matchesAll(regexs, convertExceptionCreator(errMsg));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAnd(
public <E extends RuntimeException> StringValidator<DTO> matchesAll(
Collection<Pattern> regexs,
Supplier<E> exceptionCreator) {
return matchesAnd(regexs, convertExceptionCreator(exceptionCreator));
return matchesAll(regexs, convertExceptionCreator(exceptionCreator));
}
public <E extends RuntimeException> StringValidator<DTO> matchesAnd(
public <E extends RuntimeException> StringValidator<DTO> matchesAll(
Collection<Pattern> regexs,
Function<String, E> exceptionCreator) {
withRule(input -> RegexUtil.matchesAnd(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
withRule(input -> RegexUtil.matchesAll(input, regexs.toArray(new Pattern[regexs.size()])), exceptionCreator);
return this;
}