./src/share/classes/java/lang/AbstractStringBuilder.java
Print this page
rev 5910 : 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
Summary: update StringBuilder & StringBuffer to consistently handle forwarding to AbstractStringBuilder. Some additional cleanup (removal of refs to sub-classes from AbstractStringBuilder)
Reviewed-by: chegar,alanb
*** 68,77 ****
--- 68,78 ----
* Returns the length (character count).
*
* @return the length of the sequence of characters currently
* represented by this object
*/
+ @Override
public int length() {
return count;
}
/**
*** 198,207 ****
--- 199,209 ----
* @param index the index of the desired {@code char} value.
* @return the {@code char} value at the specified index.
* @throws IndexOutOfBoundsException if {@code index} is
* negative or greater than or equal to {@code length()}.
*/
+ @Override
public char charAt(int index) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
return value[index];
}
*** 429,446 ****
sb.getChars(0, len, value, count);
count += len;
return this;
}
// Documentation in subclasses because of synchro difference
public AbstractStringBuilder append(CharSequence s) {
if (s == null)
s = "null";
if (s instanceof String)
return this.append((String)s);
! if (s instanceof StringBuffer)
! return this.append((StringBuffer)s);
return this.append(s, 0, s.length());
}
/**
* Appends a subsequence of the specified {@code CharSequence} to this
--- 431,463 ----
sb.getChars(0, len, value, count);
count += len;
return this;
}
+ /**
+ * @since 1.8
+ */
+ AbstractStringBuilder append(AbstractStringBuilder asb) {
+ if (asb == null)
+ return append("null");
+ int len = asb.length();
+ ensureCapacityInternal(count + len);
+ asb.getChars(0, len, value, count);
+ count += len;
+ return this;
+ }
+
// Documentation in subclasses because of synchro difference
+ @Override
public AbstractStringBuilder append(CharSequence s) {
if (s == null)
s = "null";
if (s instanceof String)
return this.append((String)s);
! if (s instanceof AbstractStringBuilder)
! return this.append((AbstractStringBuilder)s);
!
return this.append(s, 0, s.length());
}
/**
* Appends a subsequence of the specified {@code CharSequence} to this
*** 469,478 ****
--- 486,496 ----
* @throws IndexOutOfBoundsException if
* {@code start} is negative, or
* {@code start} is greater than {@code end} or
* {@code end} is greater than {@code s.length()}
*/
+ @Override
public AbstractStringBuilder append(CharSequence s, int start, int end) {
if (s == null)
s = "null";
if ((start < 0) || (start > end) || (end > s.length()))
throw new IndexOutOfBoundsException(
*** 583,592 ****
--- 601,611 ----
* {@link #append(String) appended} to this character sequence.
*
* @param c a {@code char}.
* @return a reference to this object.
*/
+ @Override
public AbstractStringBuilder append(char c) {
ensureCapacityInternal(count + 1);
value[count++] = c;
return this;
}
*** 845,854 ****
--- 864,874 ----
* if <tt>start</tt> or <tt>end</tt> are negative,
* if <tt>end</tt> is greater than <tt>length()</tt>,
* or if <tt>start</tt> is greater than <tt>end</tt>
* @spec JSR-51
*/
+ @Override
public CharSequence subSequence(int start, int end) {
return substring(start, end);
}
/**
*** 1395,1404 ****
--- 1415,1425 ----
* changes to this sequence do not affect the contents of the
* {@code String}.
*
* @return a string representation of this sequence of characters.
*/
+ @Override
public abstract String toString();
/**
* Needed by <tt>String</tt> for the contentEquals method.
*/