From 8e687c3cc432a821fd157d6d8691c572bbaf5db5 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Thu, 22 Jul 2021 17:15:07 +0200 Subject: [PATCH 01/24] Failing test cases --- .../java/org/apache/commons/lang3/StringUtilsTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index 2f6d9a706a8..bc718a954a5 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -1143,6 +1143,7 @@ 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)); } @Test @@ -1153,6 +1154,7 @@ 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)); } @@ -1166,6 +1168,7 @@ 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("1,2", StringUtils.join(ARRAY_FALSE_TRUE_FALSE, SEPARATOR)); } @Test @@ -1176,6 +1179,7 @@ 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)); } @Test @@ -1186,6 +1190,7 @@ 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,2", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR)); } @Test @@ -1196,6 +1201,7 @@ 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)); } @Test @@ -1206,6 +1212,7 @@ 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_CHAR)); } @Test @@ -1216,6 +1223,7 @@ 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)); } @Test @@ -1226,6 +1234,7 @@ 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)); } @Test From 79b47b8747baa945a2f07620c7cd3fdfad7ee127 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Thu, 22 Jul 2021 17:52:22 +0200 Subject: [PATCH 02/24] Fix for: long[] --- .../java/org/apache/commons/lang3/StringUtils.java | 12 +++++++++++- .../org/apache/commons/lang3/StringUtilsTest.java | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 5f22048ba0b..fc7aeb321d0 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4593,13 +4593,17 @@ 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); + } + + public static String join(final long[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4858,6 +4862,10 @@ public static String join(final T... elements) { return join(elements, null); } + public static String join(long[] elements, 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.

@@ -5520,6 +5528,8 @@ public static String mid(final String str, int pos, final int len) { return str.substring(pos, pos + len); } + // TODO: remove + @Deprecated private static StringJoiner newStringJoiner(final char delimiter) { return new StringJoiner(String.valueOf(delimiter)); } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index bc718a954a5..fd806873436 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -1143,7 +1143,7 @@ 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("1;2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR)); } @Test From 43a603e6ac8a84e42fde54e71078c5ce4788adbc Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Fri, 23 Jul 2021 18:28:31 +0200 Subject: [PATCH 03/24] Join: byte[] and boolean[] --- .../org/apache/commons/lang3/StringUtils.java | 47 +++++++++++++++++-- .../apache/commons/lang3/StringUtilsTest.java | 2 +- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index fc7aeb321d0..bd2af548a1c 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -30,6 +30,10 @@ import java.util.StringJoiner; import java.util.function.Supplier; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.LongStream; +import java.util.stream.Stream; import org.apache.commons.lang3.function.Suppliers; import org.apache.commons.lang3.function.ToBooleanBiFunction; @@ -4603,13 +4607,40 @@ public static String join(final long[] array, final String delimiter, final int if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(delimiter); - for (int i = startIndex; i < endIndex; i++) { - joiner.add(String.valueOf(array[i])); + + return join(LongStream.of(array).boxed().map(String::valueOf), delimiter, startIndex, endIndex); + } + + public static String join(final byte[] array, final String delimiter, final int startIndex, final int endIndex) { + if (array == null) { + return null; } - return joiner.toString(); + if (endIndex - startIndex <= 0) { + return EMPTY; + } + + // Java Stream API does not provide ByteStream + return join(IntStream.range(0, array.length).map(idx -> array[idx]).boxed().map(String::valueOf), delimiter, startIndex, endIndex); + } + + public static String join(final boolean[] array, final String delimiter, final int startIndex, final int endIndex) { + if (array == null) { + return null; + } + if (endIndex - startIndex <= 0) { + return EMPTY; + } + + // Java Stream API does not provide BooleanStream + return join(IntStream.range(0, array.length).boxed().map(idx -> array[idx]).map(String::valueOf), delimiter, startIndex, endIndex); } + private static String join(Stream elements, final String delimiter, final int startIndex, final int endIndex) { + return elements + .skip(startIndex) + .limit(endIndex) + .collect(Collectors.joining(delimiter)); + } /** *

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

@@ -4866,6 +4897,14 @@ public static String join(long[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } + public static String join(byte[] elements, String separator) { + return (elements == null) ? null : join(elements, separator, 0, elements.length); + } + + public static String join(boolean[] elements, 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.

diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index fd806873436..ce7e9288c3a 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -1168,7 +1168,7 @@ 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("1,2", StringUtils.join(ARRAY_FALSE_TRUE_FALSE, SEPARATOR)); + assertEquals("false,true,false", StringUtils.join(ARRAY_FALSE_TRUE_FALSE, SEPARATOR)); } @Test From 5ecaa6653a9f37786a5de6debdccac3ed1eb1a12 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 08:56:26 +0200 Subject: [PATCH 04/24] Join: char[] --- .../org/apache/commons/lang3/StringUtils.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index bd2af548a1c..c4780de1451 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4611,6 +4611,18 @@ public static String join(final long[] array, final String delimiter, final int return join(LongStream.of(array).boxed().map(String::valueOf), delimiter, startIndex, endIndex); } + public static String join(final char[] array, final String delimiter, final int startIndex, final int endIndex) { + if (array == null) { + return null; + } + if (endIndex - startIndex <= 0) { + return EMPTY; + } + + // Java Stream API does not provide CharStream + return join(IntStream.range(0, array.length).mapToObj(idx -> String.valueOf(array[idx])), delimiter, startIndex, endIndex); + } + public static String join(final byte[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; @@ -4893,6 +4905,10 @@ public static String join(final T... elements) { return join(elements, null); } + public static String join(char[] elements, String separator) { + return (elements == null) ? null : join(elements, separator, 0, elements.length); + } + public static String join(long[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } From 41620964d56ed39d0d3388448177f09e5dec38b8 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 19:44:38 +0200 Subject: [PATCH 05/24] Join: double[] --- .../org/apache/commons/lang3/StringUtils.java | 17 +++++++++++++++++ .../apache/commons/lang3/StringUtilsTest.java | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index c4780de1451..f72ee9a33e8 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -31,6 +31,7 @@ import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.stream.DoubleStream; import java.util.stream.IntStream; import java.util.stream.LongStream; import java.util.stream.Stream; @@ -4600,6 +4601,18 @@ public static String join(final long[] array, final char delimiter, final int st return join(array, Character.toString(delimiter), startIndex, endIndex); } + + public static String join(final double[] array, final String delimiter, final int startIndex, final int endIndex) { + if (array == null) { + return null; + } + if (endIndex - startIndex <= 0) { + return EMPTY; + } + + return join(DoubleStream.of(array).boxed().map(String::valueOf), delimiter, startIndex, endIndex); + } + public static String join(final long[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; @@ -4909,6 +4922,10 @@ public static String join(char[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } + public static String join(double[] elements, String separator) { + return (elements == null) ? null : join(elements, separator, 0, elements.length); + } + public static String join(long[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index ce7e9288c3a..f50cda119b6 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -1190,7 +1190,7 @@ 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,2", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR)); + assertEquals("1.0;2.0", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR)); } @Test From 05a4a17891e58482a49c21c76d3963baffd50c88 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 19:55:44 +0200 Subject: [PATCH 06/24] Join: short[] and float[] --- .../org/apache/commons/lang3/StringUtils.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index f72ee9a33e8..7d6b0975aeb 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4601,6 +4601,29 @@ public static String join(final long[] array, final char delimiter, final int st return join(array, Character.toString(delimiter), startIndex, endIndex); } + public static String join(final short[] array, final String delimiter, final int startIndex, final int endIndex) { + if (array == null) { + return null; + } + if (endIndex - startIndex <= 0) { + return EMPTY; + } + + // Java Stream API does not provide ShortStream + return join(IntStream.range(0, array.length).mapToObj(idx -> String.valueOf(array[idx])), delimiter, startIndex, endIndex); + } + + public static String join(final float[] array, final String delimiter, final int startIndex, final int endIndex) { + if (array == null) { + return null; + } + if (endIndex - startIndex <= 0) { + return EMPTY; + } + + // Java Stream API does not provide FloatStream + return join(IntStream.range(0, array.length).mapToObj(idx -> String.valueOf(array[idx])), delimiter, startIndex, endIndex); + } public static String join(final double[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { @@ -4922,6 +4945,14 @@ public static String join(char[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } + public static String join(short[] elements, String separator) { + return (elements == null) ? null : join(elements, separator, 0, elements.length); + } + + public static String join(float[] elements, String separator) { + return (elements == null) ? null : join(elements, separator, 0, elements.length); + } + public static String join(double[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } From e83115da9f37086d7d9522aeceb594ed7b202d3c Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 20:21:33 +0200 Subject: [PATCH 07/24] Code cleanup --- .../org/apache/commons/lang3/StringUtils.java | 130 +++++------------- .../apache/commons/lang3/StringUtilsTest.java | 2 +- 2 files changed, 36 insertions(+), 96 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 7d6b0975aeb..dc6fda4dc6c 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -3927,13 +3927,17 @@ 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); + } + + public static String join(final boolean[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4004,13 +4008,17 @@ 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); + } + + public static String join(final byte[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4081,13 +4089,17 @@ 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); + } + + public static String join(final char[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4158,13 +4170,17 @@ 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); + } + + public static String join(final double[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4235,13 +4251,16 @@ 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); + } + public static String join(final float[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4312,13 +4331,17 @@ 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); + } + + public static String join(final int[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4601,41 +4624,6 @@ public static String join(final long[] array, final char delimiter, final int st return join(array, Character.toString(delimiter), startIndex, endIndex); } - public static String join(final short[] array, final String delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - - // Java Stream API does not provide ShortStream - return join(IntStream.range(0, array.length).mapToObj(idx -> String.valueOf(array[idx])), delimiter, startIndex, endIndex); - } - - public static String join(final float[] array, final String delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - - // Java Stream API does not provide FloatStream - return join(IntStream.range(0, array.length).mapToObj(idx -> String.valueOf(array[idx])), delimiter, startIndex, endIndex); - } - - public static String join(final double[] array, final String delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - - return join(DoubleStream.of(array).boxed().map(String::valueOf), delimiter, startIndex, endIndex); - } - public static String join(final long[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; @@ -4647,42 +4635,6 @@ public static String join(final long[] array, final String delimiter, final int return join(LongStream.of(array).boxed().map(String::valueOf), delimiter, startIndex, endIndex); } - public static String join(final char[] array, final String delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - - // Java Stream API does not provide CharStream - return join(IntStream.range(0, array.length).mapToObj(idx -> String.valueOf(array[idx])), delimiter, startIndex, endIndex); - } - - public static String join(final byte[] array, final String delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - - // Java Stream API does not provide ByteStream - return join(IntStream.range(0, array.length).map(idx -> array[idx]).boxed().map(String::valueOf), delimiter, startIndex, endIndex); - } - - public static String join(final boolean[] array, final String delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - - // Java Stream API does not provide BooleanStream - return join(IntStream.range(0, array.length).boxed().map(idx -> array[idx]).map(String::valueOf), delimiter, startIndex, endIndex); - } - private static String join(Stream elements, final String delimiter, final int startIndex, final int endIndex) { return elements .skip(startIndex) @@ -4745,17 +4697,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); } /** @@ -4901,13 +4843,17 @@ 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); + } + + public static String join(final short[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; } if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = newStringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -5631,12 +5577,6 @@ public static String mid(final String str, int pos, final int len) { return str.substring(pos, pos + len); } - // TODO: remove - @Deprecated - private static StringJoiner newStringJoiner(final char delimiter) { - return new StringJoiner(String.valueOf(delimiter)); - } - /** *

* Similar to Date: Wed, 4 Aug 2021 20:28:09 +0200 Subject: [PATCH 08/24] Removed disabled test --- src/main/java/org/apache/commons/lang3/StringUtils.java | 6 ++++-- .../java/org/apache/commons/lang3/StringUtilsTest.java | 9 --------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index dc6fda4dc6c..c8f20425675 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -31,8 +31,6 @@ import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Collectors; -import java.util.stream.DoubleStream; -import java.util.stream.IntStream; import java.util.stream.LongStream; import java.util.stream.Stream; @@ -4887,6 +4885,10 @@ public static String join(final T... elements) { return join(elements, null); } + public static String join(int[] elements, String separator) { + return (elements == null) ? null : join(elements, separator, 0, elements.length); + } + public static String join(char[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index bc5fd3b1332..a391e16030d 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -1364,15 +1364,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")); From 8fc19c9f9e90e34590c6098610713f75ff25cc7d Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 20:49:21 +0200 Subject: [PATCH 09/24] Code cleanup - method order --- .../org/apache/commons/lang3/StringUtils.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index c8f20425675..00f4336c572 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4885,35 +4885,35 @@ public static String join(final T... elements) { return join(elements, null); } - public static String join(int[] elements, String separator) { + public static String join(byte[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(char[] elements, String separator) { + public static String join(boolean[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(short[] elements, String separator) { + public static String join(char[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(float[] elements, String separator) { + public static String join(double[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(double[] elements, String separator) { + public static String join(float[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(long[] elements, String separator) { + public static String join(int[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(byte[] elements, String separator) { + public static String join(long[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(boolean[] elements, String separator) { + public static String join(short[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } From b0f5bd3572c1f1c678e95a8a6e7111802eec7955 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 20:52:53 +0200 Subject: [PATCH 10/24] Removed import of Streams.* and added missing join method for long[] --- .../org/apache/commons/lang3/StringUtils.java | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 00f4336c572..b95377ee1ba 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -30,9 +30,6 @@ import java.util.StringJoiner; import java.util.function.Supplier; import java.util.regex.Pattern; -import java.util.stream.Collectors; -import java.util.stream.LongStream; -import java.util.stream.Stream; import org.apache.commons.lang3.function.Suppliers; import org.apache.commons.lang3.function.ToBooleanBiFunction; @@ -4622,23 +4619,6 @@ public static String join(final long[] array, final char delimiter, final int st return join(array, Character.toString(delimiter), startIndex, endIndex); } - public static String join(final long[] array, final String delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - - return join(LongStream.of(array).boxed().map(String::valueOf), delimiter, startIndex, endIndex); - } - - private static String join(Stream elements, final String delimiter, final int startIndex, final int endIndex) { - return elements - .skip(startIndex) - .limit(endIndex) - .collect(Collectors.joining(delimiter)); - } /** *

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

@@ -4698,6 +4678,20 @@ public static String join(final Object[] array, final char delimiter, final int return join(array, String.valueOf(delimiter), startIndex, endIndex); } + public static String join(final long[] array, final String delimiter, final int startIndex, final int endIndex) { + if (array == null) { + return null; + } + if (endIndex - startIndex <= 0) { + return EMPTY; + } + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); + for (int i = startIndex; i < endIndex; i++) { + joiner.add(toStringOrEmpty(array[i])); + } + return joiner.toString(); + } + /** *

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

From d106a3f28728455ff703f5eeda4d7c1db196954c Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 20:54:31 +0200 Subject: [PATCH 11/24] Removed generic from method signatures --- .../org/apache/commons/lang3/StringUtils.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index b95377ee1ba..b8233a3aef4 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4879,35 +4879,35 @@ public static String join(final T... elements) { return join(elements, null); } - public static String join(byte[] elements, String separator) { + public static String join(byte[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(boolean[] elements, String separator) { + public static String join(boolean[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(char[] elements, String separator) { + public static String join(char[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(double[] elements, String separator) { + public static String join(double[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(float[] elements, String separator) { + public static String join(float[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(int[] elements, String separator) { + public static String join(int[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(long[] elements, String separator) { + public static String join(long[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } - public static String join(short[] elements, String separator) { + public static String join(short[] elements, String separator) { return (elements == null) ? null : join(elements, separator, 0, elements.length); } From aa208fd24ec1c7cc5a9396d9dd2c002f9f1a6777 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 20:57:53 +0200 Subject: [PATCH 12/24] Code cleanup --- .../org/apache/commons/lang3/StringUtils.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index b8233a3aef4..a27270b307f 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4880,35 +4880,35 @@ public static String join(final T... elements) { } public static String join(byte[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + return (elements == null) ? null : join(elements, separator, 0, elements.length); } public static String join(boolean[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + return (elements == null) ? null : join(elements, separator, 0, elements.length); } public static String join(char[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + return (elements == null) ? null : join(elements, separator, 0, elements.length); } public static String join(double[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + return (elements == null) ? null : join(elements, separator, 0, elements.length); } public static String join(float[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + return (elements == null) ? null : join(elements, separator, 0, elements.length); } public static String join(int[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + return (elements == null) ? null : join(elements, separator, 0, elements.length); } public static String join(long[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + return (elements == null) ? null : join(elements, separator, 0, elements.length); } public static String join(short[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + return (elements == null) ? null : join(elements, separator, 0, elements.length); } /** From b7a7d5118fb1b99f261abd116c913241004b667e Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 21:03:03 +0200 Subject: [PATCH 13/24] Removed toStringOrEmpty --- src/main/java/org/apache/commons/lang3/StringUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index a27270b307f..630235acfff 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4685,7 +4685,7 @@ public static String join(final long[] array, final String delimiter, final int if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); + final StringJoiner joiner = new StringJoiner(delimiter); for (int i = startIndex; i < endIndex; i++) { joiner.add(toStringOrEmpty(array[i])); } From ae3325dd98a9786083f57da5abf0c2bed4e2db57 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 21:13:06 +0200 Subject: [PATCH 14/24] Test cases for null separator --- .../org/apache/commons/lang3/StringUtils.java | 46 +++++++++++++++---- .../apache/commons/lang3/StringUtilsTest.java | 10 +++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 630235acfff..d4ab30f4910 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -3925,6 +3925,36 @@ public static String join(final boolean[] array, final char delimiter, final int 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"
+     * 
+ * + * @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; @@ -3932,7 +3962,7 @@ public static String join(final boolean[] array, final String delimiter, final i if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4013,7 +4043,7 @@ public static String join(final byte[] array, final String delimiter, final int if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4094,7 +4124,7 @@ public static String join(final char[] array, final String delimiter, final int if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4175,7 +4205,7 @@ public static String join(final double[] array, final String delimiter, final in if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4255,7 +4285,7 @@ public static String join(final float[] array, final String delimiter, final int if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4336,7 +4366,7 @@ public static String join(final int[] array, final String delimiter, final int s if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } @@ -4685,7 +4715,7 @@ public static String join(final long[] array, final String delimiter, final int if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); for (int i = startIndex; i < endIndex; i++) { joiner.add(toStringOrEmpty(array[i])); } @@ -4845,7 +4875,7 @@ public static String join(final short[] array, final String delimiter, final int if (endIndex - startIndex <= 0) { return EMPTY; } - final StringJoiner joiner = new StringJoiner(delimiter); + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); for (int i = startIndex; i < endIndex; i++) { joiner.add(String.valueOf(array[i])); } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index a391e16030d..6ec9e8022fb 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -1155,6 +1155,7 @@ public void testJoin_ArrayOfBytes() { 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)); } @@ -1169,6 +1170,7 @@ public void testJoin_ArrayOfBooleans() { 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)); } @Test @@ -1180,6 +1182,7 @@ public void testJoin_ArrayOfChars() { 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)); } @Test @@ -1191,6 +1194,7 @@ public void testJoin_ArrayOfDoubles() { 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)); } @Test @@ -1202,6 +1206,7 @@ public void testJoin_ArrayOfFloats() { 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)); } @Test @@ -1212,7 +1217,8 @@ 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_CHAR)); + assertEquals("1,2", StringUtils.join(INT_PRIM_LIST, SEPARATOR)); + assertEquals("12", StringUtils.join(INT_PRIM_LIST, null)); } @Test @@ -1224,6 +1230,7 @@ public void testJoin_ArrayOfLongs() { 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)); } @Test @@ -1235,6 +1242,7 @@ public void testJoin_ArrayOfShorts() { 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)); } @Test From d23593550bb8858c0bd12daa421bb5a3bf510552 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 21:24:07 +0200 Subject: [PATCH 15/24] Test case for join char[] with null separator --- src/test/java/org/apache/commons/lang3/StringUtilsTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index 6ec9e8022fb..6dfa424a79d 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -1143,7 +1143,8 @@ 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_CHAR)); + assertEquals("1,2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR)); + assertEquals("12", StringUtils.join(CHAR_PRIM_LIST, null)); } @Test From 7d53cfa843d994856b67bf5d062b32a709fe42a0 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 21:59:21 +0200 Subject: [PATCH 16/24] JavaDoc --- .../org/apache/commons/lang3/StringUtils.java | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index d4ab30f4910..9732d842bc0 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4036,6 +4036,37 @@ public static String join(final byte[] array, final char delimiter, final int st 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; @@ -4117,6 +4148,37 @@ public static String join(final char[] array, final char delimiter, final int st 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 char[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; @@ -4198,6 +4260,37 @@ public static String join(final double[] array, final char delimiter, final int 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 double[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; @@ -4278,6 +4371,38 @@ public static String join(final float[] array, final char delimiter) { 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, 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 float[] array, final String delimiter, final int startIndex, final int endIndex) { if (array == null) { return null; @@ -4359,6 +4484,37 @@ public static String join(final int[] array, final char delimiter, final int sta 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; From feee78703e1e677beb68d7434607d065fe857953 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 22:03:06 +0200 Subject: [PATCH 17/24] JavaDoc --- .../org/apache/commons/lang3/StringUtils.java | 90 ++++++++++++++++--- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 9732d842bc0..83decbbe975 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -4805,6 +4805,51 @@ public static String join(final long[] array, final char delimiter, final int st 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; + } + if (endIndex - startIndex <= 0) { + return EMPTY; + } + final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); + for (int i = startIndex; i < endIndex; i++) { + joiner.add(toStringOrEmpty(array[i])); + } + return joiner.toString(); + } + /** *

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

@@ -4864,20 +4909,6 @@ public static String join(final Object[] array, final char delimiter, final int return join(array, String.valueOf(delimiter), startIndex, endIndex); } - public static String join(final long[] array, final String delimiter, final int startIndex, final int endIndex) { - if (array == null) { - return null; - } - if (endIndex - startIndex <= 0) { - return EMPTY; - } - final StringJoiner joiner = new StringJoiner(toStringOrEmpty(delimiter)); - for (int i = startIndex; i < endIndex; i++) { - joiner.add(toStringOrEmpty(array[i])); - } - return joiner.toString(); - } - /** *

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

@@ -5024,6 +5055,37 @@ public static String join(final short[] array, final char delimiter, final int s 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; From ed64d9ca588414e1aa5bca026d41a1775e39c0d2 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Wed, 4 Aug 2021 22:15:57 +0200 Subject: [PATCH 18/24] Fix: removed unused import --- src/test/java/org/apache/commons/lang3/StringUtilsTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index 6dfa424a79d..64d5342bc4b 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; /** From b7693a3cb8e0a8824ab73b80081ce9947e629d75 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Thu, 5 Aug 2021 18:40:48 +0200 Subject: [PATCH 19/24] Code review fix - remove useless parentheses --- .../org/apache/commons/lang3/StringUtils.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 83decbbe975..e0ce1738e69 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -5127,36 +5127,36 @@ public static String join(final T... elements) { return join(elements, null); } - public static String join(byte[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + public static String join(final byte[] elements, String separator) { + return elements == null ? null : join(elements, separator, 0, elements.length); } - public static String join(boolean[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + public static String join(final boolean[] elements, String separator) { + return elements == null ? null : join(elements, separator, 0, elements.length); } - public static String join(char[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + public static String join(final char[] elements, String separator) { + return elements == null ? null : join(elements, separator, 0, elements.length); } - public static String join(double[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + public static String join(final double[] elements, String separator) { + return elements == null ? null : join(elements, separator, 0, elements.length); } - public static String join(float[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + public static String join(final float[] elements, String separator) { + return elements == null ? null : join(elements, separator, 0, elements.length); } - public static String join(int[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + public static String join(final int[] elements, String separator) { + return elements == null ? null : join(elements, separator, 0, elements.length); } - public static String join(long[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + public static String join(final long[] elements, String separator) { + return elements == null ? null : join(elements, separator, 0, elements.length); } - public static String join(short[] elements, String separator) { - return (elements == null) ? null : join(elements, separator, 0, elements.length); + public static String join(final short[] elements, String separator) { + return elements == null ? null : join(elements, separator, 0, elements.length); } /** From ffe3177863038abfaee12d6ab9d447db36010703 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Thu, 5 Aug 2021 18:46:01 +0200 Subject: [PATCH 20/24] Code review fix - brought back helper method --- .../org/apache/commons/lang3/StringUtils.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index e0ce1738e69..6ac1ed242ea 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -3962,7 +3962,7 @@ public static String join(final boolean[] array, final String delimiter, final i 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(String.valueOf(array[i])); } @@ -4074,7 +4074,7 @@ public static String join(final byte[] array, final String delimiter, final int 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(String.valueOf(array[i])); } @@ -4186,7 +4186,7 @@ public static String join(final char[] array, final String delimiter, final int 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(String.valueOf(array[i])); } @@ -4298,7 +4298,7 @@ public static String join(final double[] 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(String.valueOf(array[i])); } @@ -4410,7 +4410,7 @@ public static String join(final float[] array, final String delimiter, final int 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(String.valueOf(array[i])); } @@ -4522,7 +4522,7 @@ public static String join(final int[] array, final String delimiter, final int s 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(String.valueOf(array[i])); } @@ -4843,7 +4843,7 @@ public static String join(final long[] array, final String delimiter, final int 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])); } @@ -4981,7 +4981,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])); } @@ -5093,7 +5093,7 @@ public static String join(final short[] array, final String delimiter, final int 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(String.valueOf(array[i])); } @@ -5821,6 +5821,10 @@ public static String mid(final String str, int pos, final int len) { return str.substring(pos, pos + len); } + private static StringJoiner newStringJoiner(final String delimiter) { + return new StringJoiner(toStringOrEmpty(delimiter)); + } + /** *

* Similar to Date: Thu, 5 Aug 2021 19:07:03 +0200 Subject: [PATCH 21/24] Code review fix - Javadocs --- .../org/apache/commons/lang3/StringUtils.java | 105 +++++++----------- 1 file changed, 38 insertions(+), 67 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 6ac1ed242ea..7e136c484e6 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -3926,20 +3926,17 @@ public static String join(final boolean[] array, final char delimiter, final int } /** - *

- * 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 delimiter is added before or after the list. Null objects or empty strings within the array are represented - * by empty strings. - *

+ *

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], ";")  = "true;false;true"
+     * StringUtils.join([true, false, true], null) = "truefalsetrue"
      * 
* * @param array @@ -4037,21 +4034,17 @@ public static String join(final byte[] array, final char delimiter, final int st } /** - *

- * 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 delimiter is added before or after the list. Null objects or empty strings within the array are represented - * by empty strings. - *

+ *

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

+ *

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. - *

+ *

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"
+     * StringUtils.join(['a', 'b', 'c'], ";")  = "a;b;c"
+     * StringUtils.join(['a',b','c'], null)    = "abc"
      * 
* * @param array @@ -4261,21 +4250,17 @@ 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. - *

+ *

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. - *

+ *

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"
+     * 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 @@ -4373,21 +4358,17 @@ 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. - *

+ *

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. - *

+ *

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"
+     * 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 @@ -4485,21 +4466,17 @@ public static String join(final int[] array, final char delimiter, final int sta } /** - *

- * 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 delimiter is added before or after the list. Null objects or empty strings within the array are represented - * by empty strings. - *

+ *

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"
+     * StringUtils.join([1, 2, 3], ";")        = "1;2;3"
+     * StringUtils.join([1, 2, 3], null)       = "123"
      * 
* * @param array @@ -4806,21 +4783,17 @@ public static String join(final long[] array, final char delimiter, final int st } /** - *

- * 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 delimiter is added before or after the list. Null objects or empty strings within the array are represented - * by empty strings. - *

+ *

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"
+     * StringUtils.join([1, 2, 3], ";")        = "1;2;3"
+     * StringUtils.join([1, 2, 3], null)       = "123"
      * 
* * @param array @@ -5056,9 +5029,7 @@ 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 delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -5069,8 +5040,8 @@ public static String join(final short[] array, final char delimiter, final int s * StringUtils.join(null, *) = null * StringUtils.join([], *) = "" * StringUtils.join([null], *) = "" - * StringUtils.join([1, 2, 3], ';') = "1;2;3" - * StringUtils.join([1, 2, 3], null) = "123" + * StringUtils.join([1, 2, 3], ";") = "1;2;3" + * StringUtils.join([1, 2, 3], null) = "123" * * * @param array From 9c29274049f6140df3cc6f14e88a8c25f1597d3f Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Thu, 5 Aug 2021 21:18:38 +0200 Subject: [PATCH 22/24] Code review fix - added missing Javadocs --- .../org/apache/commons/lang3/StringUtils.java | 187 +++++++++++++++++- 1 file changed, 179 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index 7e136c484e6..de94c4c3047 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -5098,35 +5098,206 @@ public static String join(final T... elements) { return join(elements, null); } - public static String join(final byte[] elements, String 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 + * 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); } - public static String join(final boolean[] elements, String 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 + * 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); } - public static String join(final char[] elements, String 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 + * 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); } - public static String join(final double[] elements, String 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 + * 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); } - public static String join(final float[] elements, String 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 + * 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); } - public static String join(final int[] elements, String 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 + * 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); } - public static String join(final long[] elements, String 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 + * 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); } - public static String join(final short[] elements, String 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 + * 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); } From 5b1a23e2a740bf276cc2bffd53e9457dbbd66887 Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Sun, 22 Aug 2021 09:07:16 +0200 Subject: [PATCH 23/24] Fix: Javadoc - removed paragraph tag from first line --- .../org/apache/commons/lang3/StringUtils.java | 58 +++++++------------ 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java index de94c4c3047..17837dd1042 100644 --- a/src/main/java/org/apache/commons/lang3/StringUtils.java +++ b/src/main/java/org/apache/commons/lang3/StringUtils.java @@ -3926,7 +3926,7 @@ public static String join(final boolean[] array, final char delimiter, final int } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -4034,7 +4034,7 @@ public static String join(final byte[] array, final char delimiter, final int st } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -4107,9 +4107,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 @@ -4142,7 +4140,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.

+ * 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.

@@ -4183,9 +4181,7 @@ public static String join(final char[] array, final String 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 @@ -4215,9 +4211,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 @@ -4250,7 +4244,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.

+ * 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.

@@ -4291,9 +4285,7 @@ public static String join(final double[] array, final String delimiter, final in } /** - *

* 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 @@ -4323,9 +4315,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 @@ -4358,7 +4348,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.

+ * 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.

@@ -4399,9 +4389,7 @@ public static String join(final float[] array, final String 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 @@ -4431,9 +4419,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 @@ -4466,7 +4452,7 @@ public static String join(final int[] array, final char delimiter, final int sta } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -4748,9 +4734,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 @@ -4783,7 +4767,7 @@ public static String join(final long[] array, final char delimiter, final int st } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -5029,7 +5013,7 @@ 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 delimiter is added before or after the list. Null objects or empty strings within the array are represented @@ -5072,8 +5056,8 @@ public static String join(final short[] array, final String delimiter, final int } /** - *

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 @@ -5099,8 +5083,8 @@ public static String join(final T... elements) { } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -5125,8 +5109,8 @@ public static String join(final byte[] elements, final String separator) { } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -5151,8 +5135,8 @@ public static String join(final boolean[] elements, final String separator) { } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -5177,7 +5161,7 @@ public static String join(final char[] elements, final String separator) { } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -5202,7 +5186,7 @@ public static String join(final double[] elements, final String separator) { } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -5227,7 +5211,7 @@ public static String join(final float[] elements, final String separator) { } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -5252,7 +5236,7 @@ public static String join(final int[] elements, final String separator) { } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

@@ -5277,7 +5261,7 @@ public static String join(final long[] elements, final String separator) { } /** - *

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 delimiter is added before or after the list. Null objects or empty strings within the array are represented * by empty strings.

From 26f3b05a71bebafff7793f4700375f00e9a7847b Mon Sep 17 00:00:00 2001 From: Hubert Wo <2518652+HubertWo@users.noreply.github.com> Date: Fri, 3 Sep 2021 05:01:42 +0200 Subject: [PATCH 24/24] Tests for StringUtils.join - null array, String separator --- .../java/org/apache/commons/lang3/StringUtilsTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index 6e29d1d4da8..fad6a944db6 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -1144,6 +1144,7 @@ public void testJoin_ArrayCharSeparator() { 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 @@ -1156,6 +1157,7 @@ public void testJoin_ArrayOfBytes() { 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)); } @@ -1171,6 +1173,7 @@ public void testJoin_ArrayOfBooleans() { 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 @@ -1183,6 +1186,7 @@ public void testJoin_ArrayOfChars() { 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 @@ -1195,6 +1199,7 @@ public void testJoin_ArrayOfDoubles() { 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 @@ -1207,6 +1212,7 @@ public void testJoin_ArrayOfFloats() { 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 @@ -1219,6 +1225,7 @@ public void testJoin_ArrayOfInts() { 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 @@ -1231,6 +1238,7 @@ public void testJoin_ArrayOfLongs() { 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 @@ -1243,6 +1251,7 @@ public void testJoin_ArrayOfShorts() { 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