refactor!: BasePropertyValidator#isTrue 重命名为 must

This commit is contained in:
zhouxy108 2025-05-19 17:11:13 +08:00
parent dc28befe88
commit ecdd0a616a
2 changed files with 17 additions and 17 deletions

View File

@ -129,46 +129,46 @@ public abstract class BasePropertyValidator< //
return thisObject(); return thisObject();
} }
// ===== isTrue ===== // ===== must =====
public TPropertyValidator isTrue(Predicate<? super TProperty> condition) { public TPropertyValidator must(Predicate<? super TProperty> condition) {
return isTrue(condition, "无效的用户输入"); return must(condition, "无效的用户输入");
} }
public TPropertyValidator isTrue(Predicate<? super TProperty> condition, String errMsg) { public TPropertyValidator must(Predicate<? super TProperty> condition, String errMsg) {
return isTrue(condition, convertExceptionCreator(errMsg)); return must(condition, convertExceptionCreator(errMsg));
} }
public <E extends RuntimeException> TPropertyValidator isTrue( public <E extends RuntimeException> TPropertyValidator must(
Predicate<? super TProperty> condition, Predicate<? super TProperty> condition,
Supplier<E> exceptionCreator) { Supplier<E> exceptionCreator) {
return isTrue(condition, convertExceptionCreator(exceptionCreator)); return must(condition, convertExceptionCreator(exceptionCreator));
} }
public <E extends RuntimeException> TPropertyValidator isTrue( public <E extends RuntimeException> TPropertyValidator must(
Predicate<? super TProperty> condition, Predicate<? super TProperty> condition,
Function<TProperty, E> exceptionCreator) { Function<TProperty, E> exceptionCreator) {
withRule(condition, exceptionCreator); withRule(condition, exceptionCreator);
return thisObject(); return thisObject();
} }
// ===== isTrue ===== // ===== must =====
public TPropertyValidator isTrue(Collection<Predicate<? super TProperty>> conditions) { public TPropertyValidator must(Collection<Predicate<? super TProperty>> conditions) {
return isTrue(conditions, "无效的用户输入"); return must(conditions, "无效的用户输入");
} }
public TPropertyValidator isTrue(Collection<Predicate<? super TProperty>> conditions, String errMsg) { public TPropertyValidator must(Collection<Predicate<? super TProperty>> conditions, String errMsg) {
return isTrue(conditions, convertExceptionCreator(errMsg)); return must(conditions, convertExceptionCreator(errMsg));
} }
public <E extends RuntimeException> TPropertyValidator isTrue( public <E extends RuntimeException> TPropertyValidator must(
Collection<Predicate<? super TProperty>> conditions, Collection<Predicate<? super TProperty>> conditions,
Supplier<E> exceptionCreator) { Supplier<E> exceptionCreator) {
return isTrue(conditions, convertExceptionCreator(exceptionCreator)); return must(conditions, convertExceptionCreator(exceptionCreator));
} }
public <E extends RuntimeException> TPropertyValidator isTrue( public <E extends RuntimeException> TPropertyValidator must(
Collection<Predicate<? super TProperty>> conditions, Collection<Predicate<? super TProperty>> conditions,
Function<TProperty, E> exceptionCreator) { Function<TProperty, E> exceptionCreator) {
for (Predicate<? super TProperty> condition : conditions) { for (Predicate<? super TProperty> condition : conditions) {

View File

@ -37,7 +37,7 @@ class BaseValidatorTest {
int thisYear = Year.now().getValue(); int thisYear = Year.now().getValue();
ruleForString(RegisterCommand::getUsername) ruleForString(RegisterCommand::getUsername)
.isTrue(PredicateTools.<String>from(Objects::nonNull) .must(PredicateTools.<String>from(Objects::nonNull)
.and(StringTools::isNotEmpty) .and(StringTools::isNotEmpty)
.and(StringTools::isNotBlank) .and(StringTools::isNotBlank)
.and(username -> RegexTools.matches(username, PatternConsts.USERNAME)), .and(username -> RegexTools.matches(username, PatternConsts.USERNAME)),