jdk/src/share/classes/java/lang/StringBuffer.java
author martin
Mon, 10 Mar 2008 14:32:51 -0700
changeset 48 dc5744ca15ea
parent 2 90ce3da70b43
child 1223 5c1037124466
permissions -rw-r--r--
4960438: (process) Need IO redirection API for subprocesses Reviewed-by: alanb, iris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1994-2004 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public synchronized void getChars(int srcBegin, int srcEnd, char dst[],
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see     java.lang.String#valueOf(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public synchronized StringBuffer append(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        super.append(String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public synchronized StringBuffer append(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        super.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Appends the specified <tt>StringBuffer</tt> to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * The characters of the <tt>StringBuffer</tt> argument are appended,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * length of this <tt>StringBuffer</tt> by the length of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Let <i>n</i> be the length of the old character sequence, the one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * contained in the <tt>StringBuffer</tt> just prior to execution of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <tt>append</tt> method. Then the character at index <i>k</i> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * the new character sequence is equal to the character at index <i>k</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * in the old character sequence, if <i>k</i> is less than <i>n</i>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * otherwise, it is equal to the character at index <i>k-n</i> in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * argument <code>sb</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * This method synchronizes on <code>this</code> (the destination)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * object but does not synchronize on the source (<code>sb</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param   sb   the <tt>StringBuffer</tt> to append.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public synchronized StringBuffer append(StringBuffer sb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        super.append(sb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * Appends the specified <code>CharSequence</code> to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * The characters of the <code>CharSequence</code> argument are appended,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * in order, increasing the length of this sequence by the length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * <p>The result of this method is exactly the same as if it were an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * invocation of this.append(s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * <p>This method synchronizes on this (the destination)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * object but does not synchronize on the source (<code>s</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * <p>If <code>s</code> is <code>null</code>, then the four characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <code>"null"</code> are appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @param   s the <code>CharSequence</code> to append.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public StringBuffer append(CharSequence s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        // Note, synchronization achieved via other invocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if (s instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return this.append((String)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        if (s instanceof StringBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            return this.append((StringBuffer)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return this.append(s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @since      1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public synchronized StringBuffer append(CharSequence s, int start, int end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        super.append(s, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public synchronized StringBuffer append(char str[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        super.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public synchronized StringBuffer append(char str[], int offset, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        super.append(str, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @see     java.lang.String#valueOf(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public synchronized StringBuffer append(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        super.append(b);
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(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        super.append(c);
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
     * @see     java.lang.String#valueOf(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public synchronized StringBuffer append(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        super.append(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public synchronized StringBuffer appendCodePoint(int codePoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        super.appendCodePoint(codePoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @see     java.lang.String#valueOf(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public synchronized StringBuffer append(long lng) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        super.append(lng);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @see     java.lang.String#valueOf(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public synchronized StringBuffer append(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        super.append(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @see     java.lang.String#valueOf(double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public synchronized StringBuffer append(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        super.append(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public synchronized StringBuffer delete(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        super.delete(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public synchronized StringBuffer deleteCharAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        super.deleteCharAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public synchronized StringBuffer replace(int start, int end, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        super.replace(start, end, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public synchronized String substring(int start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return substring(start, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public synchronized CharSequence subSequence(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        return super.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public synchronized String substring(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        return super.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public synchronized StringBuffer insert(int index, char str[], int offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                            int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        super.insert(index, str, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @see        java.lang.String#valueOf(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public synchronized StringBuffer insert(int offset, Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        super.insert(offset, String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public synchronized StringBuffer insert(int offset, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        super.insert(offset, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public synchronized StringBuffer insert(int offset, char str[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        super.insert(offset, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @since      1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public StringBuffer insert(int dstOffset, CharSequence s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        // Note, synchronization achieved via other invocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (s instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            return this.insert(dstOffset, (String)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        return this.insert(dstOffset, s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @since      1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    public synchronized StringBuffer insert(int dstOffset, CharSequence s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                                            int start, int end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        super.insert(dstOffset, s, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @see        java.lang.String#valueOf(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public StringBuffer insert(int offset, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return insert(offset, String.valueOf(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public synchronized StringBuffer insert(int offset, char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        super.insert(offset, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @see        java.lang.String#valueOf(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    public StringBuffer insert(int offset, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return insert(offset, String.valueOf(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * @see        java.lang.String#valueOf(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    public StringBuffer insert(int offset, long l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return insert(offset, String.valueOf(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @see        java.lang.String#valueOf(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    public StringBuffer insert(int offset, float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        return insert(offset, String.valueOf(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @see        java.lang.String#valueOf(double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    public StringBuffer insert(int offset, double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        return insert(offset, String.valueOf(d));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    public int indexOf(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        return indexOf(str, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public synchronized int indexOf(String str, int fromIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return String.indexOf(value, 0, count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                              str.toCharArray(), 0, str.length(), fromIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    public int lastIndexOf(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        // Note, synchronization achieved via other invocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        return lastIndexOf(str, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @since      1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    public synchronized int lastIndexOf(String str, int fromIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        return String.lastIndexOf(value, 0, count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                              str.toCharArray(), 0, str.length(), fromIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * @since   JDK1.0.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public synchronized StringBuffer reverse() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        super.reverse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    public synchronized String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        return new String(value, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Serializable fields for StringBuffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @serialField value  char[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *              The backing character array of this StringBuffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @serialField count int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     *              The number of characters in this StringBuffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @serialField shared  boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *              A flag indicating whether the backing array is shared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     *              The value is ignored upon deserialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    private static final java.io.ObjectStreamField[] serialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        new java.io.ObjectStreamField("value", char[].class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        new java.io.ObjectStreamField("count", Integer.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        new java.io.ObjectStreamField("shared", Boolean.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * readObject is called to restore the state of the StringBuffer from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    private synchronized void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        java.io.ObjectOutputStream.PutField fields = s.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        fields.put("value", value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        fields.put("count", count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        fields.put("shared", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        s.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * readObject is called to restore the state of the StringBuffer from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        throws java.io.IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        java.io.ObjectInputStream.GetField fields = s.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        value = (char[])fields.get("value", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        count = fields.get("count", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
}