diff --git a/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/StringPropertyValidator.java b/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/StringPropertyValidator.java index 733b1ed..317aadc 100644 --- a/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/StringPropertyValidator.java +++ b/plusone-validator/src/main/java/xyz/zhouxy/plusone/validator/StringPropertyValidator.java @@ -87,7 +87,7 @@ public class StringPropertyValidator // ================================ // ================================ - // #region - matchesOne + // #region - matchesAny // ================================ /** @@ -97,9 +97,9 @@ public class StringPropertyValidator * @param errorMessage 异常信息 * @return 属性校验器 */ - public final StringPropertyValidator matchesOne( + public final StringPropertyValidator 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 * @param exceptionSupplier 自定义异常 * @return 属性校验器 */ - public final StringPropertyValidator matchesOne( + public final StringPropertyValidator matchesAny( final Pattern[] patterns, final Supplier exceptionSupplier) { - return withRule(Conditions.matchesOne(patterns), exceptionSupplier); + return withRule(Conditions.matchesAny(patterns), exceptionSupplier); } /** @@ -123,9 +123,9 @@ public class StringPropertyValidator * @param exceptionFunction 自定义异常 * @return 属性校验器 */ - public final StringPropertyValidator matchesOne( + public final StringPropertyValidator matchesAny( final Pattern[] patterns, final Function exceptionFunction) { - return withRule(Conditions.matchesOne(patterns), exceptionFunction); + return withRule(Conditions.matchesAny(patterns), exceptionFunction); } /** @@ -135,9 +135,9 @@ public class StringPropertyValidator * @param errorMessage 异常信息 * @return 属性校验器 */ - public final StringPropertyValidator matchesOne( + public final StringPropertyValidator matchesAny( final Collection patterns, final String errorMessage) { - return withRule(Conditions.matchesOne(patterns), errorMessage); + return withRule(Conditions.matchesAny(patterns), errorMessage); } /** @@ -148,9 +148,9 @@ public class StringPropertyValidator * @param exceptionSupplier 自定义异常 * @return 属性校验器 */ - public final StringPropertyValidator matchesOne( + public final StringPropertyValidator matchesAny( final Collection patterns, final Supplier exceptionSupplier) { - return withRule(Conditions.matchesOne(patterns), exceptionSupplier); + return withRule(Conditions.matchesAny(patterns), exceptionSupplier); } /** @@ -161,13 +161,13 @@ public class StringPropertyValidator * @param exceptionFunction 自定义异常 * @return 属性校验器 */ - public final StringPropertyValidator matchesOne( + public final StringPropertyValidator matchesAny( final Collection patterns, final Function exceptionFunction) { - return withRule(Conditions.matchesOne(patterns), exceptionFunction); + return withRule(Conditions.matchesAny(patterns), exceptionFunction); } // ================================ - // #endregion - matchesOne + // #endregion - matchesAny // ================================ // ================================ @@ -517,14 +517,14 @@ public class StringPropertyValidator return input -> input == null || RegexTools.matches(input, pattern); } - private static Predicate matchesOne(Pattern[] patterns) { + private static Predicate 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 matchesOne(Collection patterns) { + private static Predicate matchesAny(Collection 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 matchesAll(Pattern[] patterns) { diff --git a/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/StringPropertyValidatorTests.java b/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/StringPropertyValidatorTests.java index 9b349c5..ee87e08 100644 --- a/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/StringPropertyValidatorTests.java +++ b/plusone-validator/src/test/java/xyz/zhouxy/plusone/example/validator/StringPropertyValidatorTests.java @@ -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 validator = new BaseValidator() { { 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 validator = new BaseValidator() { { 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 validator = new BaseValidator() { { 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 validator = new BaseValidator() { { 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 validator = new BaseValidator() { { 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 validator = new BaseValidator() { { 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 validator = new BaseValidator() { { 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 patterns = Lists.newArrayList( Pattern.compile("\\w{1,3}"), Pattern.compile("\\w{4,6}")); IValidator validator = new BaseValidator() { { 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 patterns = Lists.newArrayList( Pattern.compile("\\w{1,3}"), Pattern.compile("\\w{4,6}")); IValidator validator = new BaseValidator() { { 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 patterns = Lists.newArrayList( Pattern.compile("\\w{1,3}"), Pattern.compile("\\w{4,6}")); IValidator validator = new BaseValidator() { { 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 patterns = Lists.newArrayList( Pattern.compile("\\w{1,3}"), Pattern.compile("\\w{4,6}")); IValidator validator = new BaseValidator() { { 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 patterns = Lists.newArrayList( Pattern.compile("\\w{1,3}"), Pattern.compile("\\w{4,6}")); IValidator validator = new BaseValidator() { { 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 patterns = Lists.newArrayList( Pattern.compile("\\w{1,3}"), Pattern.compile("\\w{4,6}")); IValidator validator = new BaseValidator() { { 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 patterns = Lists.newArrayList( Pattern.compile("\\w{1,3}"), Pattern.compile("\\w{4,6}")); IValidator validator = new BaseValidator() { { 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 // ================================ // ================================