refactor!: 将 matchesOne 方法重命名为 matchesAny

修改了 StringPropertyValidator 类中的 matchesOne 方法,将其重命名为 matchesAny。
This commit is contained in:
zhouxy108 2025-06-04 17:15:22 +08:00
parent e79d8e9ec8
commit 62f7a9b03b
2 changed files with 52 additions and 52 deletions

View File

@ -87,7 +87,7 @@ public class StringPropertyValidator<T>
// ================================
// ================================
// #region - matchesOne
// #region - matchesAny
// ================================
/**
@ -97,9 +97,9 @@ public class StringPropertyValidator<T>
* @param errorMessage 异常信息
* @return 属性校验器
*/
public final StringPropertyValidator<T> matchesOne(
public final StringPropertyValidator<T> matchesAny(
final Pattern[] patterns, final String errorMessage) {
return withRule(Conditions.matchesOne(patterns), errorMessage);
return withRule(Conditions.matchesAny(patterns), errorMessage);
}
/**
@ -110,9 +110,9 @@ public class StringPropertyValidator<T>
* @param exceptionSupplier 自定义异常
* @return 属性校验器
*/
public final <X extends RuntimeException> StringPropertyValidator<T> matchesOne(
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
final Pattern[] patterns, final Supplier<X> exceptionSupplier) {
return withRule(Conditions.matchesOne(patterns), exceptionSupplier);
return withRule(Conditions.matchesAny(patterns), exceptionSupplier);
}
/**
@ -123,9 +123,9 @@ public class StringPropertyValidator<T>
* @param exceptionFunction 自定义异常
* @return 属性校验器
*/
public final <X extends RuntimeException> StringPropertyValidator<T> matchesOne(
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
final Pattern[] patterns, final Function<String, X> exceptionFunction) {
return withRule(Conditions.matchesOne(patterns), exceptionFunction);
return withRule(Conditions.matchesAny(patterns), exceptionFunction);
}
/**
@ -135,9 +135,9 @@ public class StringPropertyValidator<T>
* @param errorMessage 异常信息
* @return 属性校验器
*/
public final StringPropertyValidator<T> matchesOne(
public final StringPropertyValidator<T> matchesAny(
final Collection<Pattern> patterns, final String errorMessage) {
return withRule(Conditions.matchesOne(patterns), errorMessage);
return withRule(Conditions.matchesAny(patterns), errorMessage);
}
/**
@ -148,9 +148,9 @@ public class StringPropertyValidator<T>
* @param exceptionSupplier 自定义异常
* @return 属性校验器
*/
public final <X extends RuntimeException> StringPropertyValidator<T> matchesOne(
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
final Collection<Pattern> patterns, final Supplier<X> exceptionSupplier) {
return withRule(Conditions.matchesOne(patterns), exceptionSupplier);
return withRule(Conditions.matchesAny(patterns), exceptionSupplier);
}
/**
@ -161,13 +161,13 @@ public class StringPropertyValidator<T>
* @param exceptionFunction 自定义异常
* @return 属性校验器
*/
public final <X extends RuntimeException> StringPropertyValidator<T> matchesOne(
public final <X extends RuntimeException> StringPropertyValidator<T> matchesAny(
final Collection<Pattern> patterns, final Function<String, X> exceptionFunction) {
return withRule(Conditions.matchesOne(patterns), exceptionFunction);
return withRule(Conditions.matchesAny(patterns), exceptionFunction);
}
// ================================
// #endregion - matchesOne
// #endregion - matchesAny
// ================================
// ================================
@ -517,14 +517,14 @@ public class StringPropertyValidator<T>
return input -> input == null || RegexTools.matches(input, pattern);
}
private static Predicate<String> matchesOne(Pattern[] patterns) {
private static Predicate<String> matchesAny(Pattern[] patterns) {
AssertTools.checkArgument(ArrayTools.isAllElementsNotNull(patterns));
return input -> input == null || RegexTools.matchesOne(input, patterns);
return input -> input == null || RegexTools.matchesAny(input, patterns);
}
private static Predicate<String> matchesOne(Collection<Pattern> patterns) {
private static Predicate<String> matchesAny(Collection<Pattern> patterns) {
AssertTools.checkArgumentNotNull(patterns, "patterns must not be null.");
return input -> input == null || RegexTools.matchesOne(input, patterns.toArray(new Pattern[0]));
return input -> input == null || RegexTools.matchesAny(input, patterns.toArray(new Pattern[0]));
}
private static Predicate<String> matchesAll(Pattern[] patterns) {

View File

@ -158,11 +158,11 @@ public class StringPropertyValidatorTests {
// ================================
// ================================
// #region - matchesOne
// #region - matchesAny
// ================================
@Test
void matchesOne_patternArray_InputMatchesPattern() {
void matchesAny_patternArray_InputMatchesPattern() {
final Pattern[] patterns = {
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}")
@ -170,9 +170,9 @@ public class StringPropertyValidatorTests {
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, MESSAGE_SHOULD_MATCH)
.matchesOne(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH))
.matchesOne(patterns, str -> ExampleException.withMessage(
.matchesAny(patterns, MESSAGE_SHOULD_MATCH)
.matchesAny(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH))
.matchesAny(patterns, str -> ExampleException.withMessage(
"Input should match pattern, but it is %s", StringTools.toQuotedString(str)));
}
};
@ -182,7 +182,7 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternArray_message_InputDoesNotMatchPattern() {
void matchesAny_patternArray_message_InputDoesNotMatchPattern() {
final Pattern[] patterns = {
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}")
@ -190,7 +190,7 @@ public class StringPropertyValidatorTests {
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, MESSAGE_SHOULD_MATCH);
.matchesAny(patterns, MESSAGE_SHOULD_MATCH);
}
};
@ -202,7 +202,7 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternArray_exceptionSupplier_InputDoesNotMatchPattern() {
void matchesAny_patternArray_exceptionSupplier_InputDoesNotMatchPattern() {
final Pattern[] patterns = {
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}")
@ -210,7 +210,7 @@ public class StringPropertyValidatorTests {
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH));
.matchesAny(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH));
}
};
@ -222,7 +222,7 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternArray_exceptionFunction_InputDoesNotMatchPattern() {
void matchesAny_patternArray_exceptionFunction_InputDoesNotMatchPattern() {
final Pattern[] patterns = {
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}")
@ -230,7 +230,7 @@ public class StringPropertyValidatorTests {
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, str -> ExampleException.withMessage(
.matchesAny(patterns, str -> ExampleException.withMessage(
"Input should match pattern, but it is %s", StringTools.toQuotedString(str)));
}
};
@ -243,7 +243,7 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternArray_message_InputIsNull() {
void matchesAny_patternArray_message_InputIsNull() {
final Pattern[] patterns = {
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}")
@ -251,7 +251,7 @@ public class StringPropertyValidatorTests {
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, MESSAGE_SHOULD_MATCH);
.matchesAny(patterns, MESSAGE_SHOULD_MATCH);
}
};
@ -260,7 +260,7 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternArray_exceptionSupplier_InputIsNull() {
void matchesAny_patternArray_exceptionSupplier_InputIsNull() {
final Pattern[] patterns = {
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}")
@ -268,7 +268,7 @@ public class StringPropertyValidatorTests {
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH));
.matchesAny(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH));
}
};
@ -277,7 +277,7 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternArray_exceptionFunction_InputIsNull() {
void matchesAny_patternArray_exceptionFunction_InputIsNull() {
final Pattern[] patterns = {
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}")
@ -285,7 +285,7 @@ public class StringPropertyValidatorTests {
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, str -> ExampleException.withMessage(
.matchesAny(patterns, str -> ExampleException.withMessage(
"Input should match pattern, but it is %s", StringTools.toQuotedString(str)));
}
};
@ -295,16 +295,16 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternList_InputMatchesPattern() {
void matchesAny_patternList_InputMatchesPattern() {
final List<Pattern> patterns = Lists.newArrayList(
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}"));
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, MESSAGE_SHOULD_MATCH)
.matchesOne(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH))
.matchesOne(patterns, str -> ExampleException.withMessage(
.matchesAny(patterns, MESSAGE_SHOULD_MATCH)
.matchesAny(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH))
.matchesAny(patterns, str -> ExampleException.withMessage(
"Input should match pattern, but it is %s", StringTools.toQuotedString(str)));
}
};
@ -314,14 +314,14 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternList_message_InputDoesNotMatchPattern() {
void matchesAny_patternList_message_InputDoesNotMatchPattern() {
final List<Pattern> patterns = Lists.newArrayList(
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}"));
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, MESSAGE_SHOULD_MATCH);
.matchesAny(patterns, MESSAGE_SHOULD_MATCH);
}
};
@ -333,14 +333,14 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternList_exceptionSupplier_InputDoesNotMatchPattern() {
void matchesAny_patternList_exceptionSupplier_InputDoesNotMatchPattern() {
final List<Pattern> patterns = Lists.newArrayList(
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}"));
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH));
.matchesAny(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH));
}
};
@ -352,14 +352,14 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternList_exceptionFunction_InputDoesNotMatchPattern() {
void matchesAny_patternList_exceptionFunction_InputDoesNotMatchPattern() {
final List<Pattern> patterns = Lists.newArrayList(
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}"));
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, str -> ExampleException.withMessage(
.matchesAny(patterns, str -> ExampleException.withMessage(
"Input should match pattern, but it is %s", StringTools.toQuotedString(str)));
}
};
@ -372,14 +372,14 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternList_message_InputIsNull() {
void matchesAny_patternList_message_InputIsNull() {
final List<Pattern> patterns = Lists.newArrayList(
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}"));
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, MESSAGE_SHOULD_MATCH);
.matchesAny(patterns, MESSAGE_SHOULD_MATCH);
}
};
@ -388,14 +388,14 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternList_exceptionSupplier_InputIsNull() {
void matchesAny_patternList_exceptionSupplier_InputIsNull() {
final List<Pattern> patterns = Lists.newArrayList(
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}"));
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH));
.matchesAny(patterns, () -> ExampleException.withMessage(MESSAGE_SHOULD_MATCH));
}
};
@ -404,14 +404,14 @@ public class StringPropertyValidatorTests {
}
@Test
void matchesOne_patternList_exceptionFunction_InputIsNull() {
void matchesAny_patternList_exceptionFunction_InputIsNull() {
final List<Pattern> patterns = Lists.newArrayList(
Pattern.compile("\\w{1,3}"),
Pattern.compile("\\w{4,6}"));
IValidator<ExampleCommand> validator = new BaseValidator<ExampleCommand>() {
{
ruleForString(ExampleCommand::getStringProperty)
.matchesOne(patterns, str -> ExampleException.withMessage(
.matchesAny(patterns, str -> ExampleException.withMessage(
"Input should match pattern, but it is %s", StringTools.toQuotedString(str)));
}
};
@ -421,7 +421,7 @@ public class StringPropertyValidatorTests {
}
// ================================
// #endregion - matchesOne
// #endregion - matchesAny
// ================================
// ================================