jdk/src/share/classes/java/lang/AbstractStringBuilder.java
author martin
Thu, 13 May 2010 21:56:13 -0700
changeset 5603 682e3deac7ce
parent 5466 f130bb07764b
child 5627 e636ac7a63a4
permissions -rw-r--r--
6952330: Fix for 6933217 broke contract of StringBuffer.ensureCapacity Summary: make sure to grow with size => size * 2 + 2 Reviewed-by: dholmes, chegar, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1247
b4c26443dee5 6754988: Update copyright year
xdono
parents: 1223
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
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
import sun.misc.FloatingDecimal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * A mutable sequence of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Implements a modifiable string. At any point in time it contains some
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * particular sequence of characters, but the length and content of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * sequence can be changed through certain method calls.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author      Michael McCloskey
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
    39
 * @author      Martin Buchholz
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
    40
 * @author      Ulf Zibis
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @since       1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
abstract class AbstractStringBuilder implements Appendable, CharSequence {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * The value is used for character storage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
    47
    char[] value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * The count is the number of characters used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * This no-arg constructor is necessary for serialization of subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    AbstractStringBuilder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Creates an AbstractStringBuilder of the specified capacity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    AbstractStringBuilder(int capacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        value = new char[capacity];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Returns the length (character count).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @return  the length of the sequence of characters currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *          represented by this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public int length() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        return count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Returns the current capacity. The capacity is the amount of storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * available for newly inserted characters, beyond which an allocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * will occur.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @return  the current capacity
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public int capacity() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        return value.length;
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
     * Ensures that the capacity is at least equal to the specified minimum.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * If the current capacity is less than the argument, then a new internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * array is allocated with greater capacity. The new capacity is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * larger of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <li>The <code>minimumCapacity</code> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <li>Twice the old capacity, plus <code>2</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * If the <code>minimumCapacity</code> argument is nonpositive, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * method takes no action and simply returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @param   minimumCapacity   the minimum desired capacity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public void ensureCapacity(int minimumCapacity) {
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   103
        ensureCapacityInternal(minimumCapacity);
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   104
    }
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   105
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   106
    /**
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   107
     * This method has the same contract as ensureCapacity, but is
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   108
     * never synchronized.
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   109
     */
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   110
    private void ensureCapacityInternal(int minimumCapacity) {
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   111
        if (minimumCapacity - value.length > 0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            expandCapacity(minimumCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * This implements the expansion semantics of ensureCapacity with no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * size check or synchronization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    void expandCapacity(int minimumCapacity) {
5603
682e3deac7ce 6952330: Fix for 6933217 broke contract of StringBuffer.ensureCapacity
martin
parents: 5466
diff changeset
   120
        int newCapacity = value.length * 2 + 2;
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   121
        if (newCapacity - minimumCapacity < 0)
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   122
            newCapacity = minimumCapacity;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (newCapacity < 0) {
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   124
            if (minimumCapacity < 0) // overflow
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   125
                throw new OutOfMemoryError();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            newCapacity = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        value = Arrays.copyOf(value, newCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Attempts to reduce storage used for the character sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * If the buffer is larger than necessary to hold its current sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * characters, then it may be resized to become more space efficient.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Calling this method may, but is not required to, affect the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * returned by a subsequent call to the {@link #capacity()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void trimToSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (count < value.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            value = Arrays.copyOf(value, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Sets the length of the character sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * The sequence is changed to a new character sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * whose length is specified by the argument. For every nonnegative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * index <i>k</i> less than <code>newLength</code>, the character at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * index <i>k</i> in the new character sequence is the same as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * character at index <i>k</i> in the old sequence if <i>k</i> is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * than the length of the old character sequence; otherwise, it is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * null character <code>'&#92;u0000'</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * In other words, if the <code>newLength</code> argument is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * the current length, the length is changed to the specified length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * If the <code>newLength</code> argument is greater than or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * to the current length, sufficient null characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * (<code>'&#92;u0000'</code>) are appended so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * length becomes the <code>newLength</code> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * The <code>newLength</code> argument must be greater than or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * to <code>0</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param      newLength   the new length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws     IndexOutOfBoundsException  if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *               <code>newLength</code> argument is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public void setLength(int newLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (newLength < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            throw new StringIndexOutOfBoundsException(newLength);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   172
        ensureCapacityInternal(newLength);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (count < newLength) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            for (; count < newLength; count++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                value[count] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            count = newLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Returns the <code>char</code> value in this sequence at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * The first <code>char</code> value is at index <code>0</code>, the next at index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * <code>1</code>, and so on, as in array indexing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * The index argument must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * <code>0</code>, and less than the length of this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <p>If the <code>char</code> value specified by the index is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * <a href="Character.html#unicode">surrogate</a>, the surrogate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param      index   the index of the desired <code>char</code> value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @return     the <code>char</code> value at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @throws     IndexOutOfBoundsException  if <code>index</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *             negative or greater than or equal to <code>length()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public char charAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if ((index < 0) || (index >= count))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            throw new StringIndexOutOfBoundsException(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return value[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Returns the character (Unicode code point) at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * index. The index refers to <code>char</code> values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * (Unicode code units) and ranges from <code>0</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * {@link #length()}<code> - 1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <p> If the <code>char</code> value specified at the given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * is in the high-surrogate range, the following index is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * than the length of this sequence, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * <code>char</code> value at the following index is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * low-surrogate range, then the supplementary code point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * corresponding to this surrogate pair is returned. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * the <code>char</code> value at the given index is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param      index the index to the <code>char</code> values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return     the code point value of the character at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *             <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @exception  IndexOutOfBoundsException  if the <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *             argument is negative or not less than the length of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *             sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public int codePointAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if ((index < 0) || (index >= count)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            throw new StringIndexOutOfBoundsException(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return Character.codePointAt(value, index);
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
     * Returns the character (Unicode code point) before the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * index. The index refers to <code>char</code> values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * (Unicode code units) and ranges from <code>1</code> to {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * #length()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <p> If the <code>char</code> value at <code>(index - 1)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * is in the low-surrogate range, <code>(index - 2)</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * negative, and the <code>char</code> value at <code>(index -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * 2)</code> is in the high-surrogate range, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * supplementary code point value of the surrogate pair is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * returned. If the <code>char</code> value at <code>index -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * 1</code> is an unpaired low-surrogate or a high-surrogate, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * surrogate value is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param     index the index following the code point that should be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @return    the Unicode code point value before the given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @exception IndexOutOfBoundsException if the <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *            argument is less than 1 or greater than the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *            of this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public int codePointBefore(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        int i = index - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if ((i < 0) || (i >= count)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            throw new StringIndexOutOfBoundsException(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return Character.codePointBefore(value, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Returns the number of Unicode code points in the specified text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * range of this sequence. The text range begins at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * <code>beginIndex</code> and extends to the <code>char</code> at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * index <code>endIndex - 1</code>. Thus the length (in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <code>char</code>s) of the text range is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <code>endIndex-beginIndex</code>. Unpaired surrogates within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * this sequence count as one code point each.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @param beginIndex the index to the first <code>char</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * the text range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @param endIndex the index after the last <code>char</code> of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * the text range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return the number of Unicode code points in the specified text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @exception IndexOutOfBoundsException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <code>beginIndex</code> is negative, or <code>endIndex</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * is larger than the length of this sequence, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * <code>beginIndex</code> is larger than <code>endIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    public int codePointCount(int beginIndex, int endIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        if (beginIndex < 0 || endIndex > count || beginIndex > endIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return Character.codePointCountImpl(value, beginIndex, endIndex-beginIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Returns the index within this sequence that is offset from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * given <code>index</code> by <code>codePointOffset</code> code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * points. Unpaired surrogates within the text range given by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * <code>index</code> and <code>codePointOffset</code> count as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * one code point each.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @param index the index to be offset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @param codePointOffset the offset in code points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @return the index within this sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @exception IndexOutOfBoundsException if <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *   is negative or larger then the length of this sequence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *   or if <code>codePointOffset</code> is positive and the subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *   starting with <code>index</code> has fewer than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *   <code>codePointOffset</code> code points,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *   or if <code>codePointOffset</code> is negative and the subsequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *   before <code>index</code> has fewer than the absolute value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *   <code>codePointOffset</code> code points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    public int offsetByCodePoints(int index, int codePointOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (index < 0 || index > count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            throw new IndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return Character.offsetByCodePointsImpl(value, 0, count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                                index, codePointOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Characters are copied from this sequence into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * destination character array <code>dst</code>. The first character to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * be copied is at index <code>srcBegin</code>; the last character to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * be copied is at index <code>srcEnd-1</code>. The total number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * characters to be copied is <code>srcEnd-srcBegin</code>. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * characters are copied into the subarray of <code>dst</code> starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * at index <code>dstBegin</code> and ending at index:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <p><blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * dstbegin + (srcEnd-srcBegin) - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @param      srcBegin   start copying at this offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @param      srcEnd     stop copying at this offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param      dst        the array to copy the data into.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @param      dstBegin   offset into <code>dst</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @throws     NullPointerException if <code>dst</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *             <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @throws     IndexOutOfBoundsException  if any of the following is true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *             <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *             <li><code>srcBegin</code> is negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *             <li><code>dstBegin</code> is negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *             <li>the <code>srcBegin</code> argument is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *             the <code>srcEnd</code> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *             <li><code>srcEnd</code> is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *             <code>this.length()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *             <li><code>dstBegin+srcEnd-srcBegin</code> is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *             <code>dst.length</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *             </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   346
    public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (srcBegin < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            throw new StringIndexOutOfBoundsException(srcBegin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if ((srcEnd < 0) || (srcEnd > count))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            throw new StringIndexOutOfBoundsException(srcEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (srcBegin > srcEnd)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * The character at the specified index is set to <code>ch</code>. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * sequence is altered to represent a new character sequence that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * identical to the old character sequence, except that it contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * character <code>ch</code> at position <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * The index argument must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <code>0</code>, and less than the length of this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @param      index   the index of the character to modify.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param      ch      the new character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @throws     IndexOutOfBoundsException  if <code>index</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *             negative or greater than or equal to <code>length()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public void setCharAt(int index, char ch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if ((index < 0) || (index >= count))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            throw new StringIndexOutOfBoundsException(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        value[index] = ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   378
     * Appends the string representation of the {@code Object} argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   380
     * The overall effect is exactly as if the argument were converted
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   381
     * to a string by the method {@link String#valueOf(Object)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   382
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   383
     * {@link #append(String) appended} to this character sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   385
     * @param   obj   an {@code Object}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public AbstractStringBuilder append(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return append(String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Appends the specified string to this character sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   395
     * The characters of the {@code String} argument are appended, in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * order, increasing the length of this sequence by the length of the
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   397
     * argument. If {@code str} is {@code null}, then the four
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   398
     * characters {@code "null"} are appended.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Let <i>n</i> be the length of this character sequence just prior to
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   401
     * execution of the {@code append} method. Then the character at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * index <i>k</i> in the new character sequence is equal to the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * at index <i>k</i> in the old character sequence, if <i>k</i> is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * than <i>n</i>; otherwise, it is equal to the character at index
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   405
     * <i>k-n</i> in the argument {@code str}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @param   str   a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public AbstractStringBuilder append(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (str == null) str = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        int len = str.length();
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   413
        ensureCapacityInternal(count + len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        str.getChars(0, len, value, count);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   415
        count += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    // Documentation in subclasses because of synchro difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public AbstractStringBuilder append(StringBuffer sb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (sb == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            return append("null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        int len = sb.length();
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   424
        ensureCapacityInternal(count + len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        sb.getChars(0, len, value, count);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   426
        count += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    // Documentation in subclasses because of synchro difference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public AbstractStringBuilder append(CharSequence s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (s instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            return this.append((String)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (s instanceof StringBuffer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return this.append((StringBuffer)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return this.append(s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   442
     * Appends a subsequence of the specified {@code CharSequence} to this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   445
     * Characters of the argument {@code s}, starting at
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   446
     * index {@code start}, are appended, in order, to the contents of
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   447
     * this sequence up to the (exclusive) index {@code end}. The length
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   448
     * of this sequence is increased by the value of {@code end - start}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Let <i>n</i> be the length of this character sequence just prior to
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   451
     * execution of the {@code append} method. Then the character at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * index <i>k</i> in this character sequence becomes equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * character at index <i>k</i> in this sequence, if <i>k</i> is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <i>n</i>; otherwise, it is equal to the character at index
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   455
     * <i>k+start-n</i> in the argument {@code s}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   457
     * If {@code s} is {@code null}, then this method appends
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * characters as if the s parameter was a sequence containing the four
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   459
     * characters {@code "null"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @param   s the sequence to append.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param   start   the starting index of the subsequence to be appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @param   end     the end index of the subsequence to be appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @throws     IndexOutOfBoundsException if
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   466
     *             {@code start} is negative, or
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   467
     *             {@code start} is greater than {@code end} or
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   468
     *             {@code end} is greater than {@code s.length()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public AbstractStringBuilder append(CharSequence s, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            throw new IndexOutOfBoundsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                "start " + start + ", end " + end + ", s.length() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                + s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        int len = end - start;
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   478
        ensureCapacityInternal(count + len);
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   479
        for (int i = start, j = count; i < end; i++, j++)
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   480
            value[j] = s.charAt(i);
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   481
        count += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   486
     * Appends the string representation of the {@code char} array
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * argument to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * The characters of the array argument are appended, in order, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * the contents of this sequence. The length of this sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * increases by the length of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   493
     * The overall effect is exactly as if the argument were converted
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   494
     * to a string by the method {@link String#valueOf(char[])},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   495
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   496
     * {@link #append(String) appended} to this character sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @param   str   the characters to be appended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     */
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   501
    public AbstractStringBuilder append(char[] str) {
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   502
        int len = str.length;
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   503
        ensureCapacityInternal(count + len);
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   504
        System.arraycopy(str, 0, value, count, len);
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   505
        count += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return this;
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
     * Appends the string representation of a subarray of the
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   511
     * {@code char} array argument to this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   513
     * Characters of the {@code char} array {@code str}, starting at
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   514
     * index {@code offset}, are appended, in order, to the contents
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * of this sequence. The length of this sequence increases
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   516
     * by the value of {@code len}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   518
     * The overall effect is exactly as if the arguments were converted
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   519
     * to a string by the method {@link String#valueOf(char[],int,int)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   520
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   521
     * {@link #append(String) appended} to this character sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @param   str      the characters to be appended.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   524
     * @param   offset   the index of the first {@code char} to append.
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   525
     * @param   len      the number of {@code char}s to append.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @return  a reference to this object.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   527
     * @throws IndexOutOfBoundsException
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   528
     *         if {@code offset < 0} or {@code len < 0}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   529
     *         or {@code offset+len > str.length}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    public AbstractStringBuilder append(char str[], int offset, int len) {
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   532
        ensureCapacityInternal(count + len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        System.arraycopy(str, offset, value, count, len);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   534
        count += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   539
     * Appends the string representation of the {@code boolean}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * argument to the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   542
     * The overall effect is exactly as if the argument were converted
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   543
     * to a string by the method {@link String#valueOf(boolean)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   544
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   545
     * {@link #append(String) appended} to this character sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   547
     * @param   b   a {@code boolean}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    public AbstractStringBuilder append(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        if (b) {
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   552
            ensureCapacityInternal(count + 4);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            value[count++] = 't';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            value[count++] = 'r';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            value[count++] = 'u';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            value[count++] = 'e';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        } else {
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   558
            ensureCapacityInternal(count + 5);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            value[count++] = 'f';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            value[count++] = 'a';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            value[count++] = 'l';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            value[count++] = 's';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            value[count++] = 'e';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   569
     * Appends the string representation of the {@code char}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * argument to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * The argument is appended to the contents of this sequence.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   573
     * The length of this sequence increases by {@code 1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   575
     * The overall effect is exactly as if the argument were converted
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   576
     * to a string by the method {@link String#valueOf(char)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   577
     * and the character in that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   578
     * {@link #append(String) appended} to this character sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   580
     * @param   c   a {@code char}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    public AbstractStringBuilder append(char c) {
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   584
        ensureCapacityInternal(count + 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        value[count++] = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   590
     * Appends the string representation of the {@code int}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * argument to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   593
     * The overall effect is exactly as if the argument were converted
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   594
     * to a string by the method {@link String#valueOf(int)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   595
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   596
     * {@link #append(String) appended} to this character sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   598
     * @param   i   an {@code int}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    public AbstractStringBuilder append(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        if (i == Integer.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            append("-2147483648");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        int appendedLength = (i < 0) ? Integer.stringSize(-i) + 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                                     : Integer.stringSize(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        int spaceNeeded = count + appendedLength;
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   609
        ensureCapacityInternal(spaceNeeded);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        Integer.getChars(i, spaceNeeded, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        count = spaceNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   616
     * Appends the string representation of the {@code long}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * argument to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   619
     * The overall effect is exactly as if the argument were converted
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   620
     * to a string by the method {@link String#valueOf(long)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   621
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   622
     * {@link #append(String) appended} to this character sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     *
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   624
     * @param   l   a {@code long}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    public AbstractStringBuilder append(long l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        if (l == Long.MIN_VALUE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            append("-9223372036854775808");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                     : Long.stringSize(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        int spaceNeeded = count + appendedLength;
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   635
        ensureCapacityInternal(spaceNeeded);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        Long.getChars(l, spaceNeeded, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        count = spaceNeeded;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   642
     * Appends the string representation of the {@code float}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * argument to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   645
     * The overall effect is exactly as if the argument were converted
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   646
     * to a string by the method {@link String#valueOf(float)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   647
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   648
     * {@link #append(String) appended} to this character sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   650
     * @param   f   a {@code float}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    public AbstractStringBuilder append(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        new FloatingDecimal(f).appendTo(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   659
     * Appends the string representation of the {@code double}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * argument to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   662
     * The overall effect is exactly as if the argument were converted
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   663
     * to a string by the method {@link String#valueOf(double)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   664
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   665
     * {@link #append(String) appended} to this character sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   667
     * @param   d   a {@code double}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    public AbstractStringBuilder append(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        new FloatingDecimal(d).appendTo(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * Removes the characters in a substring of this sequence.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   677
     * The substring begins at the specified {@code start} and extends to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   678
     * the character at index {@code end - 1} or to the end of the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * sequence if no such character exists. If
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   680
     * {@code start} is equal to {@code end}, no changes are made.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @param      start  The beginning index, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @param      end    The ending index, exclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @return     This object.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   685
     * @throws     StringIndexOutOfBoundsException  if {@code start}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   686
     *             is negative, greater than {@code length()}, or
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   687
     *             greater than {@code end}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    public AbstractStringBuilder delete(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        if (start < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            throw new StringIndexOutOfBoundsException(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        if (end > count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            end = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        if (start > end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            throw new StringIndexOutOfBoundsException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        int len = end - start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        if (len > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            System.arraycopy(value, start+len, value, start, count-end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            count -= len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   705
     * Appends the string representation of the {@code codePoint}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * argument to this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * <p> The argument is appended to the contents of this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * The length of this sequence increases by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * {@link Character#charCount(int) Character.charCount(codePoint)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * <p> The overall effect is exactly as if the argument were
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   713
     * converted to a {@code char} array by the method
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   714
     * {@link Character#toChars(int)} and the character in that array
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   715
     * were then {@link #append(char[]) appended} to this character
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @param   codePoint   a Unicode code point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * @exception IllegalArgumentException if the specified
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   721
     * {@code codePoint} isn't a valid Unicode code point
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    public AbstractStringBuilder appendCodePoint(int codePoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        if (!Character.isValidCodePoint(codePoint)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        int n = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if (codePoint >= Character.MIN_SUPPLEMENTARY_CODE_POINT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            n++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   731
        ensureCapacityInternal(count + n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        if (n == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            value[count++] = (char) codePoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            Character.toSurrogates(codePoint, value, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            count += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * Removes the <code>char</code> at the specified position in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * sequence. This sequence is shortened by one <code>char</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * <p>Note: If the character at the given index is a supplementary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * character, this method does not remove the entire character. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * correct handling of supplementary characters is required,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * determine the number of <code>char</code>s to remove by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * <code>Character.charCount(thisSequence.codePointAt(index))</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * where <code>thisSequence</code> is this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @param       index  Index of <code>char</code> to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * @return      This object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * @throws      StringIndexOutOfBoundsException  if the <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     *              is negative or greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     *              <code>length()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    public AbstractStringBuilder deleteCharAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        if ((index < 0) || (index >= count))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            throw new StringIndexOutOfBoundsException(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        System.arraycopy(value, index+1, value, index, count-index-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        count--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * Replaces the characters in a substring of this sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * with characters in the specified <code>String</code>. The substring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * begins at the specified <code>start</code> and extends to the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * at index <code>end - 1</code> or to the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * sequence if no such character exists. First the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * characters in the substring are removed and then the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * <code>String</code> is inserted at <code>start</code>. (This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * sequence will be lengthened to accommodate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * specified String if necessary.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * @param      start    The beginning index, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @param      end      The ending index, exclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @param      str   String that will replace previous contents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @return     This object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     *             is negative, greater than <code>length()</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *             greater than <code>end</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    public AbstractStringBuilder replace(int start, int end, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        if (start < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            throw new StringIndexOutOfBoundsException(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if (start > count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            throw new StringIndexOutOfBoundsException("start > length()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        if (start > end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            throw new StringIndexOutOfBoundsException("start > end");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        if (end > count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            end = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        int len = str.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        int newCount = count + len - (end - start);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   797
        ensureCapacityInternal(newCount);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        System.arraycopy(value, end, value, start + len, count - end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        str.getChars(value, start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        count = newCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * Returns a new <code>String</code> that contains a subsequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * characters currently contained in this character sequence. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * substring begins at the specified index and extends to the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @param      start    The beginning index, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @return     The new string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * @throws     StringIndexOutOfBoundsException  if <code>start</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     *             less than zero, or greater than the length of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    public String substring(int start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        return substring(start, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * Returns a new character sequence that is a subsequence of this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * <p> An invocation of this method of the form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * sb.subSequence(begin,&nbsp;end)</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * behaves in exactly the same way as the invocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * sb.substring(begin,&nbsp;end)</pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * This method is provided so that this class can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * implement the {@link CharSequence} interface. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * @param      start   the start index, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * @param      end     the end index, exclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * @return     the specified subsequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * @throws  IndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     *          if <tt>start</tt> or <tt>end</tt> are negative,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     *          if <tt>end</tt> is greater than <tt>length()</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     *          or if <tt>start</tt> is greater than <tt>end</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * @spec JSR-51
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    public CharSequence subSequence(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        return substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * Returns a new <code>String</code> that contains a subsequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * characters currently contained in this sequence. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * substring begins at the specified <code>start</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * extends to the character at index <code>end - 1</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @param      start    The beginning index, inclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @param      end      The ending index, exclusive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @return     The new string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @throws     StringIndexOutOfBoundsException  if <code>start</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     *             or <code>end</code> are negative or greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     *             <code>length()</code>, or <code>start</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *             greater than <code>end</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    public String substring(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        if (start < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            throw new StringIndexOutOfBoundsException(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        if (end > count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            throw new StringIndexOutOfBoundsException(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        if (start > end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            throw new StringIndexOutOfBoundsException(end - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        return new String(value, start, end - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   875
     * Inserts the string representation of a subarray of the {@code str}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * array argument into this sequence. The subarray begins at the
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   877
     * specified {@code offset} and extends {@code len} {@code char}s.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * The characters of the subarray are inserted into this sequence at
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   879
     * the position indicated by {@code index}. The length of this
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   880
     * sequence increases by {@code len} {@code char}s.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @param      index    position at which to insert subarray.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   883
     * @param      str       A {@code char} array.
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   884
     * @param      offset   the index of the first {@code char} in subarray to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *             be inserted.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   886
     * @param      len      the number of {@code char}s in the subarray to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *             be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @return     This object
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   889
     * @throws     StringIndexOutOfBoundsException  if {@code index}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   890
     *             is negative or greater than {@code length()}, or
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   891
     *             {@code offset} or {@code len} are negative, or
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   892
     *             {@code (offset+len)} is greater than
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   893
     *             {@code str.length}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     */
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   895
    public AbstractStringBuilder insert(int index, char[] str, int offset,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                                        int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        if ((index < 0) || (index > length()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            throw new StringIndexOutOfBoundsException(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        if ((offset < 0) || (len < 0) || (offset > str.length - len))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            throw new StringIndexOutOfBoundsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                "offset " + offset + ", len " + len + ", str.length "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                + str.length);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   904
        ensureCapacityInternal(count + len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        System.arraycopy(value, index, value, index + len, count - index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        System.arraycopy(str, offset, value, index, len);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   907
        count += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   912
     * Inserts the string representation of the {@code Object}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * argument into this character sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   915
     * The overall effect is exactly as if the second argument were
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   916
     * converted to a string by the method {@link String#valueOf(Object)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   917
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   918
     * {@link #insert(int,String) inserted} into this character
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   919
     * sequence at the indicated offset.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   921
     * The {@code offset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   922
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   923
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * @param      offset   the offset.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   926
     * @param      obj      an {@code Object}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    public AbstractStringBuilder insert(int offset, Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        return insert(offset, String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * Inserts the string into this character sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   937
     * The characters of the {@code String} argument are inserted, in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * order, into this sequence at the indicated offset, moving up any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * characters originally above that position and increasing the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * of this sequence by the length of the argument. If
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   941
     * {@code str} is {@code null}, then the four characters
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   942
     * {@code "null"} are inserted into this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * The character at index <i>k</i> in the new character sequence is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * equal to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * <li>the character at index <i>k</i> in the old character sequence, if
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   948
     * <i>k</i> is less than {@code offset}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   949
     * <li>the character at index <i>k</i>{@code -offset} in the
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   950
     * argument {@code str}, if <i>k</i> is not less than
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   951
     * {@code offset} but is less than {@code offset+str.length()}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   952
     * <li>the character at index <i>k</i>{@code -str.length()} in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * old character sequence, if <i>k</i> is not less than
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   954
     * {@code offset+str.length()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * </ul><p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   956
     * The {@code offset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   957
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   958
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @param      offset   the offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @param      str      a string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    public AbstractStringBuilder insert(int offset, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        if ((offset < 0) || (offset > length()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            throw new StringIndexOutOfBoundsException(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        if (str == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            str = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        int len = str.length();
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   971
        ensureCapacityInternal(count + len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        System.arraycopy(value, offset, value, offset + len, count - offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        str.getChars(value, offset);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
   974
        count += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   979
     * Inserts the string representation of the {@code char} array
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * argument into this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * The characters of the array argument are inserted into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * contents of this sequence at the position indicated by
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   984
     * {@code offset}. The length of this sequence increases by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * the length of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   987
     * The overall effect is exactly as if the second argument were
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   988
     * converted to a string by the method {@link String#valueOf(char[])},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   989
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   990
     * {@link #insert(int,String) inserted} into this character
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   991
     * sequence at the indicated offset.
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   992
     * <p>
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   993
     * The {@code offset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   994
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   995
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * @param      offset   the offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * @param      str      a character array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     */
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1002
    public AbstractStringBuilder insert(int offset, char[] str) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        if ((offset < 0) || (offset > length()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            throw new StringIndexOutOfBoundsException(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        int len = str.length;
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
  1006
        ensureCapacityInternal(count + len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        System.arraycopy(value, offset, value, offset + len, count - offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        System.arraycopy(str, 0, value, offset, len);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
  1009
        count += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1014
     * Inserts the specified {@code CharSequence} into this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1016
     * The characters of the {@code CharSequence} argument are inserted,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * in order, into this sequence at the indicated offset, moving up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * any characters originally above that position and increasing the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * of this sequence by the length of the argument s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * The result of this method is exactly the same as if it were an
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1022
     * invocation of this object's
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1023
     * {@link #insert(int,CharSequence,int,int) insert}(dstOffset, s, 0, s.length())
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1024
     * method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     *
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1026
     * <p>If {@code s} is {@code null}, then the four characters
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1027
     * {@code "null"} are inserted into this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * @param      dstOffset   the offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @param      s the sequence to be inserted
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * @throws     IndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    public AbstractStringBuilder insert(int dstOffset, CharSequence s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        if (s instanceof String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            return this.insert(dstOffset, (String)s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        return this.insert(dstOffset, s, 0, s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1043
     * Inserts a subsequence of the specified {@code CharSequence} into
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1046
     * The subsequence of the argument {@code s} specified by
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1047
     * {@code start} and {@code end} are inserted,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * in order, into this sequence at the specified destination offset, moving
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * up any characters originally above that position. The length of this
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1050
     * sequence is increased by {@code end - start}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * The character at index <i>k</i> in this sequence becomes equal to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * <li>the character at index <i>k</i> in this sequence, if
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1055
     * <i>k</i> is less than {@code dstOffset}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1056
     * <li>the character at index <i>k</i>{@code +start-dstOffset} in
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1057
     * the argument {@code s}, if <i>k</i> is greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1058
     * {@code dstOffset} but is less than {@code dstOffset+end-start}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1059
     * <li>the character at index <i>k</i>{@code -(end-start)} in this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * sequence, if <i>k</i> is greater than or equal to
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1061
     * {@code dstOffset+end-start}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * </ul><p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1063
     * The {@code dstOffset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1064
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1065
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * <p>The start argument must be nonnegative, and not greater than
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1067
     * {@code end}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * <p>The end argument must be greater than or equal to
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1069
     * {@code start}, and less than or equal to the length of s.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     *
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1071
     * <p>If {@code s} is {@code null}, then this method inserts
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * characters as if the s parameter was a sequence containing the four
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1073
     * characters {@code "null"}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @param      dstOffset   the offset in this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * @param      s       the sequence to be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @param      start   the starting index of the subsequence to be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * @param      end     the end index of the subsequence to be inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * @return     a reference to this object.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1080
     * @throws     IndexOutOfBoundsException  if {@code dstOffset}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1081
     *             is negative or greater than {@code this.length()}, or
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1082
     *              {@code start} or {@code end} are negative, or
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1083
     *              {@code start} is greater than {@code end} or
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1084
     *              {@code end} is greater than {@code s.length()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     public AbstractStringBuilder insert(int dstOffset, CharSequence s,
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1087
                                         int start, int end) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        if (s == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            s = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        if ((dstOffset < 0) || (dstOffset > this.length()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            throw new IndexOutOfBoundsException("dstOffset "+dstOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        if ((start < 0) || (end < 0) || (start > end) || (end > s.length()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            throw new IndexOutOfBoundsException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                "start " + start + ", end " + end + ", s.length() "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                + s.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        int len = end - start;
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
  1097
        ensureCapacityInternal(count + len);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        System.arraycopy(value, dstOffset, value, dstOffset + len,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                         count - dstOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        for (int i=start; i<end; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            value[dstOffset++] = s.charAt(i);
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
  1102
        count += len;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1107
     * Inserts the string representation of the {@code boolean}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * argument into this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1110
     * The overall effect is exactly as if the second argument were
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1111
     * converted to a string by the method {@link String#valueOf(boolean)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1112
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1113
     * {@link #insert(int,String) inserted} into this character
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1114
     * sequence at the indicated offset.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1116
     * The {@code offset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1117
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1118
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * @param      offset   the offset.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1121
     * @param      b        a {@code boolean}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
    public AbstractStringBuilder insert(int offset, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        return insert(offset, String.valueOf(b));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1130
     * Inserts the string representation of the {@code char}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * argument into this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1133
     * The overall effect is exactly as if the second argument were
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1134
     * converted to a string by the method {@link String#valueOf(char)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1135
     * and the character in that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1136
     * {@link #insert(int,String) inserted} into this character
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1137
     * sequence at the indicated offset.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1139
     * The {@code offset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1140
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1141
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * @param      offset   the offset.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1144
     * @param      c        a {@code char}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * @throws     IndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    public AbstractStringBuilder insert(int offset, char c) {
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
  1149
        ensureCapacityInternal(count + 1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        System.arraycopy(value, offset, value, offset + 1, count - offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        value[offset] = c;
5466
f130bb07764b 6933217: Huge arrays handled poorly in core libraries
martin
parents: 1247
diff changeset
  1152
        count += 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1157
     * Inserts the string representation of the second {@code int}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * argument into this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1160
     * The overall effect is exactly as if the second argument were
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1161
     * converted to a string by the method {@link String#valueOf(int)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1162
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1163
     * {@link #insert(int,String) inserted} into this character
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1164
     * sequence at the indicated offset.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1166
     * The {@code offset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1167
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1168
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * @param      offset   the offset.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1171
     * @param      i        an {@code int}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
    public AbstractStringBuilder insert(int offset, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        return insert(offset, String.valueOf(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1180
     * Inserts the string representation of the {@code long}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * argument into this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1183
     * The overall effect is exactly as if the second argument were
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1184
     * converted to a string by the method {@link String#valueOf(long)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1185
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1186
     * {@link #insert(int,String) inserted} into this character
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1187
     * sequence at the indicated offset.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1189
     * The {@code offset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1190
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1191
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @param      offset   the offset.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1194
     * @param      l        a {@code long}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    public AbstractStringBuilder insert(int offset, long l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        return insert(offset, String.valueOf(l));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1203
     * Inserts the string representation of the {@code float}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * argument into this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1206
     * The overall effect is exactly as if the second argument were
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1207
     * converted to a string by the method {@link String#valueOf(float)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1208
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1209
     * {@link #insert(int,String) inserted} into this character
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1210
     * sequence at the indicated offset.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1212
     * The {@code offset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1213
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1214
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * @param      offset   the offset.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1217
     * @param      f        a {@code float}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    public AbstractStringBuilder insert(int offset, float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        return insert(offset, String.valueOf(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    /**
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1226
     * Inserts the string representation of the {@code double}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * argument into this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1229
     * The overall effect is exactly as if the second argument were
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1230
     * converted to a string by the method {@link String#valueOf(double)},
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1231
     * and the characters of that string were then
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1232
     * {@link #insert(int,String) inserted} into this character
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1233
     * sequence at the indicated offset.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * <p>
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1235
     * The {@code offset} argument must be greater than or equal to
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1236
     * {@code 0}, and less than or equal to the {@linkplain #length() length}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1237
     * of this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * @param      offset   the offset.
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
  1240
     * @param      d        a {@code double}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * @return     a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @throws     StringIndexOutOfBoundsException  if the offset is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    public AbstractStringBuilder insert(int offset, double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        return insert(offset, String.valueOf(d));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * Returns the index within this string of the first occurrence of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * specified substring. The integer returned is the smallest value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * <i>k</i> such that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * this.toString().startsWith(str, <i>k</i>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * is <code>true</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * @param   str   any string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * @return  if the string argument occurs as a substring within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     *          object, then the index of the first character of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     *          such substring is returned; if it does not occur as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     *          substring, <code>-1</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * @throws  java.lang.NullPointerException if <code>str</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     *          <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    public int indexOf(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        return indexOf(str, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * Returns the index within this string of the first occurrence of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * specified substring, starting at the specified index.  The integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * returned is the smallest value <tt>k</tt> for which:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     *     k >= Math.min(fromIndex, str.length()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     *                   this.toString().startsWith(str, k)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * If no such value of <i>k</i> exists, then -1 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * @param   str         the substring for which to search.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * @param   fromIndex   the index from which to start the search.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * @return  the index within this string of the first occurrence of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     *          specified substring, starting at the specified index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * @throws  java.lang.NullPointerException if <code>str</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     *            <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    public int indexOf(String str, int fromIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        return String.indexOf(value, 0, count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                              str.toCharArray(), 0, str.length(), fromIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * Returns the index within this string of the rightmost occurrence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * of the specified substring.  The rightmost empty string "" is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * considered to occur at the index value <code>this.length()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * The returned index is the largest value <i>k</i> such that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * this.toString().startsWith(str, k)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * is true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * @param   str   the substring to search for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * @return  if the string argument occurs one or more times as a substring
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     *          within this object, then the index of the first character of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     *          the last such substring is returned. If it does not occur as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     *          a substring, <code>-1</code> is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @throws  java.lang.NullPointerException  if <code>str</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     *          <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    public int lastIndexOf(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        return lastIndexOf(str, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * Returns the index within this string of the last occurrence of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * specified substring. The integer returned is the largest value <i>k</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * such that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * <blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     *     k <= Math.min(fromIndex, str.length()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     *                   this.toString().startsWith(str, k)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * If no such value of <i>k</i> exists, then -1 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * @param   str         the substring to search for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * @param   fromIndex   the index to start the search from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * @return  the index within this sequence of the last occurrence of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     *          specified substring.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * @throws  java.lang.NullPointerException if <code>str</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     *          <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
    public int lastIndexOf(String str, int fromIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        return String.lastIndexOf(value, 0, count,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                              str.toCharArray(), 0, str.length(), fromIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * Causes this character sequence to be replaced by the reverse of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * the sequence. If there are any surrogate pairs included in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     * sequence, these are treated as single characters for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * reverse operation. Thus, the order of the high-low surrogates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * is never reversed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * Let <i>n</i> be the character length of this character sequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * (not the length in <code>char</code> values) just prior to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * execution of the <code>reverse</code> method. Then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * character at index <i>k</i> in the new character sequence is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * equal to the character at index <i>n-k-1</i> in the old
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * character sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * <p>Note that the reverse operation may result in producing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * surrogate pairs that were unpaired low-surrogates and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * high-surrogates before the operation. For example, reversing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * "&#92;uDC00&#92;uD800" produces "&#92;uD800&#92;uDC00" which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * a valid surrogate pair.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    public AbstractStringBuilder reverse() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        boolean hasSurrogate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        int n = count - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        for (int j = (n-1) >> 1; j >= 0; --j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            char temp = value[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            char temp2 = value[n - j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            if (!hasSurrogate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                hasSurrogate = (temp >= Character.MIN_SURROGATE && temp <= Character.MAX_SURROGATE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                    || (temp2 >= Character.MIN_SURROGATE && temp2 <= Character.MAX_SURROGATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            value[j] = temp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
            value[n - j] = temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        if (hasSurrogate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            // Reverse back all valid surrogate pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            for (int i = 0; i < count - 1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                char c2 = value[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                if (Character.isLowSurrogate(c2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                    char c1 = value[i + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                    if (Character.isHighSurrogate(c1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                        value[i++] = c1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                        value[i] = c2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * Returns a string representing the data in this sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * A new <code>String</code> object is allocated and initialized to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * contain the character sequence currently represented by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * object. This <code>String</code> is then returned. Subsequent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * changes to this sequence do not affect the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * <code>String</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * @return  a string representation of this sequence of characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    public abstract String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     * Needed by <tt>String</tt> for the contentEquals method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
    final char[] getValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
}