author | jlaskey |
Thu, 06 Jun 2019 12:24:44 -0300 | |
changeset 55260 | cc0f117f4405 |
parent 54481 | f847a42ddc01 |
child 57956 | e0b8b019d2f5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
53653
868611f0adc3
8218227: StringBuilder/StringBuffer constructor throws confusing NegativeArraySizeException
igerasim
parents:
49115
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang; |
|
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 | 29 |
|
30 |
/** |
|
31 |
* A mutable sequence of characters. This class provides an API compatible |
|
14997 | 32 |
* with {@code StringBuffer}, but with no guarantee of synchronization. |
2 | 33 |
* This class is designed for use as a drop-in replacement for |
14997 | 34 |
* {@code StringBuffer} in places where the string buffer was being |
2 | 35 |
* used by a single thread (as is generally the case). Where possible, |
36 |
* it is recommended that this class be used in preference to |
|
14997 | 37 |
* {@code StringBuffer} as it will be faster under most implementations. |
2 | 38 |
* |
14997 | 39 |
* <p>The principal operations on a {@code StringBuilder} are the |
40 |
* {@code append} and {@code insert} methods, which are |
|
2 | 41 |
* overloaded so as to accept data of any type. Each effectively |
42 |
* converts a given datum to a string and then appends or inserts the |
|
43 |
* characters of that string to the string builder. The |
|
14997 | 44 |
* {@code append} method always adds these characters at the end |
45 |
* of the builder; the {@code insert} method adds the characters at |
|
2 | 46 |
* a specified point. |
47 |
* <p> |
|
14997 | 48 |
* For example, if {@code z} refers to a string builder object |
49 |
* whose current contents are "{@code start}", then |
|
50 |
* the method call {@code z.append("le")} would cause the string |
|
51 |
* builder to contain "{@code startle}", whereas |
|
52 |
* {@code z.insert(4, "le")} would alter the string builder to |
|
53 |
* contain "{@code starlet}". |
|
2 | 54 |
* <p> |
14997 | 55 |
* In general, if sb refers to an instance of a {@code StringBuilder}, |
56 |
* then {@code sb.append(x)} has the same effect as |
|
57 |
* {@code sb.insert(sb.length(), x)}. |
|
58 |
* <p> |
|
2 | 59 |
* Every string builder has a capacity. As long as the length of the |
60 |
* character sequence contained in the string builder does not exceed |
|
61 |
* the capacity, it is not necessary to allocate a new internal |
|
62 |
* buffer. If the internal buffer overflows, it is automatically made larger. |
|
63 |
* |
|
14997 | 64 |
* <p>Instances of {@code StringBuilder} are not safe for |
2 | 65 |
* use by multiple threads. If such synchronization is required then it is |
66 |
* recommended that {@link java.lang.StringBuffer} be used. |
|
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 |
* |
49115
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
72 |
* @apiNote |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
73 |
* {@code StringBuilder} implements {@code Comparable} but does not override |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
74 |
* {@link Object#equals equals}. Thus, the natural ordering of {@code StringBuilder} |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
75 |
* is inconsistent with equals. Care should be exercised if {@code StringBuilder} |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
76 |
* objects are used as keys in a {@code SortedMap} or elements in a {@code SortedSet}. |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
77 |
* See {@link Comparable}, {@link java.util.SortedMap SortedMap}, or |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
78 |
* {@link java.util.SortedSet SortedSet} for more information. |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
79 |
* |
2 | 80 |
* @author Michael McCloskey |
81 |
* @see java.lang.StringBuffer |
|
82 |
* @see java.lang.String |
|
83 |
* @since 1.5 |
|
84 |
*/ |
|
85 |
public final class StringBuilder |
|
86 |
extends AbstractStringBuilder |
|
49115
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
87 |
implements java.io.Serializable, Comparable<StringBuilder>, CharSequence |
2 | 88 |
{ |
89 |
||
90 |
/** use serialVersionUID for interoperability */ |
|
91 |
static final long serialVersionUID = 4383685877147921099L; |
|
92 |
||
93 |
/** |
|
94 |
* Constructs a string builder with no characters in it and an |
|
95 |
* initial capacity of 16 characters. |
|
96 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
97 |
@HotSpotIntrinsicCandidate |
2 | 98 |
public StringBuilder() { |
99 |
super(16); |
|
100 |
} |
|
101 |
||
102 |
/** |
|
103 |
* Constructs a string builder with no characters in it and an |
|
14997 | 104 |
* initial capacity specified by the {@code capacity} argument. |
2 | 105 |
* |
106 |
* @param capacity the initial capacity. |
|
14997 | 107 |
* @throws NegativeArraySizeException if the {@code capacity} |
108 |
* argument is less than {@code 0}. |
|
2 | 109 |
*/ |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
110 |
@HotSpotIntrinsicCandidate |
2 | 111 |
public StringBuilder(int capacity) { |
112 |
super(capacity); |
|
113 |
} |
|
114 |
||
115 |
/** |
|
116 |
* Constructs a string builder initialized to the contents of the |
|
117 |
* specified string. The initial capacity of the string builder is |
|
14997 | 118 |
* {@code 16} plus the length of the string argument. |
2 | 119 |
* |
120 |
* @param str the initial contents of the buffer. |
|
121 |
*/ |
|
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
122 |
@HotSpotIntrinsicCandidate |
2 | 123 |
public StringBuilder(String str) { |
54481
f847a42ddc01
8221430: StringBuffer(CharSequence) constructor truncates when -XX:-CompactStrings specified
igerasim
parents:
53653
diff
changeset
|
124 |
super(str); |
2 | 125 |
} |
126 |
||
127 |
/** |
|
128 |
* Constructs a string builder that contains the same characters |
|
14997 | 129 |
* as the specified {@code CharSequence}. The initial capacity of |
130 |
* the string builder is {@code 16} plus the length of the |
|
131 |
* {@code CharSequence} argument. |
|
2 | 132 |
* |
133 |
* @param seq the sequence to copy. |
|
134 |
*/ |
|
135 |
public StringBuilder(CharSequence seq) { |
|
54481
f847a42ddc01
8221430: StringBuffer(CharSequence) constructor truncates when -XX:-CompactStrings specified
igerasim
parents:
53653
diff
changeset
|
136 |
super(seq); |
2 | 137 |
} |
138 |
||
49115
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
139 |
/** |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
140 |
* Compares two {@code StringBuilder} instances lexicographically. This method |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
141 |
* follows the same rules for lexicographical comparison as defined in the |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
142 |
* {@linkplain java.lang.CharSequence#compare(java.lang.CharSequence, |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
143 |
* java.lang.CharSequence) CharSequence.compare(this, another)} method. |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
144 |
* |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
145 |
* <p> |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
146 |
* For finer-grained, locale-sensitive String comparison, refer to |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
147 |
* {@link java.text.Collator}. |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
148 |
* |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
149 |
* @param another the {@code StringBuilder} to be compared with |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
150 |
* |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
151 |
* @return the value {@code 0} if this {@code StringBuilder} contains the same |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
152 |
* character sequence as that of the argument {@code StringBuilder}; a negative integer |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
153 |
* if this {@code StringBuilder} is lexicographically less than the |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
154 |
* {@code StringBuilder} argument; or a positive integer if this {@code StringBuilder} |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
155 |
* is lexicographically greater than the {@code StringBuilder} argument. |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
156 |
* |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
157 |
* @since 11 |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
158 |
*/ |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
159 |
@Override |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
160 |
public int compareTo(StringBuilder another) { |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
161 |
return super.compareTo(another); |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
162 |
} |
ecfaa82c53be
8137326: Methods for comparing CharSequence, StringBuilder, and StringBuffer
joehw
parents:
47216
diff
changeset
|
163 |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
164 |
@Override |
2 | 165 |
public StringBuilder append(Object obj) { |
166 |
return append(String.valueOf(obj)); |
|
167 |
} |
|
168 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
169 |
@Override |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
170 |
@HotSpotIntrinsicCandidate |
2 | 171 |
public StringBuilder append(String str) { |
172 |
super.append(str); |
|
173 |
return this; |
|
174 |
} |
|
175 |
||
176 |
/** |
|
14997 | 177 |
* Appends the specified {@code StringBuffer} to this sequence. |
2 | 178 |
* <p> |
14997 | 179 |
* The characters of the {@code StringBuffer} argument are appended, |
2 | 180 |
* in order, to this sequence, increasing the |
181 |
* length of this sequence by the length of the argument. |
|
14997 | 182 |
* If {@code sb} is {@code null}, then the four characters |
183 |
* {@code "null"} are appended to this sequence. |
|
2 | 184 |
* <p> |
185 |
* Let <i>n</i> be the length of this character sequence just prior to |
|
14997 | 186 |
* execution of the {@code append} method. Then the character at index |
2 | 187 |
* <i>k</i> in the new character sequence is equal to the character at |
188 |
* index <i>k</i> in the old character sequence, if <i>k</i> is less than |
|
189 |
* <i>n</i>; otherwise, it is equal to the character at index <i>k-n</i> |
|
14997 | 190 |
* in the argument {@code sb}. |
2 | 191 |
* |
14997 | 192 |
* @param sb the {@code StringBuffer} to append. |
2 | 193 |
* @return a reference to this object. |
194 |
*/ |
|
195 |
public StringBuilder append(StringBuffer sb) { |
|
196 |
super.append(sb); |
|
197 |
return this; |
|
198 |
} |
|
199 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
200 |
@Override |
2 | 201 |
public StringBuilder append(CharSequence s) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
202 |
super.append(s); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
203 |
return this; |
2 | 204 |
} |
205 |
||
206 |
/** |
|
207 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
208 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
209 |
@Override |
2 | 210 |
public StringBuilder append(CharSequence s, int start, int end) { |
211 |
super.append(s, start, end); |
|
212 |
return this; |
|
213 |
} |
|
214 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
215 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
216 |
public StringBuilder append(char[] str) { |
2 | 217 |
super.append(str); |
218 |
return this; |
|
219 |
} |
|
220 |
||
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
221 |
/** |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
222 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
223 |
*/ |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
224 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
225 |
public StringBuilder append(char[] str, int offset, int len) { |
2 | 226 |
super.append(str, offset, len); |
227 |
return this; |
|
228 |
} |
|
229 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
230 |
@Override |
2 | 231 |
public StringBuilder append(boolean b) { |
232 |
super.append(b); |
|
233 |
return this; |
|
234 |
} |
|
235 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
236 |
@Override |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
237 |
@HotSpotIntrinsicCandidate |
2 | 238 |
public StringBuilder append(char c) { |
239 |
super.append(c); |
|
240 |
return this; |
|
241 |
} |
|
242 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
243 |
@Override |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
244 |
@HotSpotIntrinsicCandidate |
2 | 245 |
public StringBuilder append(int i) { |
246 |
super.append(i); |
|
247 |
return this; |
|
248 |
} |
|
249 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
250 |
@Override |
2 | 251 |
public StringBuilder append(long lng) { |
252 |
super.append(lng); |
|
253 |
return this; |
|
254 |
} |
|
255 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
256 |
@Override |
2 | 257 |
public StringBuilder append(float f) { |
258 |
super.append(f); |
|
259 |
return this; |
|
260 |
} |
|
261 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
262 |
@Override |
2 | 263 |
public StringBuilder append(double d) { |
264 |
super.append(d); |
|
265 |
return this; |
|
266 |
} |
|
267 |
||
268 |
/** |
|
269 |
* @since 1.5 |
|
270 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
271 |
@Override |
2 | 272 |
public StringBuilder appendCodePoint(int codePoint) { |
273 |
super.appendCodePoint(codePoint); |
|
274 |
return this; |
|
275 |
} |
|
276 |
||
277 |
/** |
|
278 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
279 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
280 |
@Override |
2 | 281 |
public StringBuilder delete(int start, int end) { |
282 |
super.delete(start, end); |
|
283 |
return this; |
|
284 |
} |
|
285 |
||
286 |
/** |
|
287 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
288 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
289 |
@Override |
2 | 290 |
public StringBuilder deleteCharAt(int index) { |
291 |
super.deleteCharAt(index); |
|
292 |
return this; |
|
293 |
} |
|
294 |
||
295 |
/** |
|
296 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
297 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
298 |
@Override |
2 | 299 |
public StringBuilder replace(int start, int end, String str) { |
300 |
super.replace(start, end, str); |
|
301 |
return this; |
|
302 |
} |
|
303 |
||
304 |
/** |
|
305 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
306 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
307 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
308 |
public StringBuilder insert(int index, char[] str, int offset, |
2 | 309 |
int len) |
310 |
{ |
|
311 |
super.insert(index, str, offset, len); |
|
312 |
return this; |
|
313 |
} |
|
314 |
||
315 |
/** |
|
316 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
317 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
318 |
@Override |
2 | 319 |
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
|
320 |
super.insert(offset, obj); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
321 |
return this; |
2 | 322 |
} |
323 |
||
324 |
/** |
|
325 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
326 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
327 |
@Override |
2 | 328 |
public StringBuilder insert(int offset, String str) { |
329 |
super.insert(offset, str); |
|
330 |
return this; |
|
331 |
} |
|
332 |
||
333 |
/** |
|
334 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
335 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
336 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
337 |
public StringBuilder insert(int offset, char[] str) { |
2 | 338 |
super.insert(offset, str); |
339 |
return this; |
|
340 |
} |
|
341 |
||
342 |
/** |
|
343 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
344 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
345 |
@Override |
2 | 346 |
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
|
347 |
super.insert(dstOffset, s); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
348 |
return this; |
2 | 349 |
} |
350 |
||
351 |
/** |
|
352 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
353 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
354 |
@Override |
2 | 355 |
public StringBuilder insert(int dstOffset, CharSequence s, |
356 |
int start, int end) |
|
357 |
{ |
|
358 |
super.insert(dstOffset, s, start, end); |
|
359 |
return this; |
|
360 |
} |
|
361 |
||
362 |
/** |
|
363 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
364 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
365 |
@Override |
2 | 366 |
public StringBuilder insert(int offset, boolean b) { |
367 |
super.insert(offset, b); |
|
368 |
return this; |
|
369 |
} |
|
370 |
||
371 |
/** |
|
372 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
373 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
374 |
@Override |
2 | 375 |
public StringBuilder insert(int offset, char c) { |
376 |
super.insert(offset, c); |
|
377 |
return this; |
|
378 |
} |
|
379 |
||
380 |
/** |
|
381 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
382 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
383 |
@Override |
2 | 384 |
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
|
385 |
super.insert(offset, i); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
386 |
return this; |
2 | 387 |
} |
388 |
||
389 |
/** |
|
390 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
391 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
392 |
@Override |
2 | 393 |
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
|
394 |
super.insert(offset, l); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
395 |
return this; |
2 | 396 |
} |
397 |
||
398 |
/** |
|
399 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
400 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
401 |
@Override |
2 | 402 |
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
|
403 |
super.insert(offset, f); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
404 |
return this; |
2 | 405 |
} |
406 |
||
407 |
/** |
|
408 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
409 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
410 |
@Override |
2 | 411 |
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
|
412 |
super.insert(offset, d); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
413 |
return this; |
2 | 414 |
} |
415 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
416 |
@Override |
2 | 417 |
public int indexOf(String str) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
418 |
return super.indexOf(str); |
2 | 419 |
} |
420 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
421 |
@Override |
2 | 422 |
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
|
423 |
return super.indexOf(str, fromIndex); |
2 | 424 |
} |
425 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
426 |
@Override |
2 | 427 |
public int lastIndexOf(String str) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
428 |
return super.lastIndexOf(str); |
2 | 429 |
} |
430 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
431 |
@Override |
2 | 432 |
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
|
433 |
return super.lastIndexOf(str, fromIndex); |
2 | 434 |
} |
435 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
436 |
@Override |
2 | 437 |
public StringBuilder reverse() { |
438 |
super.reverse(); |
|
439 |
return this; |
|
440 |
} |
|
441 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
5506
diff
changeset
|
442 |
@Override |
31671
362e0c0acece
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
25859
diff
changeset
|
443 |
@HotSpotIntrinsicCandidate |
2 | 444 |
public String toString() { |
445 |
// Create a copy, don't share the array |
|
33663 | 446 |
return isLatin1() ? StringLatin1.newString(value, 0, count) |
34517
c6e795a80c80
8142303: C2 compilation fails with "bad AD file"
thartmann
parents:
33663
diff
changeset
|
447 |
: StringUTF16.newString(value, 0, count); |
2 | 448 |
} |
449 |
||
450 |
/** |
|
14997 | 451 |
* Save the state of the {@code StringBuilder} instance to a stream |
2 | 452 |
* (that is, serialize it). |
453 |
* |
|
454 |
* @serialData the number of characters currently stored in the string |
|
14997 | 455 |
* builder ({@code int}), followed by the characters in the |
456 |
* string builder ({@code char[]}). The length of the |
|
457 |
* {@code char} array may be greater than the number of |
|
2 | 458 |
* characters currently stored in the string builder, in which |
459 |
* case extra characters are ignored. |
|
460 |
*/ |
|
461 |
private void writeObject(java.io.ObjectOutputStream s) |
|
462 |
throws java.io.IOException { |
|
463 |
s.defaultWriteObject(); |
|
464 |
s.writeInt(count); |
|
33663 | 465 |
char[] val = new char[capacity()]; |
466 |
if (isLatin1()) { |
|
467 |
StringLatin1.getChars(value, 0, count, val, 0); |
|
468 |
} else { |
|
469 |
StringUTF16.getChars(value, 0, count, val, 0); |
|
470 |
} |
|
471 |
s.writeObject(val); |
|
2 | 472 |
} |
473 |
||
474 |
/** |
|
475 |
* readObject is called to restore the state of the StringBuffer from |
|
476 |
* a stream. |
|
477 |
*/ |
|
478 |
private void readObject(java.io.ObjectInputStream s) |
|
479 |
throws java.io.IOException, ClassNotFoundException { |
|
480 |
s.defaultReadObject(); |
|
481 |
count = s.readInt(); |
|
33663 | 482 |
char[] val = (char[]) s.readObject(); |
483 |
initBytes(val, 0, val.length); |
|
2 | 484 |
} |
485 |
||
486 |
} |