changeset 8930:d93bf7b29a34

Review feedback for StringJoiner::merge
author henryjen
date Wed, 03 Jul 2013 11:19:01 -0700
parents f15e90d404bf
children 440c09e5f48f
files src/share/classes/java/util/StringJoiner.java
diffstat 1 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/StringJoiner.java	Wed Jul 03 13:32:14 2013 -0400
+++ b/src/share/classes/java/util/StringJoiner.java	Wed Jul 03 11:19:01 2013 -0700
@@ -187,17 +187,17 @@
 
     /**
      * Adds the contents of the supplied {@code StringJoiner} without prefix
-     * and suffix as the next element if it is nonempty. If the supplied
+     * and suffix as the next element if it is non-empty. If the supplied
      * {@code StringJoiner} is empty, the call has no effect.
      *
      * <p>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.
+     * with a non-empty {@code StringJoiner} argument.
      *
      * <p>If the other {@code StringJoiner} is using a different delimiter,
-     * elements from the other {@code StringJoiner} are concatenated with that
-     * delimiter and the result is appended to this {@code StringJoiner} as a
-     * single element.
+     * 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
@@ -207,9 +207,10 @@
         Objects.requireNonNull(other);
         if (other.value != null) {
             StringBuilder builder = prepareBuilder();
-            StringBuilder otherBuffer = other.value;
-            for (int i=other.prefix.length(); i < otherBuffer.length(); i++)
-                builder.append(otherBuffer.charAt(i));
+            StringBuilder otherBuilder = other.value;
+            if (other.prefix.length() < otherBuilder.length()) {
+                builder.append(otherBuilder, other.prefix.length(), otherBuilder.length());
+            }
         }
         return this;
     }