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 2023/12/29 16:14:43 UTC

(commons-exec) 11/12: Deprecate StringUtils.toString(String[], String) in favor of String.join(CharSequence, CharSequence...)

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-exec.git

commit 06c6725b37c455cd472cfc6a5d08eb464dad8796
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Dec 29 11:12:33 2023 -0500

    Deprecate StringUtils.toString(String[], String) in favor of
    String.join(CharSequence, CharSequence...)
    
    - Format-tweaks
    - Inline single-use local variable
---
 src/changes/changes.xml                                     |  1 +
 src/main/java/org/apache/commons/exec/CommandLine.java      |  2 +-
 src/main/java/org/apache/commons/exec/util/MapUtils.java    |  7 -------
 src/main/java/org/apache/commons/exec/util/StringUtils.java | 12 ++++++------
 4 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3be929ab..1398d7de 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -42,6 +42,7 @@
             <action dev="ggregory" type="fix" due-to="ArdenL-Liu, Gary Gregory">[Javadoc] CommandLine.toCleanExecutable(final String dirtyExecutable) IllegalArgumentException #61.</action>
             <action dev="ggregory" type="fix" due-to="Gary Gregory">ExecuteException propagates its cause to its IOException superclass.</action>
             <action dev="ggregory" type="fix" due-to="Gary Gregory">Propagate exception in DebugUtils.handleException(String, Exception).</action>
+            <action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate StringUtils.toString(String[], String) in favor of String#join(CharSequence, CharSequence...).</action>
             <!-- REMOVE -->
             <action dev="ggregory" type="remove" due-to="Gary Gregory">Deprecate DefaultExecuteResultHandler.waitFor(long).</action>
             <action dev="ggregory" type="remove" due-to="Gary Gregory">Deprecate ExecuteWatchdog.ExecuteWatchdog(long).</action>
diff --git a/src/main/java/org/apache/commons/exec/CommandLine.java b/src/main/java/org/apache/commons/exec/CommandLine.java
index 4d488ed5..4eb8d251 100644
--- a/src/main/java/org/apache/commons/exec/CommandLine.java
+++ b/src/main/java/org/apache/commons/exec/CommandLine.java
@@ -403,7 +403,7 @@ public class CommandLine {
      */
     @Override
     public String toString() {
-        return "[" + StringUtils.toString(toStrings(), ", ") + "]";
+        return "[" + String.join(", ", toStrings()) + "]";
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/exec/util/MapUtils.java b/src/main/java/org/apache/commons/exec/util/MapUtils.java
index 73d2fa04..7be47e34 100644
--- a/src/main/java/org/apache/commons/exec/util/MapUtils.java
+++ b/src/main/java/org/apache/commons/exec/util/MapUtils.java
@@ -46,9 +46,7 @@ public class MapUtils {
      * @return the merged map
      */
     public static <K, V> Map<K, V> merge(final Map<K, V> lhs, final Map<K, V> rhs) {
-
         Map<K, V> result = null;
-
         if (lhs == null || lhs.isEmpty()) {
             result = copy(rhs);
         } else if (rhs == null || rhs.isEmpty()) {
@@ -57,7 +55,6 @@ public class MapUtils {
             result = copy(lhs);
             result.putAll(rhs);
         }
-
         return result;
     }
 
@@ -71,19 +68,15 @@ public class MapUtils {
      * @return the clone of the source map
      */
     public static <K, V> Map<String, V> prefix(final Map<K, V> source, final String prefix) {
-
         if (source == null) {
             return null;
         }
-
         final Map<String, V> result = new HashMap<>();
-
         for (final Map.Entry<K, V> entry : source.entrySet()) {
             final K key = entry.getKey();
             final V value = entry.getValue();
             result.put(prefix + '.' + key.toString(), value);
         }
-
         return result;
     }
 }
diff --git a/src/main/java/org/apache/commons/exec/util/StringUtils.java b/src/main/java/org/apache/commons/exec/util/StringUtils.java
index bdecf27f..0b38e52d 100644
--- a/src/main/java/org/apache/commons/exec/util/StringUtils.java
+++ b/src/main/java/org/apache/commons/exec/util/StringUtils.java
@@ -39,7 +39,6 @@ public class StringUtils {
 
     /**
      * Fixes the file separator char for the target platform using the following replacement.
-     *
      * <ul>
      * <li>'/' &#x2192; File.separatorChar</li>
      * <li>'\\' &#x2192; File.separatorChar</li>
@@ -223,12 +222,13 @@ public class StringUtils {
     /**
      * Concatenates an array of string using a separator.
      *
-     * @param strings   the strings to concatenate
-     * @param separator the separator between two strings
-     * @return the concatenated strings
+     * @param strings   the strings to concatenate.
+     * @param separator the separator between two strings.
+     * @return the concatenated strings.
+     * @deprecated Use {@link String#join(CharSequence, CharSequence...)}.
      */
+    @Deprecated
     public static String toString(final String[] strings, final String separator) {
-        final String sb = String.join(separator, strings);
-        return sb;
+        return String.join(separator, strings);
     }
 }
\ No newline at end of file