diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index cc423201109..a2a8cdbd683 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -3924,6 +3924,37 @@ public static String join(final boolean[] array, final char delimiter) { * @since 3.12.0 */ public static String join(final boolean[] array, final char delimiter, final int startIndex, final int endIndex) { + return join(array, String.valueOf(delimiter), startIndex, endIndex); + } + + /** + * Joins the elements of the provided array into a single String containing the provided list of elements. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null, *)                   = null
+     * StringUtils.join([], *)                     = ""
+     * StringUtils.join([null], *)                 = ""
+     * StringUtils.join([true, false, true], ";")  = "true;false;true"
+     * StringUtils.join([true, false, true], null) = "truefalsetrue"
+     * 
+ * + * @param array + * the array of values to join together, may be null + * @param delimiter + * the separator String to use + * @param startIndex + * the first index to start joining from. It is an error to pass in a start index past the end of the + * array + * @param endIndex + * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of + * the array + * @return the joined String, {@code null} if null array input + * @since 3.13.0 + */ + public static String join(final boolean[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } @@ -4001,6 +4032,37 @@ public static String join(final byte[] array, final char delimiter) { * @since 3.2 */ public static String join(final byte[] array, final char delimiter, final int startIndex, final int endIndex) { + return join(array, String.valueOf(delimiter), startIndex, endIndex); + } + + /** + * Joins the elements of the provided array into a single String containing the provided list of elements. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null, *)               = null
+     * StringUtils.join([], *)                 = ""
+     * StringUtils.join([null], *)             = ""
+     * StringUtils.join([1, 2, 3], ";")        = "1;2;3"
+     * StringUtils.join([1, 2, 3], null)       = "123"
+     * 
+ * + * @param array + * the array of values to join together, may be null + * @param delimiter + * the separator String to use + * @param startIndex + * the first index to start joining from. It is an error to pass in a start index past the end of the + * array + * @param endIndex + * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of + * the array + * @return the joined String, {@code null} if null array input + * @since 3.13.0 + */ + public static String join(final byte[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } @@ -4047,9 +4109,7 @@ public static String join(final char[] array, final char delimiter) { } /** - *

* Joins the elements of the provided array into a single String containing the provided list of elements. - *

* *

* No delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -4078,6 +4138,37 @@ public static String join(final char[] array, final char delimiter) { * @since 3.2 */ public static String join(final char[] array, final char delimiter, final int startIndex, final int endIndex) { + return join(array, String.valueOf(delimiter), startIndex, endIndex); + } + + /** + * Joins the elements of the provided array into a single String containing the provided list of elements. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null, *)               = null
+     * StringUtils.join([], *)                 = ""
+     * StringUtils.join([null], *)             = ""
+     * StringUtils.join(['a', 'b', 'c'], ";")  = "a;b;c"
+     * StringUtils.join(['a',b','c'], null)    = "abc"
+     * 
+ * + * @param array + * the array of values to join together, may be null + * @param delimiter + * the separator String to use + * @param startIndex + * the first index to start joining from. It is an error to pass in a start index past the end of the + * array + * @param endIndex + * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of + * the array + * @return the joined String, {@code null} if null array input + * @since 3.13.0 + */ + public static String join(final char[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } @@ -4092,9 +4183,7 @@ public static String join(final char[] array, final char delimiter, final int st } /** - *

* Joins the elements of the provided array into a single String containing the provided list of elements. - *

* *

* No delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -4124,9 +4213,7 @@ public static String join(final double[] array, final char delimiter) { } /** - *

* Joins the elements of the provided array into a single String containing the provided list of elements. - *

* *

* No delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -4155,6 +4242,37 @@ public static String join(final double[] array, final char delimiter) { * @since 3.2 */ public static String join(final double[] array, final char delimiter, final int startIndex, final int endIndex) { + return join(array, String.valueOf(delimiter), startIndex, endIndex); + } + + /** + * Joins the elements of the provided array into a single String containing the provided list of elements. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null, *)               = null
+     * StringUtils.join([], *)                 = ""
+     * StringUtils.join([null], *)             = ""
+     * StringUtils.join([1.0, 2.0, 3.0], ";")  = "1.0;2.0;3.0"
+     * StringUtils.join([1.0, 2.0, 3.0], null) = "1.02.03.0"
+     * 
+ * + * @param array + * the array of values to join together, may be null + * @param delimiter + * the separator String to use + * @param startIndex + * the first index to start joining from. It is an error to pass in a start index past the end of the + * array + * @param endIndex + * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of + * the array + * @return the joined String, {@code null} if null array input + * @since 3.13.0 + */ + public static String join(final double[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } @@ -4169,9 +4287,7 @@ public static String join(final double[] array, final char delimiter, final int } /** - *

* Joins the elements of the provided array into a single String containing the provided list of elements. - *

* *

* No delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -4201,9 +4317,7 @@ public static String join(final float[] array, final char delimiter) { } /** - *

* Joins the elements of the provided array into a single String containing the provided list of elements. - *

* *

* No delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -4232,6 +4346,37 @@ public static String join(final float[] array, final char delimiter) { * @since 3.2 */ public static String join(final float[] array, final char delimiter, final int startIndex, final int endIndex) { + return join(array, String.valueOf(delimiter), startIndex, endIndex); + } + + /** + * Joins the elements of the provided array into a single String containing the provided list of elements. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null, *)               = null
+     * StringUtils.join([], *)                 = ""
+     * StringUtils.join([null], *)             = ""
+     * StringUtils.join([1.0, 2.0, 3.0], ";")  = "1.0;2.0;3.0"
+     * StringUtils.join([1.0, 2.0, 3.0], null) = "1.02.03.0"
+     * 
+ * + * @param array + * the array of values to join together, may be null + * @param delimiter + * the separator String to use + * @param startIndex + * the first index to start joining from. It is an error to pass in a start index past the end of the + * array + * @param endIndex + * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of + * the array + * @return the joined String, {@code null} if null array input + * @since 3.13.0 + */ + public static String join(final float[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } @@ -4246,9 +4391,7 @@ public static String join(final float[] array, final char delimiter, final int s } /** - *

* Joins the elements of the provided array into a single String containing the provided list of elements. - *

* *

* No delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -4278,9 +4421,7 @@ public static String join(final int[] array, final char separator) { } /** - *

* Joins the elements of the provided array into a single String containing the provided list of elements. - *

* *

* No delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -4309,6 +4450,37 @@ public static String join(final int[] array, final char separator) { * @since 3.2 */ public static String join(final int[] array, final char delimiter, final int startIndex, final int endIndex) { + return join(array, String.valueOf(delimiter), startIndex, endIndex); + } + + /** + * Joins the elements of the provided array into a single String containing the provided list of elements. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null, *)               = null
+     * StringUtils.join([], *)                 = ""
+     * StringUtils.join([null], *)             = ""
+     * StringUtils.join([1, 2, 3], ";")        = "1;2;3"
+     * StringUtils.join([1, 2, 3], null)       = "123"
+     * 
+ * + * @param array + * the array of values to join together, may be null + * @param delimiter + * the separator String to use + * @param startIndex + * the first index to start joining from. It is an error to pass in a start index past the end of the + * array + * @param endIndex + * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of + * the array + * @return the joined String, {@code null} if null array input + * @since 3.13.0 + */ + public static String join(final int[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } @@ -4564,9 +4736,7 @@ public static String join(final long[] array, final char separator) { } /** - *

* Joins the elements of the provided array into a single String containing the provided list of elements. - *

* *

* No delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -4595,6 +4765,37 @@ public static String join(final long[] array, final char separator) { * @since 3.2 */ public static String join(final long[] array, final char delimiter, final int startIndex, final int endIndex) { + return join(array, Character.toString(delimiter), startIndex, endIndex); + } + + /** + * Joins the elements of the provided array into a single String containing the provided list of elements. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null, *)               = null
+     * StringUtils.join([], *)                 = ""
+     * StringUtils.join([null], *)             = ""
+     * StringUtils.join([1, 2, 3], ";")        = "1;2;3"
+     * StringUtils.join([1, 2, 3], null)       = "123"
+     * 
+ * + * @param array + * the array of values to join together, may be null + * @param delimiter + * the separator String to use + * @param startIndex + * the first index to start joining from. It is an error to pass in a start index past the end of the + * array + * @param endIndex + * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of + * the array + * @return the joined String, {@code null} if null array input + * @since 3.13.0 + */ + public static String join(final long[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } @@ -4603,7 +4804,7 @@ public static String join(final long[] array, final char delimiter, final int st } final StringJoiner joiner = newStringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + joiner.add(toStringOrEmpty(array[i])); } return joiner.toString(); } @@ -4664,17 +4865,7 @@ public static String join(final Object[] array, final char delimiter) { * @since 2.0 */ public static String join(final Object[] array, final char delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - final StringJoiner joiner = newStringJoiner(delimiter); - for (int i = startIndex; i < endIndex; i++) { - joiner.add(toStringOrEmpty(array[i])); - } - return joiner.toString(); + return join(array, String.valueOf(delimiter), startIndex, endIndex); } /** @@ -4749,7 +4940,7 @@ public static String join(final Object[] array, final String delimiter, final in if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); + final StringJoiner joiner = newStringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(toStringOrEmpty(array[i])); } @@ -4820,6 +5011,39 @@ public static String join(final short[] array, final char delimiter) { * @since 3.2 */ public static String join(final short[] array, final char delimiter, final int startIndex, final int endIndex) { + return join(array, String.valueOf(delimiter), startIndex, endIndex); + } + + /** + * Joins the elements of the provided array into a single String containing the provided list of elements. + * + *

+ * No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings. + *

+ * + *
+     * StringUtils.join(null, *)               = null
+     * StringUtils.join([], *)                 = ""
+     * StringUtils.join([null], *)             = ""
+     * StringUtils.join([1, 2, 3], ";")        = "1;2;3"
+     * StringUtils.join([1, 2, 3], null)       = "123"
+     * 
+ * + * @param array + * the array of values to join together, may be null + * @param delimiter + * the separator String to use + * @param startIndex + * the first index to start joining from. It is an error to pass in a start index past the end of the + * array + * @param endIndex + * the index to stop joining from (exclusive). It is an error to pass in an end index past the end of + * the array + * @return the joined String, {@code null} if null array input + * @since 3.13.0 + */ + public static String join(final short[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } @@ -4834,8 +5058,8 @@ public static String join(final short[] array, final char delimiter, final int s } /** - *

Joins the elements of the provided array into a single String - * containing the provided list of elements.

+ * Joins the elements of the provided array into a single String + * containing the provided list of elements. * *

No separator is added to the joined String. * Null objects or empty strings within the array are represented by @@ -4860,6 +5084,209 @@ public static String join(final T... elements) { return join(elements, null); } + /** + * Joins the elements of the provided array into a single String + * containing the provided list of elements. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null)            = null
+     * StringUtils.join([])              = ""
+     * StringUtils.join([null])          = ""
+     * StringUtils.join([1, 2, 3], ";")  = "1;2;3"
+     * StringUtils.join([1, 2, 3], null) = "123"
+     * 
+ * + * @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. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null)                     = null
+     * StringUtils.join([])                       = ""
+     * StringUtils.join([null])                   = ""
+     * StringUtils.join([false,true,false], ";")  = "false;true;false"
+     * StringUtils.join([false,true,false], null) = "falsetruefalse"
+     * 
+ * + * @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. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null)                   = null
+     * StringUtils.join([])                     = ""
+     * StringUtils.join([null])                 = ""
+     * StringUtils.join(['a', 'b', 'c'], ";")   = "a;b;c"
+     * StringUtils.join(['a', 'b', 'c'], null)  = "abc"
+     * 
+ * + * @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); + } + + /** + * Joins the elements of the provided array into a single String containing the provided list of elements. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null)                   = null
+     * StringUtils.join([])                     = ""
+     * StringUtils.join([null])                 = ""
+     * StringUtils.join([1.0, 2.0, 3.0], ";")   = "1.0;2.0;3.0"
+     * StringUtils.join([1.0, 2.0, 3.0], null)  = "1.02.03.0"
+     * 
+ * + * @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 double[] 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. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null)                   = null
+     * StringUtils.join([])                     = ""
+     * StringUtils.join([null])                 = ""
+     * StringUtils.join([1.0, 2.0, 3.0], ";")   = "1.0;2.0;3.0"
+     * StringUtils.join([1.0, 2.0, 3.0], null)  = "1.02.03.0"
+     * 
+ * + * @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 float[] 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. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null)                   = null
+     * StringUtils.join([])                     = ""
+     * StringUtils.join([null])                 = ""
+     * StringUtils.join([1, 2, 3], ";")         = "1;2;3"
+     * StringUtils.join([1, 2, 3], null)        = "123"
+     * 
+ * + * @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 int[] 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. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null)                   = null
+     * StringUtils.join([])                     = ""
+     * StringUtils.join([null])                 = ""
+     * StringUtils.join([1, 2, 3], ";")         = "1;2;3"
+     * StringUtils.join([1, 2, 3], null)        = "123"
+     * 
+ * + * @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 long[] 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. + * + *

No delimiter is added before or after the list. Null objects or empty strings within the array are represented + * by empty strings.

+ * + *
+     * StringUtils.join(null)                   = null
+     * StringUtils.join([])                     = ""
+     * StringUtils.join([null])                 = ""
+     * StringUtils.join([1, 2, 3], ";")         = "1;2;3"
+     * StringUtils.join([1, 2, 3], null)        = "123"
+     * 
+ * + * @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 short[] elements, final String separator) { + return elements == null ? null : join(elements, separator, 0, elements.length); + } + /** *

Joins the elements of the provided varargs into a * single String containing the provided elements.

@@ -5522,8 +5949,8 @@ public static String mid(final String str, int pos, final int len) { return str.substring(pos, pos + len); } - private static StringJoiner newStringJoiner(final char delimiter) { - return new StringJoiner(String.valueOf(delimiter)); + private static StringJoiner newStringJoiner(final String delimiter) { + return new StringJoiner(toStringOrEmpty(delimiter)); } /** diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index e501982f26b..39f66197e7a 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -44,7 +44,6 @@ import org.apache.commons.lang3.mutable.MutableInt; import org.apache.commons.lang3.text.WordUtils; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** @@ -1143,6 +1142,9 @@ public void testJoin_ArrayCharSeparator() { assertEquals("foo/2", StringUtils.join(MIXED_TYPE_LIST, '/', 0, 2)); assertEquals("2", StringUtils.join(MIXED_TYPE_LIST, '/', 1, 2)); assertEquals("", StringUtils.join(MIXED_TYPE_LIST, '/', 2, 1)); + assertEquals("1,2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR)); + assertEquals("12", StringUtils.join(CHAR_PRIM_LIST, null)); + assertNull(StringUtils.join((Object []) null, SEPARATOR)); } @Test @@ -1153,6 +1155,9 @@ public void testJoin_ArrayOfBytes() { assertNull(StringUtils.join((byte[]) null, SEPARATOR_CHAR, 0, 1)); assertEquals(StringUtils.EMPTY, StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); assertEquals(StringUtils.EMPTY, StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); + assertEquals("1,2", StringUtils.join(BYTE_PRIM_LIST, SEPARATOR)); + assertEquals("12", StringUtils.join(BYTE_PRIM_LIST, null)); + assertNull(StringUtils.join((byte[]) null, SEPARATOR)); } @@ -1166,6 +1171,9 @@ public void testJoin_ArrayOfBooleans() { assertNull(StringUtils.join((boolean[]) null, SEPARATOR_CHAR, 0, 1)); assertEquals(StringUtils.EMPTY, StringUtils.join(ARRAY_FALSE_FALSE, SEPARATOR_CHAR, 0, 0)); assertEquals(StringUtils.EMPTY, StringUtils.join(ARRAY_FALSE_TRUE_FALSE, SEPARATOR_CHAR, 1, 0)); + assertEquals("false,true,false", StringUtils.join(ARRAY_FALSE_TRUE_FALSE, SEPARATOR)); + assertEquals("falsetruefalse", StringUtils.join(ARRAY_FALSE_TRUE_FALSE, null)); + assertNull(StringUtils.join((boolean[]) null, SEPARATOR)); } @Test @@ -1176,6 +1184,9 @@ public void testJoin_ArrayOfChars() { assertNull(StringUtils.join((char[]) null, SEPARATOR_CHAR, 0, 1)); assertEquals(StringUtils.EMPTY, StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); assertEquals(StringUtils.EMPTY, StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); + assertEquals("1,2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR)); + assertEquals("12", StringUtils.join(CHAR_PRIM_LIST, null)); + assertNull(StringUtils.join((char[]) null, SEPARATOR)); } @Test @@ -1186,6 +1197,9 @@ public void testJoin_ArrayOfDoubles() { assertNull(StringUtils.join((double[]) null, SEPARATOR_CHAR, 0, 1)); assertEquals(StringUtils.EMPTY, StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); assertEquals(StringUtils.EMPTY, StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); + assertEquals("1.0,2.0", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR)); + assertEquals("1.02.0", StringUtils.join(DOUBLE_PRIM_LIST, null)); + assertNull(StringUtils.join((double[]) null, SEPARATOR)); } @Test @@ -1196,6 +1210,9 @@ public void testJoin_ArrayOfFloats() { assertNull(StringUtils.join((float[]) null, SEPARATOR_CHAR, 0, 1)); assertEquals(StringUtils.EMPTY, StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); assertEquals(StringUtils.EMPTY, StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); + assertEquals("1.0,2.0", StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR)); + assertEquals("1.02.0", StringUtils.join(FLOAT_PRIM_LIST, null)); + assertNull(StringUtils.join((float[]) null, SEPARATOR)); } @Test @@ -1206,6 +1223,9 @@ public void testJoin_ArrayOfInts() { assertNull(StringUtils.join((int[]) null, SEPARATOR_CHAR, 0, 1)); assertEquals(StringUtils.EMPTY, StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); assertEquals(StringUtils.EMPTY, StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); + assertEquals("1,2", StringUtils.join(INT_PRIM_LIST, SEPARATOR)); + assertEquals("12", StringUtils.join(INT_PRIM_LIST, null)); + assertNull(StringUtils.join((int[]) null, SEPARATOR)); } @Test @@ -1216,6 +1236,9 @@ public void testJoin_ArrayOfLongs() { assertNull(StringUtils.join((long[]) null, SEPARATOR_CHAR, 0, 1)); assertEquals(StringUtils.EMPTY, StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); assertEquals(StringUtils.EMPTY, StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); + assertEquals("1,2", StringUtils.join(LONG_PRIM_LIST, SEPARATOR)); + assertEquals("12", StringUtils.join(LONG_PRIM_LIST, null)); + assertNull(StringUtils.join((long[]) null, SEPARATOR)); } @Test @@ -1226,6 +1249,9 @@ public void testJoin_ArrayOfShorts() { assertNull(StringUtils.join((short[]) null, SEPARATOR_CHAR, 0, 1)); assertEquals(StringUtils.EMPTY, StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); assertEquals(StringUtils.EMPTY, StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); + assertEquals("1,2", StringUtils.join(SHORT_PRIM_LIST, SEPARATOR)); + assertEquals("12", StringUtils.join(SHORT_PRIM_LIST, null)); + assertNull(StringUtils.join((short[]) null, SEPARATOR)); } @Test @@ -1355,15 +1381,6 @@ public void testJoin_Objectarray() { assertEquals("foo2", StringUtils.join(MIXED_TYPE_LIST)); } - @Disabled - @Test - public void testLang1593() { - final int[] arr = {1, 2, 3, 4, 5, 6, 7}; - final String expected = StringUtils.join(arr, '-'); - final String actual = StringUtils.join(arr, "-"); - assertEquals(expected, actual); - } - @Test public void testJoin_Objects() { assertEquals("abc", StringUtils.join("a", "b", "c"));