You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/01/17 13:40:17 UTC

[commons-text] branch master updated: Minor Improvements (#196)

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 29b60f5  Minor Improvements (#196)
29b60f5 is described below

commit 29b60f5788d8a7bc51ed195634063cf7e02c9ff0
Author: Arturo Bernal <ar...@gmail.com>
AuthorDate: Sun Jan 17 14:40:07 2021 +0100

    Minor Improvements (#196)
    
    * Minor Improvement:
    * Remove redundant initializer
    *  Use Empty array
    
    * Re-Use ArrayUtils.EMPTY_STRING_ARRAY instead Use Empty array
---
 src/main/java/org/apache/commons/text/StrSubstitutor.java          | 2 +-
 src/main/java/org/apache/commons/text/StrTokenizer.java            | 7 ++++---
 src/main/java/org/apache/commons/text/StringTokenizer.java         | 7 ++++---
 .../java/org/apache/commons/text/diff/ReplacementsFinderTest.java  | 2 +-
 4 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/main/java/org/apache/commons/text/StrSubstitutor.java b/src/main/java/org/apache/commons/text/StrSubstitutor.java
index 362c023..021d2e1 100644
--- a/src/main/java/org/apache/commons/text/StrSubstitutor.java
+++ b/src/main/java/org/apache/commons/text/StrSubstitutor.java
@@ -179,7 +179,7 @@ public class StrSubstitutor {
     /**
      * Whether escapes should be preserved.  Default is false;
      */
-    private boolean preserveEscapes = false;
+    private boolean preserveEscapes;
 
     /**
      * The flag whether substitution in variable values is disabled.
diff --git a/src/main/java/org/apache/commons/text/StrTokenizer.java b/src/main/java/org/apache/commons/text/StrTokenizer.java
index 318aac5..27147f3 100644
--- a/src/main/java/org/apache/commons/text/StrTokenizer.java
+++ b/src/main/java/org/apache/commons/text/StrTokenizer.java
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.ListIterator;
 import java.util.NoSuchElementException;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 
 /**
@@ -124,7 +125,7 @@ public class StrTokenizer implements ListIterator<String>, Cloneable {
     private StrMatcher trimmerMatcher = StrMatcher.noneMatcher();
 
     /** Whether to return empty tokens as null. */
-    private boolean emptyAsNull = false;
+    private boolean emptyAsNull;
     /** Whether to ignore empty tokens. */
     private boolean ignoreEmptyTokens = true;
 
@@ -608,10 +609,10 @@ public class StrTokenizer implements ListIterator<String>, Cloneable {
             if (chars == null) {
                 // still call tokenize as subclass may do some work
                 final List<String> split = tokenize(null, 0, 0);
-                tokens = split.toArray(new String[split.size()]);
+                tokens = split.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
             } else {
                 final List<String> split = tokenize(chars, 0, chars.length);
-                tokens = split.toArray(new String[split.size()]);
+                tokens = split.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
             }
         }
     }
diff --git a/src/main/java/org/apache/commons/text/StringTokenizer.java b/src/main/java/org/apache/commons/text/StringTokenizer.java
index 4c68606..e8520e2 100644
--- a/src/main/java/org/apache/commons/text/StringTokenizer.java
+++ b/src/main/java/org/apache/commons/text/StringTokenizer.java
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.ListIterator;
 import java.util.NoSuchElementException;
 
+import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.matcher.StringMatcher;
 import org.apache.commons.text.matcher.StringMatcherFactory;
@@ -130,7 +131,7 @@ public class StringTokenizer implements ListIterator<String>, Cloneable {
     private StringMatcher trimmerMatcher = StringMatcherFactory.INSTANCE.noneMatcher();
 
     /** Whether to return empty tokens as null. */
-    private boolean emptyAsNull = false;
+    private boolean emptyAsNull;
     /** Whether to ignore empty tokens. */
     private boolean ignoreEmptyTokens = true;
 
@@ -646,10 +647,10 @@ public class StringTokenizer implements ListIterator<String>, Cloneable {
             if (chars == null) {
                 // still call tokenize as subclass may do some work
                 final List<String> split = tokenize(null, 0, 0);
-                tokens = split.toArray(new String[split.size()]);
+                tokens = split.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
             } else {
                 final List<String> split = tokenize(chars, 0, chars.length);
-                tokens = split.toArray(new String[split.size()]);
+                tokens = split.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
             }
         }
     }
diff --git a/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java b/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java
index 7fc33ae..4eaab9d 100644
--- a/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java
+++ b/src/test/java/org/apache/commons/text/diff/ReplacementsFinderTest.java
@@ -34,7 +34,7 @@ import org.junit.jupiter.params.provider.MethodSource;
  */
 public class ReplacementsFinderTest {
 
-    private SimpleHandler handler = null;
+    private SimpleHandler handler;
 
     @BeforeEach
     public void setUp() {