./src/share/classes/java/lang/StringBuffer.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
*** 147,249 ****
--- 147,263 ----
public StringBuffer(CharSequence seq) {
this(seq.length() + 16);
append(seq);
}
+ @Override
public synchronized int length() {
return count;
}
+ @Override
public synchronized int capacity() {
return value.length;
}
+ @Override
public synchronized void ensureCapacity(int minimumCapacity) {
if (minimumCapacity > value.length) {
expandCapacity(minimumCapacity);
}
}
/**
* @since 1.5
*/
+ @Override
public synchronized void trimToSize() {
super.trimToSize();
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @see #length()
*/
+ @Override
public synchronized void setLength(int newLength) {
super.setLength(newLength);
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @see #length()
*/
+ @Override
public synchronized char charAt(int index) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
return value[index];
}
/**
* @since 1.5
*/
+ @Override
public synchronized int codePointAt(int index) {
return super.codePointAt(index);
}
/**
* @since 1.5
*/
+ @Override
public synchronized int codePointBefore(int index) {
return super.codePointBefore(index);
}
/**
* @since 1.5
*/
+ @Override
public synchronized int codePointCount(int beginIndex, int endIndex) {
return super.codePointCount(beginIndex, endIndex);
}
/**
* @since 1.5
*/
+ @Override
public synchronized int offsetByCodePoints(int index, int codePointOffset) {
return super.offsetByCodePoints(index, codePointOffset);
}
/**
* @throws NullPointerException {@inheritDoc}
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
int dstBegin)
{
super.getChars(srcBegin, srcEnd, dst, dstBegin);
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @see #length()
*/
+ @Override
public synchronized void setCharAt(int index, char ch) {
if ((index < 0) || (index >= count))
throw new StringIndexOutOfBoundsException(index);
value[index] = ch;
}
+ @Override
public synchronized StringBuffer append(Object obj) {
super.append(String.valueOf(obj));
return this;
}
+ @Override
public synchronized StringBuffer append(String str) {
super.append(str);
return this;
}
*** 274,283 ****
--- 288,305 ----
public synchronized StringBuffer append(StringBuffer sb) {
super.append(sb);
return this;
}
+ /**
+ * @since 1.8
+ */
+ @Override
+ synchronized StringBuffer append(AbstractStringBuilder asb) {
+ super.append(asb);
+ return this;
+ }
/**
* Appends the specified {@code CharSequence} to this
* sequence.
* <p>
*** 296,573 ****
*
* @param s the {@code CharSequence} to append.
* @return a reference to this object.
* @since 1.5
*/
public StringBuffer append(CharSequence s) {
! // Note, synchronization achieved via other invocations
! 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());
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.5
*/
public synchronized StringBuffer append(CharSequence s, int start, int end)
{
super.append(s, start, end);
return this;
}
public synchronized StringBuffer append(char[] str) {
super.append(str);
return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public synchronized StringBuffer append(char[] str, int offset, int len) {
super.append(str, offset, len);
return this;
}
public synchronized StringBuffer append(boolean b) {
super.append(b);
return this;
}
public synchronized StringBuffer append(char c) {
super.append(c);
return this;
}
public synchronized StringBuffer append(int i) {
super.append(i);
return this;
}
/**
* @since 1.5
*/
public synchronized StringBuffer appendCodePoint(int codePoint) {
super.appendCodePoint(codePoint);
return this;
}
public synchronized StringBuffer append(long lng) {
super.append(lng);
return this;
}
public synchronized StringBuffer append(float f) {
super.append(f);
return this;
}
public synchronized StringBuffer append(double d) {
super.append(d);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
public synchronized StringBuffer delete(int start, int end) {
super.delete(start, end);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
public synchronized StringBuffer deleteCharAt(int index) {
super.deleteCharAt(index);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
public synchronized StringBuffer replace(int start, int end, String str) {
super.replace(start, end, str);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
public synchronized String substring(int start) {
return substring(start, count);
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.4
*/
public synchronized CharSequence subSequence(int start, int end) {
return super.substring(start, end);
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
public synchronized String substring(int start, int end) {
return super.substring(start, end);
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
public synchronized StringBuffer insert(int index, char[] str, int offset,
int len)
{
super.insert(index, str, offset, len);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
public synchronized StringBuffer insert(int offset, Object obj) {
super.insert(offset, String.valueOf(obj));
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
public synchronized StringBuffer insert(int offset, String str) {
super.insert(offset, str);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
public synchronized StringBuffer insert(int offset, char[] str) {
super.insert(offset, str);
return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.5
*/
public StringBuffer insert(int dstOffset, CharSequence s) {
! // Note, synchronization achieved via other invocations
! if (s == null)
! s = "null";
! if (s instanceof String)
! return this.insert(dstOffset, (String)s);
! return this.insert(dstOffset, s, 0, s.length());
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.5
*/
public synchronized StringBuffer insert(int dstOffset, CharSequence s,
int start, int end)
{
super.insert(dstOffset, s, start, end);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
public StringBuffer insert(int offset, boolean b) {
! return insert(offset, String.valueOf(b));
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
public synchronized StringBuffer insert(int offset, char c) {
super.insert(offset, c);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
public StringBuffer insert(int offset, int i) {
! return insert(offset, String.valueOf(i));
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
public StringBuffer insert(int offset, long l) {
! return insert(offset, String.valueOf(l));
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
public StringBuffer insert(int offset, float f) {
! return insert(offset, String.valueOf(f));
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
public StringBuffer insert(int offset, double d) {
! return insert(offset, String.valueOf(d));
}
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
public int indexOf(String str) {
! return indexOf(str, 0);
}
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
public synchronized int indexOf(String str, int fromIndex) {
! return String.indexOf(value, 0, count,
! str.toCharArray(), 0, str.length(), fromIndex);
}
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
public int lastIndexOf(String str) {
! // Note, synchronization achieved via other invocations
return lastIndexOf(str, count);
}
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
public synchronized int lastIndexOf(String str, int fromIndex) {
! return String.lastIndexOf(value, 0, count,
! str.toCharArray(), 0, str.length(), fromIndex);
}
/**
* @since JDK1.0.2
*/
public synchronized StringBuffer reverse() {
super.reverse();
return this;
}
public synchronized String toString() {
return new String(value, 0, count);
}
/**
--- 318,638 ----
*
* @param s the {@code CharSequence} to append.
* @return a reference to this object.
* @since 1.5
*/
+ @Override
public StringBuffer append(CharSequence s) {
! // Note, synchronization achieved via invocations of other StringBuffer methods after
! // narrowing of s to specific type
! super.append(s);
! return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.5
*/
+ @Override
public synchronized StringBuffer append(CharSequence s, int start, int end)
{
super.append(s, start, end);
return this;
}
+ @Override
public synchronized StringBuffer append(char[] str) {
super.append(str);
return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public synchronized StringBuffer append(char[] str, int offset, int len) {
super.append(str, offset, len);
return this;
}
+ @Override
public synchronized StringBuffer append(boolean b) {
super.append(b);
return this;
}
+ @Override
public synchronized StringBuffer append(char c) {
super.append(c);
return this;
}
+ @Override
public synchronized StringBuffer append(int i) {
super.append(i);
return this;
}
/**
* @since 1.5
*/
+ @Override
public synchronized StringBuffer appendCodePoint(int codePoint) {
super.appendCodePoint(codePoint);
return this;
}
+ @Override
public synchronized StringBuffer append(long lng) {
super.append(lng);
return this;
}
+ @Override
public synchronized StringBuffer append(float f) {
super.append(f);
return this;
}
+ @Override
public synchronized StringBuffer append(double d) {
super.append(d);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
+ @Override
public synchronized StringBuffer delete(int start, int end) {
super.delete(start, end);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
+ @Override
public synchronized StringBuffer deleteCharAt(int index) {
super.deleteCharAt(index);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
+ @Override
public synchronized StringBuffer replace(int start, int end, String str) {
super.replace(start, end, str);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
+ @Override
public synchronized String substring(int start) {
return substring(start, count);
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.4
*/
+ @Override
public synchronized CharSequence subSequence(int start, int end) {
return super.substring(start, end);
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
+ @Override
public synchronized String substring(int start, int end) {
return super.substring(start, end);
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
* @since 1.2
*/
+ @Override
public synchronized StringBuffer insert(int index, char[] str, int offset,
int len)
{
super.insert(index, str, offset, len);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public synchronized StringBuffer insert(int offset, Object obj) {
super.insert(offset, String.valueOf(obj));
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public synchronized StringBuffer insert(int offset, String str) {
super.insert(offset, str);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public synchronized StringBuffer insert(int offset, char[] str) {
super.insert(offset, str);
return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.5
*/
+ @Override
public StringBuffer insert(int dstOffset, CharSequence s) {
! // Note, synchronization achieved via invocations of other StringBuffer methods
! // after narrowing of s to specific type
! super.insert(dstOffset, s);
! return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
* @since 1.5
*/
+ @Override
public synchronized StringBuffer insert(int dstOffset, CharSequence s,
int start, int end)
{
super.insert(dstOffset, s, start, end);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public StringBuffer insert(int offset, boolean b) {
! // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
! // after conversion of b to String by super class method
! super.insert(offset, b);
! return this;
}
/**
* @throws IndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public synchronized StringBuffer insert(int offset, char c) {
super.insert(offset, c);
return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public StringBuffer insert(int offset, int i) {
! // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
! // after conversion of i to String by super class method
! super.insert(offset, i);
! return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public StringBuffer insert(int offset, long l) {
! // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
! // after conversion of l to String by super class method
! super.insert(offset, l);
! return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public StringBuffer insert(int offset, float f) {
! // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
! // after conversion of f to String by super class method
! super.insert(offset, f);
! return this;
}
/**
* @throws StringIndexOutOfBoundsException {@inheritDoc}
*/
+ @Override
public StringBuffer insert(int offset, double d) {
! // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
! // after conversion of d to String by super class method
! super.insert(offset, d);
! return this;
}
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
+ @Override
public int indexOf(String str) {
! // Note, synchronization achieved via invocations of other StringBuffer methods
! return super.indexOf(str);
}
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
+ @Override
public synchronized int indexOf(String str, int fromIndex) {
! return super.indexOf(str, fromIndex);
}
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
+ @Override
public int lastIndexOf(String str) {
! // Note, synchronization achieved via invocations of other StringBuffer methods
return lastIndexOf(str, count);
}
/**
* @throws NullPointerException {@inheritDoc}
* @since 1.4
*/
+ @Override
public synchronized int lastIndexOf(String str, int fromIndex) {
! return super.lastIndexOf(str, fromIndex);
}
/**
* @since JDK1.0.2
*/
+ @Override
public synchronized StringBuffer reverse() {
super.reverse();
return this;
}
+ @Override
public synchronized String toString() {
return new String(value, 0, count);
}
/**