[ 
https://issues.apache.org/jira/browse/LANG-1593?focusedWorklogId=641090&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-641090
 ]

ASF GitHub Bot logged work on LANG-1593:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Aug/21 13:27
            Start Date: 24/Aug/21 13:27
    Worklog Time Spent: 10m 
      Work Description: garydgregory commented on a change in pull request #784:
URL: https://github.com/apache/commons-lang/pull/784#discussion_r694849198



##########
File path: src/main/java/org/apache/commons/lang3/StringUtils.java
##########
@@ -4858,6 +5082,209 @@ public static String join(final short[] array, final 
char delimiter, final int s
         return join(elements, null);
     }
 
+    /**
+     * Joins the elements of the provided array into a single String
+     * containing the provided list of elements.
+     *
+     * <p>No delimiter is added before or after the list. Null objects or 
empty strings within the array are represented
+     * by empty strings.</p>
+     *
+     * <pre>
+     * StringUtils.join(null)            = null
+     * StringUtils.join([])              = ""
+     * StringUtils.join([null])          = ""
+     * StringUtils.join([1, 2, 3], ";")  = "1;2;3"
+     * StringUtils.join([1, 2, 3], null) = "123"
+     * </pre>
+     *
+     * @param elements
+     *            the values to join together, may be null
+     * @param separator
+     *            the separator String to use
+     * @return the joined String, {@code null} if null array input
+     * @since 3.13.0
+     */
+    public static String join(final byte[] elements, final String separator) {
+        return elements == null ? null : join(elements, separator, 0, 
elements.length);
+    }
+
+    /**
+     * Joins the elements of the provided array into a single String
+     * containing the provided list of elements.
+     *
+     * <p>No delimiter is added before or after the list. Null objects or 
empty strings within the array are represented
+     * by empty strings.</p>
+     *
+     * <pre>
+     * StringUtils.join(null)                     = null
+     * StringUtils.join([])                       = ""
+     * StringUtils.join([null])                   = ""
+     * StringUtils.join([false,true,false], ";")  = "false;true;false"
+     * StringUtils.join([false,true,false], null) = "falsetruefalse"
+     * </pre>
+     *
+     * @param elements
+     *            the values to join together, may be null
+     * @param separator
+     *            the separator String to use
+     * @return the joined String, {@code null} if null array input
+     * @since 3.13.0
+     */
+    public static String join(final boolean[] elements, final String 
separator) {
+        return elements == null ? null : join(elements, separator, 0, 
elements.length);
+    }
+
+    /**
+     * Joins the elements of the provided array into a single String
+     * containing the provided list of elements.
+     *
+     * <p>No delimiter is added before or after the list. Null objects or 
empty strings within the array are represented
+     * by empty strings.</p>
+     *
+     * <pre>
+     * StringUtils.join(null)                   = null
+     * StringUtils.join([])                     = ""
+     * StringUtils.join([null])                 = ""
+     * StringUtils.join(['a', 'b', 'c'], ";")   = "a;b;c"
+     * StringUtils.join(['a', 'b', 'c'], null)  = "abc"
+     * </pre>
+     *
+     * @param elements
+     *            the values to join together, may be null
+     * @param separator
+     *            the separator String to use
+     * @return the joined String, {@code null} if null array input
+     * @since 3.13.0
+     */
+    public static String join(final char[] elements, final String separator) {
+        return elements == null ? null : join(elements, separator, 0, 
elements.length);

Review comment:
       The null checks in these methods are superfluous as the join method 
called already checks for the same condition. Less boilerplate is better IMO.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 641090)
    Time Spent: 5h  (was: 4h 50m)

> Common behaviour for StringUtils join APIs when called with char or String 
> delimiter
> ------------------------------------------------------------------------------------
>
>                 Key: LANG-1593
>                 URL: https://issues.apache.org/jira/browse/LANG-1593
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 3.4, 3.11
>            Reporter: Kiruahxh
>            Priority: Minor
>          Time Spent: 5h
>  Remaining Estimate: 0h
>
> For now, join(int[], char) is working well.
>  However, the same join method called with a string delimiter behaves 
> differently : it returns a single memory address which is not the desired 
> behavior.
>  I think that, for coherence, calling StringUtils with a char or String 
> delimiter should return the exact same value.
> Ex :
> {code:java}
> CLASSPATH="./commons-lang3-3.11.jar" jshell 
> |  Welcome to JShell -- Version 11.0.8
> jshell> import org.apache.commons.lang3.StringUtils
> jshell> int[] arr = {1, 2, 3, 4, 5, 6, 7};
> jshell> String result = StringUtils.join(arr, '-');
> result ==> "1-2-3-4-5-6-7"
> jshell> String result = StringUtils.join(arr, "-");
> result ==> "[I@69663380-"
> {code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to