Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1242,14 +1242,20 @@ public static byte decodeHexByte(CharSequence s, int pos) {
}

/**
* Create the common-delimited {@link String} by one or more {@link String} members
* Creates a comma-delimited string from one or more string values.
*
* @param one one {@link String}
* @param others others {@link String}
* @return <code>null</code> if <code>one</code> or <code>others</code> is <code>null</code>
* @param one the first string value
* @param others additional string values
* @return the combined string, or null if the first value is null
* @since 2.7.8
*/
public static String toCommaDelimitedString(String one, String... others) {
if (one == null) {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if one != null && others == null

should return one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it should return one

}
if (others == null) {
return one;
}
String another = arrayToDelimitedString(others, COMMA_SEPARATOR);
return isEmpty(another) ? one : one + COMMA_SEPARATOR + another;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ private void assertEqualsWithoutSpaces(String expect, String actual) {

/**
* Test {@link StringUtils#toCommaDelimitedString(String, String...)}
*
* @since 2.7.8
*/
@Test
Expand All @@ -484,6 +485,9 @@ void testToCommaDelimitedString() {
value = toCommaDelimitedString(null, null);
assertNull(value);

value = toCommaDelimitedString("one", null);
assertEquals("one", value);

value = toCommaDelimitedString("");
assertEquals("", value);

Expand Down