jdk/src/share/classes/java/lang/StringBuffer.java
author jrose
Tue, 17 May 2011 19:48:19 -0700
changeset 9731 d0f7a3e441c4
parent 5506 202f599c92aa
child 13155 8140afb39557
permissions -rw-r--r--
7044892: JSR 292: API entry points sometimes throw the wrong exceptions or doesn't throw the expected one Summary: point-fixes for 7038847, 7038860, 7042656, 7042829, 7041853, and several other reports Reviewed-by: never, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     2
 * Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * A thread-safe, mutable sequence of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * A string buffer is like a {@link String}, but can be modified. At any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * point in time it contains some particular sequence of characters, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * the length and content of the sequence can be changed through certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * method calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * String buffers are safe for use by multiple threads. The methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * are synchronized where necessary so that all the operations on any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * particular instance behave as if they occur in some serial order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * that is consistent with the order of the method calls made by each of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * the individual threads involved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The principal operations on a <code>StringBuffer</code> are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>append</code> and <code>insert</code> methods, which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * overloaded so as to accept data of any type. Each effectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * converts a given datum to a string and then appends or inserts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * characters of that string to the string buffer. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <code>append</code> method always adds these characters at the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * of the buffer; the <code>insert</code> method adds the characters at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * a specified point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * For example, if <code>z</code> refers to a string buffer object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * whose current contents are "<code>start</code>", then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * the method call <code>z.append("le")</code> would cause the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * buffer to contain "<code>startle</code>", whereas
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>z.insert(4, "le")</code> would alter the string buffer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * contain "<code>starlet</code>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * In general, if sb refers to an instance of a <code>StringBuffer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * then <code>sb.append(x)</code> has the same effect as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <code>sb.insert(sb.length(),&nbsp;x)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Whenever an operation occurs involving a source sequence (such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * appending or inserting from a source sequence) this class synchronizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * only on the string buffer performing the operation, not on the source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Every string buffer has a capacity. As long as the length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * character sequence contained in the string buffer does not exceed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * the capacity, it is not necessary to allocate a new internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * buffer array. If the internal buffer overflows, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * automatically made larger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * As of  release JDK 5, this class has been supplemented with an equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * class designed for use by a single thread, {@link StringBuilder}.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <tt>StringBuilder</tt> class should generally be used in preference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * this one, as it supports all of the same operations but it is faster, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * it performs no synchronization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author      Arthur van Hoff
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * @see     java.lang.StringBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @see     java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 public final class StringBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    extends AbstractStringBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    implements java.io.Serializable, CharSequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /** use serialVersionUID from JDK 1.0.2 for interoperability */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    static final long serialVersionUID = 3388685877147921107L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Constructs a string buffer with no characters in it and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * initial capacity of 16 characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public StringBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Constructs a string buffer with no characters in it and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * the specified initial capacity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param      capacity  the initial capacity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @exception  NegativeArraySizeException  if the <code>capacity</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *               argument is less than <code>0</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public StringBuffer(int capacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        super(capacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Constructs a string buffer initialized to the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * specified string. The initial capacity of the string buffer is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * <code>16</code> plus the length of the string argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param   str   the initial contents of the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @exception NullPointerException if <code>str</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public StringBuffer(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        super(str.length() + 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Constructs a string buffer that contains the same characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * as the specified <code>CharSequence</code>. The initial capacity of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * the string buffer is <code>16</code> plus the length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <code>CharSequence</code> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * If the length of the specified <code>CharSequence</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * less than or equal to zero, then an empty buffer of capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <code>16</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param      seq   the sequence to copy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @exception NullPointerException if <code>seq</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public StringBuffer(CharSequence seq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        this(seq.length() + 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        append(seq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public synchronized int length() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public synchronized int capacity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return value.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public synchronized void ensureCapacity(int minimumCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (minimumCapacity > value.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            expandCapacity(minimumCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @since      1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public synchronized void trimToSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        super.trimToSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public synchronized void setLength(int newLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        super.setLength(newLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public synchronized char charAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if ((index < 0) || (index >= count))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            throw new StringIndexOutOfBoundsException(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return value[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @since      1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public synchronized int codePointAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return super.codePointAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @since     1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public synchronized int codePointBefore(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return super.codePointBefore(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @since     1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public synchronized int codePointCount(int beginIndex, int endIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        return super.codePointCount(beginIndex, endIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @since     1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public synchronized int offsetByCodePoints(int index, int codePointOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        return super.offsetByCodePoints(index, codePointOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   215
    public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                      int dstBegin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        super.getChars(srcBegin, srcEnd, dst, dstBegin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public synchronized void setCharAt(int index, char ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if ((index < 0) || (index >= count))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            throw new StringIndexOutOfBoundsException(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        value[index] = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public synchronized StringBuffer append(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        super.append(String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public synchronized StringBuffer append(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        super.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Appends the specified <tt>StringBuffer</tt> to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * The characters of the <tt>StringBuffer</tt> argument are appended,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * length of this <tt>StringBuffer</tt> by the length of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Let <i>n</i> be the length of the old character sequence, the one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * contained in the <tt>StringBuffer</tt> just prior to execution of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <tt>append</tt> method. Then the character at index <i>k</i> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * the new character sequence is equal to the character at index <i>k</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * in the old character sequence, if <i>k</i> is less than <i>n</i>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * otherwise, it is equal to the character at index <i>k-n</i> in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * argument <code>sb</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * This method synchronizes on <code>this</code> (the destination)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * object but does not synchronize on the source (<code>sb</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param   sb   the <tt>StringBuffer</tt> to append.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public synchronized StringBuffer append(StringBuffer sb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        super.append(sb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Appends the specified <code>CharSequence</code> to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * The characters of the <code>CharSequence</code> argument are appended,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * in order, increasing the length of this sequence by the length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <p>The result of this method is exactly the same as if it were an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * invocation of this.append(s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * <p>This method synchronizes on this (the destination)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * object but does not synchronize on the source (<code>s</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <p>If <code>s</code> is <code>null</code>, then the four characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * <code>"null"</code> are appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param   s the <code>CharSequence</code> to append.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public StringBuffer append(CharSequence s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        // Note, synchronization achieved via other invocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (s instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            return this.append((String)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (s instanceof StringBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            return this.append((StringBuffer)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return this.append(s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @since      1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public synchronized StringBuffer append(CharSequence s, int start, int end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        super.append(s, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   313
    public synchronized StringBuffer append(char[] str) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        super.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   318
    /**
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   319
     * @throws IndexOutOfBoundsException {@inheritDoc}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   320
     */
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   321
    public synchronized StringBuffer append(char[] str, int offset, int len) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        super.append(str, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public synchronized StringBuffer append(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        super.append(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public synchronized StringBuffer append(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        super.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public synchronized StringBuffer append(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        super.append(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public synchronized StringBuffer appendCodePoint(int codePoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        super.appendCodePoint(codePoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public synchronized StringBuffer append(long lng) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        super.append(lng);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public synchronized StringBuffer append(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        super.append(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public synchronized StringBuffer append(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        super.append(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public synchronized StringBuffer delete(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        super.delete(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public synchronized StringBuffer deleteCharAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        super.deleteCharAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public synchronized StringBuffer replace(int start, int end, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        super.replace(start, end, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public synchronized String substring(int start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return substring(start, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public synchronized CharSequence subSequence(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return super.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public synchronized String substring(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        return super.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   419
    public synchronized StringBuffer insert(int index, char[] str, int offset,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                                            int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        super.insert(index, str, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public synchronized StringBuffer insert(int offset, Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        super.insert(offset, String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public synchronized StringBuffer insert(int offset, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        super.insert(offset, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   445
    public synchronized StringBuffer insert(int offset, char[] str) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        super.insert(offset, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @since      1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public StringBuffer insert(int dstOffset, CharSequence s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        // Note, synchronization achieved via other invocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (s instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            return this.insert(dstOffset, (String)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return this.insert(dstOffset, s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @since      1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public synchronized StringBuffer insert(int dstOffset, CharSequence s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                            int start, int end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        super.insert(dstOffset, s, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    public StringBuffer insert(int offset, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return insert(offset, String.valueOf(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    public synchronized StringBuffer insert(int offset, char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        super.insert(offset, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public StringBuffer insert(int offset, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        return insert(offset, String.valueOf(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public StringBuffer insert(int offset, long l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        return insert(offset, String.valueOf(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public StringBuffer insert(int offset, float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return insert(offset, String.valueOf(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public StringBuffer insert(int offset, double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        return insert(offset, String.valueOf(d));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    public int indexOf(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        return indexOf(str, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public synchronized int indexOf(String str, int fromIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return String.indexOf(value, 0, count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                              str.toCharArray(), 0, str.length(), fromIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public int lastIndexOf(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        // Note, synchronization achieved via other invocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        return lastIndexOf(str, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    public synchronized int lastIndexOf(String str, int fromIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return String.lastIndexOf(value, 0, count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                              str.toCharArray(), 0, str.length(), fromIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @since   JDK1.0.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    public synchronized StringBuffer reverse() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        super.reverse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public synchronized String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return new String(value, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Serializable fields for StringBuffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @serialField value  char[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     *              The backing character array of this StringBuffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * @serialField count int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     *              The number of characters in this StringBuffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * @serialField shared  boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *              A flag indicating whether the backing array is shared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     *              The value is ignored upon deserialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    private static final java.io.ObjectStreamField[] serialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        new java.io.ObjectStreamField("value", char[].class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        new java.io.ObjectStreamField("count", Integer.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        new java.io.ObjectStreamField("shared", Boolean.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * readObject is called to restore the state of the StringBuffer from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    private synchronized void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        java.io.ObjectOutputStream.PutField fields = s.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        fields.put("value", value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        fields.put("count", count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        fields.put("shared", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        s.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * readObject is called to restore the state of the StringBuffer from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        throws java.io.IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        java.io.ObjectInputStream.GetField fields = s.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        value = (char[])fields.get("value", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        count = fields.get("count", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
}