jdk/src/java.base/share/classes/java/lang/StringBuilder.java
author thartmann
Tue, 03 Nov 2015 09:42:11 +0100
changeset 33663 2cd62a4bd471
parent 31671 362e0c0acece
child 34517 c6e795a80c80
permissions -rw-r--r--
8141132: JEP 254: Compact Strings Summary: Adopt a more space-efficient internal representation for strings. Reviewed-by: alanb, bdelsart, coleenp, iklam, jiangli, jrose, kevinw, naoto, pliden, roland, smarks, twisti Contributed-by: Brent Christian <brent.christian@oracle.com>, Vivek Deshpande <vivek.r.deshpande@intel.com>, Tobias Hartmann <tobias.hartmann@oracle.com>, Charlie Hunt <charlie.hunt@oracle.com>, Vladimir Kozlov <vladimir.kozlov@oracle.com>, Roger Riggs <roger.riggs@oracle.com>, Xueming Shen <xueming.shen@oracle.com>, Aleksey Shipilev <aleksey.shipilev@oracle.com>, Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 15312
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
    28
import jdk.internal.HotSpotIntrinsicCandidate;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * A mutable sequence of characters.  This class provides an API compatible
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    32
 * with {@code StringBuffer}, but with no guarantee of synchronization.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * This class is designed for use as a drop-in replacement for
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    34
 * {@code StringBuffer} in places where the string buffer was being
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * used by a single thread (as is generally the case).   Where possible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * it is recommended that this class be used in preference to
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    37
 * {@code StringBuffer} as it will be faster under most implementations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    39
 * <p>The principal operations on a {@code StringBuilder} are the
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    40
 * {@code append} and {@code insert} methods, which are
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * overloaded so as to accept data of any type. Each effectively
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * converts a given datum to a string and then appends or inserts the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * characters of that string to the string builder. The
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    44
 * {@code append} method always adds these characters at the end
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    45
 * of the builder; the {@code insert} method adds the characters at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a specified point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    48
 * For example, if {@code z} refers to a string builder object
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    49
 * whose current contents are "{@code start}", then
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    50
 * the method call {@code z.append("le")} would cause the string
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    51
 * builder to contain "{@code startle}", whereas
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    52
 * {@code z.insert(4, "le")} would alter the string builder to
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    53
 * contain "{@code starlet}".
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    55
 * In general, if sb refers to an instance of a {@code StringBuilder},
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    56
 * then {@code sb.append(x)} has the same effect as
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    57
 * {@code sb.insert(sb.length(), x)}.
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    58
 * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Every string builder has a capacity. As long as the length of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * character sequence contained in the string builder does not exceed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * the capacity, it is not necessary to allocate a new internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * buffer. If the internal buffer overflows, it is automatically made larger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    64
 * <p>Instances of {@code StringBuilder} are not safe for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * use by multiple threads. If such synchronization is required then it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * recommended that {@link java.lang.StringBuffer} be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
15312
4b57f9da8192 4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents: 14997
diff changeset
    68
 * <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
    69
 * 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
    70
 * thrown.
4b57f9da8192 4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents: 14997
diff changeset
    71
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * @author      Michael McCloskey
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @see         java.lang.StringBuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @see         java.lang.String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @since       1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
public final class StringBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    extends AbstractStringBuilder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    implements java.io.Serializable, CharSequence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /** use serialVersionUID for interoperability */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    static final long serialVersionUID = 4383685877147921099L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Constructs a string builder with no characters in it and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * initial capacity of 16 characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
    89
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public StringBuilder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        super(16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Constructs a string builder with no characters in it and an
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    96
     * initial capacity specified by the {@code capacity} argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param      capacity  the initial capacity.
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
    99
     * @throws     NegativeArraySizeException  if the {@code capacity}
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   100
     *               argument is less than {@code 0}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   102
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public StringBuilder(int capacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        super(capacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Constructs a string builder initialized to the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * specified string. The initial capacity of the string builder is
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   110
     * {@code 16} plus the length of the string argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param   str   the initial contents of the buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   114
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public StringBuilder(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        super(str.length() + 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Constructs a string builder that contains the same characters
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   122
     * as the specified {@code CharSequence}. The initial capacity of
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   123
     * the string builder is {@code 16} plus the length of the
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   124
     * {@code CharSequence} argument.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param      seq   the sequence to copy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public StringBuilder(CharSequence seq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        this(seq.length() + 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        append(seq);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   133
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public StringBuilder append(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        return append(String.valueOf(obj));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   138
    @Override
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   139
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public StringBuilder append(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        super.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   146
     * Appends the specified {@code StringBuffer} to this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * <p>
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   148
     * The characters of the {@code StringBuffer} argument are appended,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * in order, to this sequence, increasing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * length of this sequence by the length of the argument.
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   151
     * If {@code sb} is {@code null}, then the four characters
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   152
     * {@code "null"} are appended to this sequence.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Let <i>n</i> be the length of this character sequence just prior to
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   155
     * execution of the {@code append} method. Then the character at index
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <i>k</i> in the new character sequence is equal to the character at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * index <i>k</i> in the old character sequence, if <i>k</i> is less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i>
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   159
     * in the argument {@code sb}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   161
     * @param   sb   the {@code StringBuffer} to append.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return  a reference to this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public StringBuilder append(StringBuffer sb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        super.append(sb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   169
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public StringBuilder append(CharSequence s) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   171
        super.append(s);
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   172
        return this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @throws     IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   178
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public StringBuilder append(CharSequence s, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        super.append(s, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   184
    @Override
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   185
    public StringBuilder append(char[] str) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        super.append(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   190
    /**
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   191
     * @throws IndexOutOfBoundsException {@inheritDoc}
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   192
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   193
    @Override
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   194
    public StringBuilder append(char[] str, int offset, int len) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        super.append(str, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   199
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public StringBuilder append(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        super.append(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   205
    @Override
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   206
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public StringBuilder append(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        super.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   212
    @Override
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   213
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public StringBuilder append(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        super.append(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   219
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public StringBuilder append(long lng) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        super.append(lng);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   225
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public StringBuilder append(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        super.append(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   231
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public StringBuilder append(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        super.append(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   240
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    public StringBuilder appendCodePoint(int codePoint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        super.appendCodePoint(codePoint);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   249
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public StringBuilder delete(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        super.delete(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   258
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public StringBuilder deleteCharAt(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        super.deleteCharAt(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   267
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public StringBuilder replace(int start, int end, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        super.replace(start, end, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   276
    @Override
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   277
    public StringBuilder insert(int index, char[] str, int offset,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                                int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        super.insert(index, str, offset, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   287
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public StringBuilder insert(int offset, Object obj) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   289
            super.insert(offset, obj);
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   290
            return this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   296
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    public StringBuilder insert(int offset, String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        super.insert(offset, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   305
    @Override
1223
5c1037124466 6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents: 2
diff changeset
   306
    public StringBuilder insert(int offset, char[] str) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        super.insert(offset, str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   314
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public StringBuilder insert(int dstOffset, CharSequence s) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   316
            super.insert(dstOffset, s);
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   317
            return this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   323
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public StringBuilder insert(int dstOffset, CharSequence s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                int start, int end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        super.insert(dstOffset, s, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   334
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public StringBuilder insert(int offset, boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        super.insert(offset, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @throws IndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   343
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    public StringBuilder insert(int offset, char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        super.insert(offset, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   352
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public StringBuilder insert(int offset, int i) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   354
        super.insert(offset, i);
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   355
        return this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   361
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public StringBuilder insert(int offset, long l) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   363
        super.insert(offset, l);
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   364
        return this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   370
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public StringBuilder insert(int offset, float f) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   372
        super.insert(offset, f);
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   373
        return this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @throws StringIndexOutOfBoundsException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   379
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public StringBuilder insert(int offset, double d) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   381
        super.insert(offset, d);
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   382
        return this;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   385
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public int indexOf(String str) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   387
        return super.indexOf(str);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   390
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public int indexOf(String str, int fromIndex) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   392
        return super.indexOf(str, fromIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   395
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public int lastIndexOf(String str) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   397
        return super.lastIndexOf(str);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   400
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public int lastIndexOf(String str, int fromIndex) {
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   402
        return super.lastIndexOf(str, fromIndex);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   405
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public StringBuilder reverse() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        super.reverse();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
14332
451c5dd717dc 6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents: 5506
diff changeset
   411
    @Override
31671
362e0c0acece 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents: 25859
diff changeset
   412
    @HotSpotIntrinsicCandidate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        // Create a copy, don't share the array
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   415
        return isLatin1() ? StringLatin1.newString(value, 0, count)
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   416
                          : StringUTF16.newStringSB(value, 0, count);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   420
     * Save the state of the {@code StringBuilder} instance to a stream
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * (that is, serialize it).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @serialData the number of characters currently stored in the string
14997
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   424
     *             builder ({@code int}), followed by the characters in the
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   425
     *             string builder ({@code char[]}).   The length of the
97d6098fd419 8005118: Javadoc styles are inconsistent
jgish
parents: 14342
diff changeset
   426
     *             {@code char} array may be greater than the number of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *             characters currently stored in the string builder, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *             case extra characters are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        s.writeInt(count);
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   434
        char[] val = new char[capacity()];
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   435
        if (isLatin1()) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   436
            StringLatin1.getChars(value, 0, count, val, 0);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   437
        } else {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   438
            StringUTF16.getChars(value, 0, count, val, 0);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   439
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   440
        s.writeObject(val);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * readObject is called to restore the state of the StringBuffer from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * a stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        throws java.io.IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        count = s.readInt();
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   451
        char[] val = (char[]) s.readObject();
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 31671
diff changeset
   452
        initBytes(val, 0, val.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
}