mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-09 19:45:01 +00:00
StringUtils.join(Iterator, String) should only return null when the
Iterator is null
This commit is contained in:
parent
6a95f03a6a
commit
39f08ac62f
@ -90,6 +90,7 @@ The <action> type attribute can be add,update,fix,remove.
|
|||||||
<action type="fix" dev="ggregory" due-to="guicaiyue">Javadoc: StringUtils.repeat("", "x", 3) = "xx"; #918.</action>
|
<action type="fix" dev="ggregory" due-to="guicaiyue">Javadoc: StringUtils.repeat("", "x", 3) = "xx"; #918.</action>
|
||||||
<action type="fix" dev="ggregory" due-to="Marc Wrobel">Fix typos #920, #923.</action>
|
<action type="fix" dev="ggregory" due-to="Marc Wrobel">Fix typos #920, #923.</action>
|
||||||
<action type="fix" dev="ggregory" due-to="Bhimantoro Suryo Admodjo">Simplify condition #925.</action>
|
<action type="fix" dev="ggregory" due-to="Bhimantoro Suryo Admodjo">Simplify condition #925.</action>
|
||||||
|
<action type="fix" dev="ggregory" due-to="Gary Gregory">StringUtils.join(Iterator, String) should only return null when the Iterator is null.</action>
|
||||||
<!-- ADD -->
|
<!-- ADD -->
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GitHub coverage.yml.</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add GitHub coverage.yml.</action>
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add EnumUtils.getEnumSystemProperty(...).</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add EnumUtils.getEnumSystemProperty(...).</action>
|
||||||
@ -160,7 +161,7 @@ The <action> type attribute can be add,update,fix,remove.
|
|||||||
<action issue="LANG-1662" type="add" dev="ggregory" due-to="Daniel Augusto Veronezi Salvador, Gary Gregory, Bruno P. Kinoshita">Let ReflectionToStringBuilder only reflect given field names #849.</action>
|
<action issue="LANG-1662" type="add" dev="ggregory" due-to="Daniel Augusto Veronezi Salvador, Gary Gregory, Bruno P. Kinoshita">Let ReflectionToStringBuilder only reflect given field names #849.</action>
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.of(Enumeration<E>).</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.of(Enumeration<E>).</action>
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.of(Iterable<E>).</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.of(Iterable<E>).</action>
|
||||||
<action type="add" dev="ggregory" due-to="Gary Gregory">Add LangCollectors.</action>
|
<action type="add" dev="ggregory" due-to="Gary Gregory">Add Streams.of(Iterator<E>).</action>
|
||||||
<!-- UPDATE -->
|
<!-- UPDATE -->
|
||||||
<action type="update" dev="ggregory" due-to="Dependabot, XenoAmess, Gary Gregory">Bump actions/cache from 2.1.4 to 3.0.7 #742, #752, #764, #833, #867.</action>
|
<action type="update" dev="ggregory" due-to="Dependabot, XenoAmess, Gary Gregory">Bump actions/cache from 2.1.4 to 3.0.7 #742, #752, #764, #833, #867.</action>
|
||||||
<action type="update" dev="ggregory" due-to="Dependabot">Bump actions/checkout from 2 to 3 #819, #825, #859.</action>
|
<action type="update" dev="ggregory" due-to="Dependabot">Bump actions/checkout from 2 to 3 #819, #825, #859.</action>
|
||||||
|
@ -4350,10 +4350,7 @@ public static String join(final int[] array, final char delimiter, final int sta
|
|||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public static String join(final Iterable<?> iterable, final char separator) {
|
public static String join(final Iterable<?> iterable, final char separator) {
|
||||||
if (iterable == null) {
|
return iterable != null ? join(iterable.iterator(), separator) : null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return join(iterable.iterator(), separator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4371,10 +4368,7 @@ public static String join(final Iterable<?> iterable, final char separator) {
|
|||||||
* @since 2.3
|
* @since 2.3
|
||||||
*/
|
*/
|
||||||
public static String join(final Iterable<?> iterable, final String separator) {
|
public static String join(final Iterable<?> iterable, final String separator) {
|
||||||
if (iterable == null) {
|
return iterable != null ? join(iterable.iterator(), separator) : null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return join(iterable.iterator(), separator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4436,7 +4430,6 @@ public static String join(final Iterator<?> iterator, final char separator) {
|
|||||||
* @return the joined String, {@code null} if null iterator input
|
* @return the joined String, {@code null} if null iterator input
|
||||||
*/
|
*/
|
||||||
public static String join(final Iterator<?> iterator, final String separator) {
|
public static String join(final Iterator<?> iterator, final String separator) {
|
||||||
|
|
||||||
// handle null, zero and one elements before building a buffer
|
// handle null, zero and one elements before building a buffer
|
||||||
if (iterator == null) {
|
if (iterator == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -4444,25 +4437,18 @@ public static String join(final Iterator<?> iterator, final String separator) {
|
|||||||
if (!iterator.hasNext()) {
|
if (!iterator.hasNext()) {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
final Object first = iterator.next();
|
|
||||||
if (!iterator.hasNext()) {
|
|
||||||
return Objects.toString(first, "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// two or more elements
|
// two or more elements
|
||||||
final StringBuilder buf = new StringBuilder(STRING_BUILDER_SIZE); // Java default is 16, probably too small
|
final StringBuilder buf = new StringBuilder(STRING_BUILDER_SIZE); // Java default is 16, probably too small
|
||||||
if (first != null) {
|
|
||||||
buf.append(first);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
if (separator != null) {
|
|
||||||
buf.append(separator);
|
|
||||||
}
|
|
||||||
final Object obj = iterator.next();
|
final Object obj = iterator.next();
|
||||||
if (obj != null) {
|
if (obj != null) {
|
||||||
buf.append(obj);
|
buf.append(obj);
|
||||||
}
|
}
|
||||||
|
if (separator != null && iterator.hasNext()) {
|
||||||
|
buf.append(separator);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
@ -1310,7 +1310,7 @@ public void testJoin_IteratorString() {
|
|||||||
|
|
||||||
assertEquals(TEXT_LIST, StringUtils.join(Arrays.asList(ARRAY_LIST).iterator(), SEPARATOR));
|
assertEquals(TEXT_LIST, StringUtils.join(Arrays.asList(ARRAY_LIST).iterator(), SEPARATOR));
|
||||||
|
|
||||||
assertNull(StringUtils.join(Arrays.asList(NULL_TO_STRING_LIST).iterator(), SEPARATOR));
|
assertEquals("null", StringUtils.join(Arrays.asList(NULL_TO_STRING_LIST).iterator(), SEPARATOR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user