jdk/src/share/classes/java/lang/StringBuilder.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 2003-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 mutable sequence of characters.  This class provides an API compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * with <code>StringBuffer</code>, but with no guarantee of synchronization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This class is designed for use as a drop-in replacement for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <code>StringBuffer</code> in places where the string buffer was being
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * used by a single thread (as is generally the case).   Where possible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * it is recommended that this class be used in preference to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <code>StringBuffer</code> as it will be faster under most implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>The principal operations on a <code>StringBuilder</code> are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <code>append</code> and <code>insert</code> methods, which are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * overloaded so as to accept data of any type. Each effectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * converts a given datum to a string and then appends or inserts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * characters of that string to the string builder. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>append</code> method always adds these characters at the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * of the builder; the <code>insert</code> method adds the characters at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * a specified point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * For example, if <code>z</code> refers to a string builder object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * whose current contents are "<code>start</code>", then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * the method call <code>z.append("le")</code> would cause the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * builder to contain "<code>startle</code>", whereas
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>z.insert(4, "le")</code> would alter the string builder to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * contain "<code>starlet</code>".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * In general, if sb refers to an instance of a <code>StringBuilder</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * then <code>sb.append(x)</code> has the same effect as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <code>sb.insert(sb.length(),&nbsp;x)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Every string builder has a capacity. As long as the length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * character sequence contained in the string builder does not exceed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * the capacity, it is not necessary to allocate a new internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * buffer. If the internal buffer overflows, it is automatically made larger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>Instances of <code>StringBuilder</code> are not safe for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * use by multiple threads. If such synchronization is required then it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * recommended that {@link java.lang.StringBuffer} be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author      Michael McCloskey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see         java.lang.StringBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @see         java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @since       1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public final class StringBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    extends AbstractStringBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    implements java.io.Serializable, CharSequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /** use serialVersionUID for interoperability */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static final long serialVersionUID = 4383685877147921099L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Constructs a string builder with no characters in it and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * initial capacity of 16 characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public StringBuilder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        super(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Constructs a string builder with no characters in it and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * initial capacity specified by the <code>capacity</code> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param      capacity  the initial capacity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @throws     NegativeArraySizeException  if the <code>capacity</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *               argument is less than <code>0</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public StringBuilder(int capacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        super(capacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Constructs a string builder initialized to the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * specified string. The initial capacity of the string builder is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <code>16</code> plus the length of the string argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param   str   the initial contents of the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @throws    NullPointerException if <code>str</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public StringBuilder(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        super(str.length() + 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Constructs a string builder that contains the same characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * as the specified <code>CharSequence</code>. The initial capacity of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * the string builder is <code>16</code> plus the length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <code>CharSequence</code> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param      seq   the sequence to copy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @throws    NullPointerException if <code>seq</code> is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public StringBuilder(CharSequence seq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this(seq.length() + 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        append(seq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @see     java.lang.String#valueOf(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public StringBuilder append(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return append(String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public StringBuilder append(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        super.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    // Appends the specified string builder to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private StringBuilder append(StringBuilder sb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (sb == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            return append("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        int len = sb.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        int newcount = count + len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (newcount > value.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            expandCapacity(newcount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        sb.getChars(0, len, value, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        count = newcount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Appends the specified <tt>StringBuffer</tt> to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * The characters of the <tt>StringBuffer</tt> argument are appended,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * in order, to this sequence, increasing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * length of this sequence by the length of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * If <tt>sb</tt> is <tt>null</tt>, then the four characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * <tt>"null"</tt> are appended to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Let <i>n</i> be the length of this character sequence just prior to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * execution of the <tt>append</tt> method. Then the character at index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <i>k</i> in the new character sequence is equal to the character at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * index <i>k</i> in the old character sequence, if <i>k</i> is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * in the argument <code>sb</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param   sb   the <tt>StringBuffer</tt> to append.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public StringBuilder append(StringBuffer sb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        super.append(sb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public StringBuilder append(CharSequence s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (s instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            return this.append((String)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (s instanceof StringBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return this.append((StringBuffer)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (s instanceof StringBuilder)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return this.append((StringBuilder)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        return this.append(s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @throws     IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public StringBuilder append(CharSequence s, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        super.append(s, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public StringBuilder append(char str[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        super.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public StringBuilder append(char str[], int offset, int len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        super.append(str, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @see     java.lang.String#valueOf(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public StringBuilder append(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        super.append(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public StringBuilder append(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        super.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @see     java.lang.String#valueOf(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public StringBuilder append(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        super.append(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see     java.lang.String#valueOf(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public StringBuilder append(long lng) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        super.append(lng);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see     java.lang.String#valueOf(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public StringBuilder append(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        super.append(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see     java.lang.String#valueOf(double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @see     #append(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public StringBuilder append(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        super.append(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public StringBuilder appendCodePoint(int codePoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        super.appendCodePoint(codePoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public StringBuilder delete(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        super.delete(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public StringBuilder deleteCharAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        super.deleteCharAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public StringBuilder replace(int start, int end, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        super.replace(start, end, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public StringBuilder insert(int index, char str[], int offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        super.insert(index, str, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see        java.lang.String#valueOf(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public StringBuilder insert(int offset, Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return insert(offset, String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    public StringBuilder insert(int offset, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        super.insert(offset, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public StringBuilder insert(int offset, char str[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        super.insert(offset, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public StringBuilder insert(int dstOffset, CharSequence s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (s instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            return this.insert(dstOffset, (String)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return this.insert(dstOffset, s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public StringBuilder insert(int dstOffset, CharSequence s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                                int start, int end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        super.insert(dstOffset, s, start, end);
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
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @see        java.lang.String#valueOf(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public StringBuilder insert(int offset, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        super.insert(offset, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public StringBuilder insert(int offset, char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        super.insert(offset, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see        java.lang.String#valueOf(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public StringBuilder insert(int offset, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        return insert(offset, String.valueOf(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @see        java.lang.String#valueOf(long)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public StringBuilder insert(int offset, long l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return insert(offset, String.valueOf(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see        java.lang.String#valueOf(float)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public StringBuilder insert(int offset, float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return insert(offset, String.valueOf(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @see        java.lang.String#valueOf(double)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @see        #insert(int, java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see        #length()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public StringBuilder insert(int offset, double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return insert(offset, String.valueOf(d));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public int indexOf(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return indexOf(str, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public int indexOf(String str, int fromIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        return String.indexOf(value, 0, count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                              str.toCharArray(), 0, str.length(), fromIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    public int lastIndexOf(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        return lastIndexOf(str, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public int lastIndexOf(String str, int fromIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        return String.lastIndexOf(value, 0, count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                              str.toCharArray(), 0, str.length(), fromIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public StringBuilder reverse() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        super.reverse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        // Create a copy, don't share the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return new String(value, 0, count);
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
     * Save the state of the <tt>StringBuilder</tt> instance to a stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * (that is, serialize it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @serialData the number of characters currently stored in the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *             builder (<tt>int</tt>), followed by the characters in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     *             string builder (<tt>char[]</tt>).   The length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *             <tt>char</tt> array may be greater than the number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *             characters currently stored in the string builder, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *             case extra characters are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        s.writeInt(count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        s.writeObject(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * readObject is called to restore the state of the StringBuffer from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        throws java.io.IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        count = s.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        value = (char[]) s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
}