--- old/src/share/classes/java/util/StringJoiner.java 2013-07-03 14:07:36.686987111 -0700 +++ new/src/share/classes/java/util/StringJoiner.java 2013-07-03 14:07:36.506987115 -0700 @@ -114,8 +114,9 @@ * @throws NullPointerException if {@code prefix}, {@code delimiter}, or * {@code suffix} is {@code null} */ - public StringJoiner(CharSequence delimiter, CharSequence prefix, - CharSequence suffix) { + public StringJoiner(CharSequence delimiter, + CharSequence prefix, + CharSequence suffix) { Objects.requireNonNull(prefix, "The prefix must not be null"); Objects.requireNonNull(delimiter, "The delimiter must not be null"); Objects.requireNonNull(suffix, "The suffix must not be null"); @@ -172,7 +173,7 @@ } /** - * Add the a copy of the supplied {@code CharSequence} value as the next + * Adds a copy of the given {@code CharSequence} value as the next * element of the {@code StringJoiner} value. If {@code newElement} is * {@code null}, then {@code "null"} is added. * @@ -184,6 +185,36 @@ return this; } + /** + * Adds the contents of the given {@code StringJoiner} without prefix and + * suffix as the next element if it is non-empty. If the given {@code + * StringJoiner} is empty, the call has no effect. + * + *

A {@code StringJoiner} is empty if {@link #add(CharSequence) add()} + * has never been called, and if {@code merge()} has never been called + * with a non-empty {@code StringJoiner} argument. + * + *

If the other {@code StringJoiner} is using a different delimiter, + * then elements from the other {@code StringJoiner} are concatenated with + * that delimiter and the result is appended to this {@code StringJoiner} + * as a single element. + * + * @param other The {@code StringJoiner} whose contents should be merged + * into this one + * @throws NullPointerException if the other {@code StringJoiner} is null + */ + public StringJoiner merge(StringJoiner other) { + Objects.requireNonNull(other); + if (other.value != null) { + StringBuilder builder = prepareBuilder(); + StringBuilder otherBuilder = other.value; + if (other.prefix.length() < otherBuilder.length()) { + builder.append(otherBuilder, other.prefix.length(), otherBuilder.length()); + } + } + return this; + } + private StringBuilder prepareBuilder() { if (value != null) { value.append(delimiter);