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 9447958  Reuse ArrayUtils.isEmpty(chars).
9447958 is described below

commit 9447958cf9f3a607c1d915bb038f99bd4b800d11
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Jun 30 16:38:32 2020 -0400

    Reuse ArrayUtils.isEmpty(chars).
---
 src/main/java/org/apache/commons/text/AlphabetConverter.java       | 7 +++++--
 src/main/java/org/apache/commons/text/CaseUtils.java               | 3 ++-
 src/main/java/org/apache/commons/text/RandomStringGenerator.java   | 3 ++-
 src/main/java/org/apache/commons/text/StrMatcher.java              | 3 ++-
 .../java/org/apache/commons/text/matcher/StringMatcherFactory.java | 6 ++++--
 5 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/AlphabetConverter.java 
b/src/main/java/org/apache/commons/text/AlphabetConverter.java
index 6dd1927..78e4f06 100644
--- a/src/main/java/org/apache/commons/text/AlphabetConverter.java
+++ b/src/main/java/org/apache/commons/text/AlphabetConverter.java
@@ -26,6 +26,9 @@ import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Map.Entry;
+
+import org.apache.commons.lang3.ArrayUtils;
+
 import java.util.Objects;
 import java.util.Set;
 
@@ -375,8 +378,8 @@ public final class AlphabetConverter {
      * @return an equivalent array of integers
      */
     private static Integer[] convertCharsToIntegers(final Character[] chars) {
-        if (chars == null || chars.length == 0) {
-            return new Integer[0];
+        if (ArrayUtils.isEmpty(chars)) {
+            return ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY;
         }
         final Integer[] integers = new Integer[chars.length];
         for (int i = 0; i < chars.length; i++) {
diff --git a/src/main/java/org/apache/commons/text/CaseUtils.java 
b/src/main/java/org/apache/commons/text/CaseUtils.java
index b6719fe..ba360b3 100644
--- a/src/main/java/org/apache/commons/text/CaseUtils.java
+++ b/src/main/java/org/apache/commons/text/CaseUtils.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.text;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import java.util.HashSet;
@@ -121,7 +122,7 @@ public class CaseUtils {
     private static Set<Integer> generateDelimiterSet(final char[] delimiters) {
         final Set<Integer> delimiterHashSet = new HashSet<>();
         delimiterHashSet.add(Character.codePointAt(new char[]{' '}, 0));
-        if (delimiters == null || delimiters.length == 0) {
+        if (ArrayUtils.isEmpty(delimiters)) {
             return delimiterHashSet;
         }
 
diff --git a/src/main/java/org/apache/commons/text/RandomStringGenerator.java 
b/src/main/java/org/apache/commons/text/RandomStringGenerator.java
index 93db59f..f1a9b4f 100644
--- a/src/main/java/org/apache/commons/text/RandomStringGenerator.java
+++ b/src/main/java/org/apache/commons/text/RandomStringGenerator.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.text;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.Validate;
 
 import java.util.ArrayList;
@@ -376,7 +377,7 @@ public final class RandomStringGenerator {
          * @return {@code this}, to allow method chaining
          */
         public Builder filteredBy(final CharacterPredicate... predicates) {
-            if (predicates == null || predicates.length == 0) {
+            if (ArrayUtils.isEmpty(predicates)) {
                 inclusivePredicates = null;
                 return this;
             }
diff --git a/src/main/java/org/apache/commons/text/StrMatcher.java 
b/src/main/java/org/apache/commons/text/StrMatcher.java
index 1ad0110..e506c95 100644
--- a/src/main/java/org/apache/commons/text/StrMatcher.java
+++ b/src/main/java/org/apache/commons/text/StrMatcher.java
@@ -18,6 +18,7 @@ package org.apache.commons.text;
 
 import java.util.Arrays;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.text.matcher.StringMatcherFactory;
 
 /**
@@ -180,7 +181,7 @@ public abstract class StrMatcher {
      * @return a new matcher for the given char[]
      */
     public static StrMatcher charSetMatcher(final char... chars) {
-        if (chars == null || chars.length == 0) {
+        if (ArrayUtils.isEmpty(chars)) {
             return NONE_MATCHER;
         }
         if (chars.length == 1) {
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 d1011ae..30e4c77 100644
--- a/src/main/java/org/apache/commons/text/matcher/StringMatcherFactory.java
+++ b/src/main/java/org/apache/commons/text/matcher/StringMatcherFactory.java
@@ -17,6 +17,8 @@
 
 package org.apache.commons.text.matcher;
 
+import org.apache.commons.lang3.ArrayUtils;
+
 /**
  * Provides access to matchers defined in this package.
  *
@@ -104,7 +106,7 @@ public final class StringMatcherFactory {
      * @return a new matcher for the given char[]
      */
     public StringMatcher charSetMatcher(final char... chars) {
-        if (chars == null || chars.length == 0) {
+        if (ArrayUtils.isEmpty(chars)) {
             return NONE_MATCHER;
         }
         if (chars.length == 1) {
@@ -202,7 +204,7 @@ public final class StringMatcherFactory {
      * @since 1.9
      */
     public StringMatcher stringMatcher(final char... chars) {
-        if (chars == null || chars.length == 0) {
+        if (ArrayUtils.isEmpty(chars)) {
             return NONE_MATCHER;
         }
         return new AbstractStringMatcher.StringMatcher(chars);

Reply via email to