This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git


The following commit(s) were added to refs/heads/master by this push:
     new acee2ce  Create the best kind of matcher.
acee2ce is described below

commit acee2ce78b9126afd47dca23ef5fe9e0364c7815
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Jul 14 11:06:47 2020 -0400

    Create the best kind of matcher.
---
 .../commons/text/matcher/StringMatcherFactory.java    | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/text/matcher/StringMatcherFactory.java 
b/src/main/java/org/apache/commons/text/matcher/StringMatcherFactory.java
index b539a0b..c08b795 100644
--- a/src/main/java/org/apache/commons/text/matcher/StringMatcherFactory.java
+++ b/src/main/java/org/apache/commons/text/matcher/StringMatcherFactory.java
@@ -96,6 +96,13 @@ public final class StringMatcherFactory {
      * @since 1.9
      */
     public StringMatcher andMatcher(final StringMatcher... stringMatchers) {
+        final int len = ArrayUtils.getLength(stringMatchers);
+        if (len == 0) {
+            return NONE_MATCHER;
+        }
+        if (len == 1) {
+            return stringMatchers[0];
+        }
         return new AbstractStringMatcher.AndStringMatcher(stringMatchers);
     }
 
@@ -116,10 +123,11 @@ public final class StringMatcherFactory {
      * @return a new matcher for the given char[]
      */
     public StringMatcher charSetMatcher(final char... chars) {
-        if (ArrayUtils.isEmpty(chars)) {
+        final int len = ArrayUtils.getLength(chars);
+        if (len == 0) {
             return NONE_MATCHER;
         }
-        if (chars.length == 1) {
+        if (len == 1) {
             return new AbstractStringMatcher.CharMatcher(chars[0]);
         }
         return new AbstractStringMatcher.CharSetMatcher(chars);
@@ -132,10 +140,11 @@ public final class StringMatcherFactory {
      * @return a new Matcher for the given characters
      */
     public StringMatcher charSetMatcher(final String chars) {
-        if (StringUtils.isEmpty(chars)) {
+        final int len = StringUtils.length(chars);
+        if (len == 0) {
             return NONE_MATCHER;
         }
-        if (chars.length() == 1) {
+        if (len == 1) {
             return new AbstractStringMatcher.CharMatcher(chars.charAt(0));
         }
         return new AbstractStringMatcher.CharSetMatcher(chars.toCharArray());
@@ -225,7 +234,7 @@ public final class StringMatcherFactory {
      * @return a new Matcher for the given String
      */
     public StringMatcher stringMatcher(final String str) {
-        return str == null ? NONE_MATCHER : stringMatcher(str.toCharArray());
+        return StringUtils.isEmpty(str) ? NONE_MATCHER : 
stringMatcher(str.toCharArray());
     }
 
     /**

Reply via email to