src/share/classes/java/lang/StringBuilder.java
Print this page
rev 6294 : 8005118: Javadoc styles are inconsistent
Summary: use a common javadoc style in the String classes
Reviewed-by: darcy
*** 26,68 ****
package java.lang;
/**
* A mutable sequence of characters. This class provides an API compatible
! * with <code>StringBuffer</code>, but with no guarantee of synchronization.
* This class is designed for use as a drop-in replacement for
! * <code>StringBuffer</code> in places where the string buffer was being
* used by a single thread (as is generally the case). Where possible,
* it is recommended that this class be used in preference to
! * <code>StringBuffer</code> as it will be faster under most implementations.
*
! * <p>The principal operations on a <code>StringBuilder</code> are the
! * <code>append</code> and <code>insert</code> methods, which are
* overloaded so as to accept data of any type. Each effectively
* converts a given datum to a string and then appends or inserts the
* characters of that string to the string builder. The
! * <code>append</code> method always adds these characters at the end
! * of the builder; the <code>insert</code> method adds the characters at
* a specified point.
* <p>
! * For example, if <code>z</code> refers to a string builder object
! * whose current contents are "<code>start</code>", then
! * the method call <code>z.append("le")</code> would cause the string
! * builder to contain "<code>startle</code>", whereas
! * <code>z.insert(4, "le")</code> would alter the string builder to
! * contain "<code>starlet</code>".
* <p>
- * In general, if sb refers to an instance of a <code>StringBuilder</code>,
- * then <code>sb.append(x)</code> has the same effect as
- * <code>sb.insert(sb.length(), x)</code>.
- *
* Every string builder has a capacity. As long as the length of the
* character sequence contained in the string builder does not exceed
* the capacity, it is not necessary to allocate a new internal
* buffer. If the internal buffer overflows, it is automatically made larger.
*
! * <p>Instances of <code>StringBuilder</code> are not safe for
* use by multiple threads. If such synchronization is required then it is
* recommended that {@link java.lang.StringBuffer} be used.
*
* @author Michael McCloskey
* @see java.lang.StringBuffer
--- 26,68 ----
package java.lang;
/**
* A mutable sequence of characters. This class provides an API compatible
! * with {@code StringBuffer}, but with no guarantee of synchronization.
* This class is designed for use as a drop-in replacement for
! * {@code StringBuffer} in places where the string buffer was being
* used by a single thread (as is generally the case). Where possible,
* it is recommended that this class be used in preference to
! * {@code StringBuffer} as it will be faster under most implementations.
*
! * <p>The principal operations on a {@code StringBuilder} are the
! * {@code append} and {@code insert} methods, which are
* overloaded so as to accept data of any type. Each effectively
* converts a given datum to a string and then appends or inserts the
* characters of that string to the string builder. The
! * {@code append} method always adds these characters at the end
! * of the builder; the {@code insert} method adds the characters at
* a specified point.
* <p>
! * For example, if {@code z} refers to a string builder object
! * whose current contents are "{@code start}", then
! * the method call {@code z.append("le")} would cause the string
! * builder to contain "{@code startle}", whereas
! * {@code z.insert(4, "le")} would alter the string builder to
! * contain "{@code starlet}".
! * <p>
! * In general, if sb refers to an instance of a {@code StringBuilder},
! * then {@code sb.append(x)} has the same effect as
! * {@code sb.insert(sb.length(), x)}.
* <p>
* Every string builder has a capacity. As long as the length of the
* character sequence contained in the string builder does not exceed
* the capacity, it is not necessary to allocate a new internal
* buffer. If the internal buffer overflows, it is automatically made larger.
*
! * <p>Instances of {@code StringBuilder} are not safe for
* use by multiple threads. If such synchronization is required then it is
* recommended that {@link java.lang.StringBuffer} be used.
*
* @author Michael McCloskey
* @see java.lang.StringBuffer
*** 85,125 ****
super(16);
}
/**
* Constructs a string builder with no characters in it and an
! * initial capacity specified by the <code>capacity</code> argument.
*
* @param capacity the initial capacity.
! * @throws NegativeArraySizeException if the <code>capacity</code>
! * argument is less than <code>0</code>.
*/
public StringBuilder(int capacity) {
super(capacity);
}
/**
* Constructs a string builder initialized to the contents of the
* specified string. The initial capacity of the string builder is
! * <code>16</code> plus the length of the string argument.
*
* @param str the initial contents of the buffer.
! * @throws NullPointerException if <code>str</code> is <code>null</code>
*/
public StringBuilder(String str) {
super(str.length() + 16);
append(str);
}
/**
* Constructs a string builder that contains the same characters
! * as the specified <code>CharSequence</code>. The initial capacity of
! * the string builder is <code>16</code> plus the length of the
! * <code>CharSequence</code> argument.
*
* @param seq the sequence to copy.
! * @throws NullPointerException if <code>seq</code> is <code>null</code>
*/
public StringBuilder(CharSequence seq) {
this(seq.length() + 16);
append(seq);
}
--- 85,125 ----
super(16);
}
/**
* Constructs a string builder with no characters in it and an
! * initial capacity specified by the {@code capacity} argument.
*
* @param capacity the initial capacity.
! * @throws NegativeArraySizeException if the {@code capacity}
! * argument is less than {@code 0}.
*/
public StringBuilder(int capacity) {
super(capacity);
}
/**
* Constructs a string builder initialized to the contents of the
* specified string. The initial capacity of the string builder is
! * {@code 16} plus the length of the string argument.
*
* @param str the initial contents of the buffer.
! * @throws NullPointerException if {@code str} is {@code null}
*/
public StringBuilder(String str) {
super(str.length() + 16);
append(str);
}
/**
* Constructs a string builder that contains the same characters
! * as the specified {@code CharSequence}. The initial capacity of
! * the string builder is {@code 16} plus the length of the
! * {@code CharSequence} argument.
*
* @param seq the sequence to copy.
! * @throws NullPointerException if {@code seq} is {@code null}
*/
public StringBuilder(CharSequence seq) {
this(seq.length() + 16);
append(seq);
}
*** 134,159 ****
super.append(str);
return this;
}
/**
! * Appends the specified <tt>StringBuffer</tt> to this sequence.
* <p>
! * The characters of the <tt>StringBuffer</tt> argument are appended,
* in order, to this sequence, increasing the
* length of this sequence by the length of the argument.
! * If <tt>sb</tt> is <tt>null</tt>, then the four characters
! * <tt>"null"</tt> are appended to this sequence.
* <p>
* Let <i>n</i> be the length of this character sequence just prior to
! * execution of the <tt>append</tt> method. Then the character at index
* <i>k</i> in the new character sequence is equal to the character at
* index <i>k</i> in the old character sequence, if <i>k</i> is less than
* <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
! * in the argument <code>sb</code>.
*
! * @param sb the <tt>StringBuffer</tt> to append.
* @return a reference to this object.
*/
public StringBuilder append(StringBuffer sb) {
super.append(sb);
return this;
--- 134,159 ----
super.append(str);
return this;
}
/**
! * Appends the specified {@code StringBuffer} to this sequence.
* <p>
! * The characters of the {@code StringBuffer} argument are appended,
* in order, to this sequence, increasing the
* length of this sequence by the length of the argument.
! * If {@code sb} is {@code null}, then the four characters
! * {@code "null"} are appended to this sequence.
* <p>
* Let <i>n</i> be the length of this character sequence just prior to
! * execution of the {@code append} method. Then the character at index
* <i>k</i> in the new character sequence is equal to the character at
* index <i>k</i> in the old character sequence, if <i>k</i> is less than
* <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
! * in the argument {@code sb}.
*
! * @param sb the {@code StringBuffer} to append.
* @return a reference to this object.
*/
public StringBuilder append(StringBuffer sb) {
super.append(sb);
return this;
*** 416,432 ****
// Create a copy, don't share the array
return new String(value, 0, count);
}
/**
! * Save the state of the <tt>StringBuilder</tt> instance to a stream
* (that is, serialize it).
*
* @serialData the number of characters currently stored in the string
! * builder (<tt>int</tt>), followed by the characters in the
! * string builder (<tt>char[]</tt>). The length of the
! * <tt>char</tt> array may be greater than the number of
* characters currently stored in the string builder, in which
* case extra characters are ignored.
*/
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {
--- 416,432 ----
// Create a copy, don't share the array
return new String(value, 0, count);
}
/**
! * Save the state of the {@code StringBuilder} instance to a stream
* (that is, serialize it).
*
* @serialData the number of characters currently stored in the string
! * builder ({@code int}), followed by the characters in the
! * string builder ({@code char[]}). The length of the
! * {@code char} array may be greater than the number of
* characters currently stored in the string builder, in which
* case extra characters are ignored.
*/
private void writeObject(java.io.ObjectOutputStream s)
throws java.io.IOException {