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