author | darcy |
Thu, 27 Jun 2013 19:02:02 -0700 | |
changeset 18569 | 0e46c17766b7 |
parent 17709 | fc6f678fdb83 |
child 24865 | 09b1d992ca72 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
2 |
* Copyright (c) 1994, 2013, 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 |
||
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
28 |
import java.util.Arrays; |
2 | 29 |
|
30 |
/** |
|
31 |
* A thread-safe, mutable sequence of characters. |
|
32 |
* A string buffer is like a {@link String}, but can be modified. At any |
|
33 |
* point in time it contains some particular sequence of characters, but |
|
34 |
* the length and content of the sequence can be changed through certain |
|
35 |
* method calls. |
|
36 |
* <p> |
|
37 |
* String buffers are safe for use by multiple threads. The methods |
|
38 |
* are synchronized where necessary so that all the operations on any |
|
39 |
* particular instance behave as if they occur in some serial order |
|
40 |
* that is consistent with the order of the method calls made by each of |
|
41 |
* the individual threads involved. |
|
42 |
* <p> |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
43 |
* The principal operations on a {@code StringBuffer} are the |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
44 |
* {@code append} and {@code insert} methods, which are |
2 | 45 |
* overloaded so as to accept data of any type. Each effectively |
46 |
* converts a given datum to a string and then appends or inserts the |
|
47 |
* characters of that string to the string buffer. The |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
48 |
* {@code append} method always adds these characters at the end |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
49 |
* of the buffer; the {@code insert} method adds the characters at |
2 | 50 |
* a specified point. |
51 |
* <p> |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
52 |
* For example, if {@code z} refers to a string buffer object |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
53 |
* whose current contents are {@code "start"}, then |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
54 |
* the method call {@code z.append("le")} would cause the string |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
55 |
* buffer to contain {@code "startle"}, whereas |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
56 |
* {@code z.insert(4, "le")} would alter the string buffer to |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
57 |
* contain {@code "starlet"}. |
2 | 58 |
* <p> |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
59 |
* In general, if sb refers to an instance of a {@code StringBuffer}, |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
60 |
* then {@code sb.append(x)} has the same effect as |
14997 | 61 |
* {@code sb.insert(sb.length(), x)}. |
2 | 62 |
* <p> |
63 |
* Whenever an operation occurs involving a source sequence (such as |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
64 |
* appending or inserting from a source sequence), this class synchronizes |
2 | 65 |
* only on the string buffer performing the operation, not on the source. |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
66 |
* Note that while {@code StringBuffer} is designed to be safe to use |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
67 |
* concurrently from multiple threads, if the constructor or the |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
68 |
* {@code append} or {@code insert} operation is passed a source sequence |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
69 |
* that is shared across threads, the calling code must ensure |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
70 |
* that the operation has a consistent and unchanging view of the source |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
71 |
* sequence for the duration of the operation. |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
72 |
* This could be satisfied by the caller holding a lock during the |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
73 |
* operation's call, by using an immutable source sequence, or by not |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
74 |
* sharing the source sequence across threads. |
2 | 75 |
* <p> |
76 |
* Every string buffer has a capacity. As long as the length of the |
|
77 |
* character sequence contained in the string buffer does not exceed |
|
78 |
* the capacity, it is not necessary to allocate a new internal |
|
79 |
* buffer array. If the internal buffer overflows, it is |
|
80 |
* automatically made larger. |
|
15312
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
81 |
* <p> |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
82 |
* 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
|
83 |
* 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
|
84 |
* thrown. |
4b57f9da8192
4247235: (spec str) StringBuffer.insert(int, char[]) specification is inconsistent
jgish
parents:
14997
diff
changeset
|
85 |
* <p> |
2 | 86 |
* As of release JDK 5, this class has been supplemented with an equivalent |
87 |
* class designed for use by a single thread, {@link StringBuilder}. The |
|
14997 | 88 |
* {@code StringBuilder} class should generally be used in preference to |
2 | 89 |
* this one, as it supports all of the same operations but it is faster, as |
90 |
* it performs no synchronization. |
|
91 |
* |
|
92 |
* @author Arthur van Hoff |
|
93 |
* @see java.lang.StringBuilder |
|
94 |
* @see java.lang.String |
|
95 |
* @since JDK1.0 |
|
96 |
*/ |
|
97 |
public final class StringBuffer |
|
98 |
extends AbstractStringBuilder |
|
99 |
implements java.io.Serializable, CharSequence |
|
100 |
{ |
|
101 |
||
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
102 |
/** |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
103 |
* A cache of the last value returned by toString. Cleared |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
104 |
* whenever the StringBuffer is modified. |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
105 |
*/ |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
106 |
private transient char[] toStringCache; |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
107 |
|
2 | 108 |
/** use serialVersionUID from JDK 1.0.2 for interoperability */ |
109 |
static final long serialVersionUID = 3388685877147921107L; |
|
110 |
||
111 |
/** |
|
112 |
* Constructs a string buffer with no characters in it and an |
|
113 |
* initial capacity of 16 characters. |
|
114 |
*/ |
|
115 |
public StringBuffer() { |
|
116 |
super(16); |
|
117 |
} |
|
118 |
||
119 |
/** |
|
120 |
* Constructs a string buffer with no characters in it and |
|
121 |
* the specified initial capacity. |
|
122 |
* |
|
123 |
* @param capacity the initial capacity. |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
124 |
* @exception NegativeArraySizeException if the {@code capacity} |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
125 |
* argument is less than {@code 0}. |
2 | 126 |
*/ |
127 |
public StringBuffer(int capacity) { |
|
128 |
super(capacity); |
|
129 |
} |
|
130 |
||
131 |
/** |
|
132 |
* Constructs a string buffer initialized to the contents of the |
|
133 |
* specified string. The initial capacity of the string buffer is |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
134 |
* {@code 16} plus the length of the string argument. |
2 | 135 |
* |
136 |
* @param str the initial contents of the buffer. |
|
137 |
*/ |
|
138 |
public StringBuffer(String str) { |
|
139 |
super(str.length() + 16); |
|
140 |
append(str); |
|
141 |
} |
|
142 |
||
143 |
/** |
|
144 |
* Constructs a string buffer that contains the same characters |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
145 |
* as the specified {@code CharSequence}. The initial capacity of |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
146 |
* the string buffer is {@code 16} plus the length of the |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
147 |
* {@code CharSequence} argument. |
2 | 148 |
* <p> |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
149 |
* If the length of the specified {@code CharSequence} is |
2 | 150 |
* less than or equal to zero, then an empty buffer of capacity |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
151 |
* {@code 16} is returned. |
2 | 152 |
* |
153 |
* @param seq the sequence to copy. |
|
154 |
* @since 1.5 |
|
155 |
*/ |
|
156 |
public StringBuffer(CharSequence seq) { |
|
157 |
this(seq.length() + 16); |
|
158 |
append(seq); |
|
159 |
} |
|
160 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
161 |
@Override |
2 | 162 |
public synchronized int length() { |
163 |
return count; |
|
164 |
} |
|
165 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
166 |
@Override |
2 | 167 |
public synchronized int capacity() { |
168 |
return value.length; |
|
169 |
} |
|
170 |
||
171 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
172 |
@Override |
2 | 173 |
public synchronized void ensureCapacity(int minimumCapacity) { |
174 |
if (minimumCapacity > value.length) { |
|
175 |
expandCapacity(minimumCapacity); |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
/** |
|
180 |
* @since 1.5 |
|
181 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
182 |
@Override |
2 | 183 |
public synchronized void trimToSize() { |
184 |
super.trimToSize(); |
|
185 |
} |
|
186 |
||
187 |
/** |
|
188 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
189 |
* @see #length() |
|
190 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
191 |
@Override |
2 | 192 |
public synchronized void setLength(int newLength) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
193 |
toStringCache = null; |
2 | 194 |
super.setLength(newLength); |
195 |
} |
|
196 |
||
197 |
/** |
|
198 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
199 |
* @see #length() |
|
200 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
201 |
@Override |
2 | 202 |
public synchronized char charAt(int index) { |
203 |
if ((index < 0) || (index >= count)) |
|
204 |
throw new StringIndexOutOfBoundsException(index); |
|
205 |
return value[index]; |
|
206 |
} |
|
207 |
||
208 |
/** |
|
209 |
* @since 1.5 |
|
210 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
211 |
@Override |
2 | 212 |
public synchronized int codePointAt(int index) { |
213 |
return super.codePointAt(index); |
|
214 |
} |
|
215 |
||
216 |
/** |
|
217 |
* @since 1.5 |
|
218 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
219 |
@Override |
2 | 220 |
public synchronized int codePointBefore(int index) { |
221 |
return super.codePointBefore(index); |
|
222 |
} |
|
223 |
||
224 |
/** |
|
225 |
* @since 1.5 |
|
226 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
227 |
@Override |
2 | 228 |
public synchronized int codePointCount(int beginIndex, int endIndex) { |
229 |
return super.codePointCount(beginIndex, endIndex); |
|
230 |
} |
|
231 |
||
232 |
/** |
|
233 |
* @since 1.5 |
|
234 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
235 |
@Override |
2 | 236 |
public synchronized int offsetByCodePoints(int index, int codePointOffset) { |
237 |
return super.offsetByCodePoints(index, codePointOffset); |
|
238 |
} |
|
239 |
||
240 |
/** |
|
241 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
242 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
243 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
244 |
public synchronized void getChars(int srcBegin, int srcEnd, char[] dst, |
2 | 245 |
int dstBegin) |
246 |
{ |
|
247 |
super.getChars(srcBegin, srcEnd, dst, dstBegin); |
|
248 |
} |
|
249 |
||
250 |
/** |
|
251 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
252 |
* @see #length() |
|
253 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
254 |
@Override |
2 | 255 |
public synchronized void setCharAt(int index, char ch) { |
256 |
if ((index < 0) || (index >= count)) |
|
257 |
throw new StringIndexOutOfBoundsException(index); |
|
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
258 |
toStringCache = null; |
2 | 259 |
value[index] = ch; |
260 |
} |
|
261 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
262 |
@Override |
2 | 263 |
public synchronized StringBuffer append(Object obj) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
264 |
toStringCache = null; |
2 | 265 |
super.append(String.valueOf(obj)); |
266 |
return this; |
|
267 |
} |
|
268 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
269 |
@Override |
2 | 270 |
public synchronized StringBuffer append(String str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
271 |
toStringCache = null; |
2 | 272 |
super.append(str); |
273 |
return this; |
|
274 |
} |
|
275 |
||
276 |
/** |
|
14997 | 277 |
* Appends the specified {@code StringBuffer} to this sequence. |
2 | 278 |
* <p> |
14997 | 279 |
* The characters of the {@code StringBuffer} argument are appended, |
280 |
* in order, to the contents of this {@code StringBuffer}, increasing the |
|
281 |
* length of this {@code StringBuffer} by the length of the argument. |
|
282 |
* If {@code sb} is {@code null}, then the four characters |
|
283 |
* {@code "null"} are appended to this {@code StringBuffer}. |
|
2 | 284 |
* <p> |
285 |
* Let <i>n</i> be the length of the old character sequence, the one |
|
14997 | 286 |
* contained in the {@code StringBuffer} just prior to execution of the |
287 |
* {@code append} method. Then the character at index <i>k</i> in |
|
2 | 288 |
* the new character sequence is equal to the character at index <i>k</i> |
289 |
* in the old character sequence, if <i>k</i> is less than <i>n</i>; |
|
290 |
* otherwise, it is equal to the character at index <i>k-n</i> in the |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
291 |
* argument {@code sb}. |
2 | 292 |
* <p> |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
293 |
* This method synchronizes on {@code this}, the destination |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
294 |
* object, but does not synchronize on the source ({@code sb}). |
2 | 295 |
* |
14997 | 296 |
* @param sb the {@code StringBuffer} to append. |
2 | 297 |
* @return a reference to this object. |
298 |
* @since 1.4 |
|
299 |
*/ |
|
300 |
public synchronized StringBuffer append(StringBuffer sb) { |
|
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
301 |
toStringCache = null; |
2 | 302 |
super.append(sb); |
303 |
return this; |
|
304 |
} |
|
305 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
306 |
/** |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
307 |
* @since 1.8 |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
308 |
*/ |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
309 |
@Override |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
310 |
synchronized StringBuffer append(AbstractStringBuilder asb) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
311 |
toStringCache = null; |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
312 |
super.append(asb); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
313 |
return this; |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
314 |
} |
2 | 315 |
|
316 |
/** |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
317 |
* Appends the specified {@code CharSequence} to this |
2 | 318 |
* sequence. |
319 |
* <p> |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
320 |
* The characters of the {@code CharSequence} argument are appended, |
2 | 321 |
* in order, increasing the length of this sequence by the length of the |
322 |
* argument. |
|
323 |
* |
|
324 |
* <p>The result of this method is exactly the same as if it were an |
|
325 |
* invocation of this.append(s, 0, s.length()); |
|
326 |
* |
|
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
327 |
* <p>This method synchronizes on {@code this}, the destination |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
328 |
* object, but does not synchronize on the source ({@code s}). |
2 | 329 |
* |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
330 |
* <p>If {@code s} is {@code null}, then the four characters |
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
331 |
* {@code "null"} are appended. |
2 | 332 |
* |
13155
8140afb39557
7100996: (spec str) IndexOutOfBoundsException when using a StringBuffer from multiple threads
jgish
parents:
5506
diff
changeset
|
333 |
* @param s the {@code CharSequence} to append. |
2 | 334 |
* @return a reference to this object. |
335 |
* @since 1.5 |
|
336 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
337 |
@Override |
17709
fc6f678fdb83
8014814: (str) StringBuffer "null" is not appended
dholmes
parents:
17472
diff
changeset
|
338 |
public synchronized StringBuffer append(CharSequence s) { |
fc6f678fdb83
8014814: (str) StringBuffer "null" is not appended
dholmes
parents:
17472
diff
changeset
|
339 |
toStringCache = null; |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
340 |
super.append(s); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
341 |
return this; |
2 | 342 |
} |
343 |
||
344 |
/** |
|
345 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
346 |
* @since 1.5 |
|
347 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
348 |
@Override |
2 | 349 |
public synchronized StringBuffer append(CharSequence s, int start, int end) |
350 |
{ |
|
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
351 |
toStringCache = null; |
2 | 352 |
super.append(s, start, end); |
353 |
return this; |
|
354 |
} |
|
355 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
356 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
357 |
public synchronized StringBuffer append(char[] str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
358 |
toStringCache = null; |
2 | 359 |
super.append(str); |
360 |
return this; |
|
361 |
} |
|
362 |
||
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
363 |
/** |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
364 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
365 |
*/ |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
366 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
367 |
public synchronized StringBuffer append(char[] str, int offset, int len) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
368 |
toStringCache = null; |
2 | 369 |
super.append(str, offset, len); |
370 |
return this; |
|
371 |
} |
|
372 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
373 |
@Override |
2 | 374 |
public synchronized StringBuffer append(boolean b) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
375 |
toStringCache = null; |
2 | 376 |
super.append(b); |
377 |
return this; |
|
378 |
} |
|
379 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
380 |
@Override |
2 | 381 |
public synchronized StringBuffer append(char c) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
382 |
toStringCache = null; |
2 | 383 |
super.append(c); |
384 |
return this; |
|
385 |
} |
|
386 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
387 |
@Override |
2 | 388 |
public synchronized StringBuffer append(int i) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
389 |
toStringCache = null; |
2 | 390 |
super.append(i); |
391 |
return this; |
|
392 |
} |
|
393 |
||
394 |
/** |
|
395 |
* @since 1.5 |
|
396 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
397 |
@Override |
2 | 398 |
public synchronized StringBuffer appendCodePoint(int codePoint) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
399 |
toStringCache = null; |
2 | 400 |
super.appendCodePoint(codePoint); |
401 |
return this; |
|
402 |
} |
|
403 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
404 |
@Override |
2 | 405 |
public synchronized StringBuffer append(long lng) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
406 |
toStringCache = null; |
2 | 407 |
super.append(lng); |
408 |
return this; |
|
409 |
} |
|
410 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
411 |
@Override |
2 | 412 |
public synchronized StringBuffer append(float f) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
413 |
toStringCache = null; |
2 | 414 |
super.append(f); |
415 |
return this; |
|
416 |
} |
|
417 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
418 |
@Override |
2 | 419 |
public synchronized StringBuffer append(double d) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
420 |
toStringCache = null; |
2 | 421 |
super.append(d); |
422 |
return this; |
|
423 |
} |
|
424 |
||
425 |
/** |
|
426 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
427 |
* @since 1.2 |
|
428 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
429 |
@Override |
2 | 430 |
public synchronized StringBuffer delete(int start, int end) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
431 |
toStringCache = null; |
2 | 432 |
super.delete(start, end); |
433 |
return this; |
|
434 |
} |
|
435 |
||
436 |
/** |
|
437 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
438 |
* @since 1.2 |
|
439 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
440 |
@Override |
2 | 441 |
public synchronized StringBuffer deleteCharAt(int index) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
442 |
toStringCache = null; |
2 | 443 |
super.deleteCharAt(index); |
444 |
return this; |
|
445 |
} |
|
446 |
||
447 |
/** |
|
448 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
449 |
* @since 1.2 |
|
450 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
451 |
@Override |
2 | 452 |
public synchronized StringBuffer replace(int start, int end, String str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
453 |
toStringCache = null; |
2 | 454 |
super.replace(start, end, str); |
455 |
return this; |
|
456 |
} |
|
457 |
||
458 |
/** |
|
459 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
460 |
* @since 1.2 |
|
461 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
462 |
@Override |
2 | 463 |
public synchronized String substring(int start) { |
464 |
return substring(start, count); |
|
465 |
} |
|
466 |
||
467 |
/** |
|
468 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
469 |
* @since 1.4 |
|
470 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
471 |
@Override |
2 | 472 |
public synchronized CharSequence subSequence(int start, int end) { |
473 |
return super.substring(start, end); |
|
474 |
} |
|
475 |
||
476 |
/** |
|
477 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
478 |
* @since 1.2 |
|
479 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
480 |
@Override |
2 | 481 |
public synchronized String substring(int start, int end) { |
482 |
return super.substring(start, end); |
|
483 |
} |
|
484 |
||
485 |
/** |
|
486 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
487 |
* @since 1.2 |
|
488 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
489 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
490 |
public synchronized StringBuffer insert(int index, char[] str, int offset, |
2 | 491 |
int len) |
492 |
{ |
|
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
493 |
toStringCache = null; |
2 | 494 |
super.insert(index, str, offset, len); |
495 |
return this; |
|
496 |
} |
|
497 |
||
498 |
/** |
|
499 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
500 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
501 |
@Override |
2 | 502 |
public synchronized StringBuffer insert(int offset, Object obj) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
503 |
toStringCache = null; |
2 | 504 |
super.insert(offset, String.valueOf(obj)); |
505 |
return this; |
|
506 |
} |
|
507 |
||
508 |
/** |
|
509 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
510 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
511 |
@Override |
2 | 512 |
public synchronized StringBuffer insert(int offset, String str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
513 |
toStringCache = null; |
2 | 514 |
super.insert(offset, str); |
515 |
return this; |
|
516 |
} |
|
517 |
||
518 |
/** |
|
519 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
520 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
521 |
@Override |
1223
5c1037124466
6728229: (str) StringBuilder.append(CharSequence) does not throw IndexOutOfBoundsException
martin
parents:
2
diff
changeset
|
522 |
public synchronized StringBuffer insert(int offset, char[] str) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
523 |
toStringCache = null; |
2 | 524 |
super.insert(offset, str); |
525 |
return this; |
|
526 |
} |
|
527 |
||
528 |
/** |
|
529 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
530 |
* @since 1.5 |
|
531 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
532 |
@Override |
2 | 533 |
public StringBuffer insert(int dstOffset, CharSequence s) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
534 |
// Note, synchronization achieved via invocations of other StringBuffer methods |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
535 |
// after narrowing of s to specific type |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
536 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
537 |
super.insert(dstOffset, s); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
538 |
return this; |
2 | 539 |
} |
540 |
||
541 |
/** |
|
542 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
543 |
* @since 1.5 |
|
544 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
545 |
@Override |
2 | 546 |
public synchronized StringBuffer insert(int dstOffset, CharSequence s, |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
547 |
int start, int end) |
2 | 548 |
{ |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
549 |
toStringCache = null; |
2 | 550 |
super.insert(dstOffset, s, start, end); |
551 |
return this; |
|
552 |
} |
|
553 |
||
554 |
/** |
|
555 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
556 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
557 |
@Override |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
558 |
public StringBuffer insert(int offset, boolean b) { |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
559 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
560 |
// after conversion of b to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
561 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
562 |
super.insert(offset, b); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
563 |
return this; |
2 | 564 |
} |
565 |
||
566 |
/** |
|
567 |
* @throws IndexOutOfBoundsException {@inheritDoc} |
|
568 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
569 |
@Override |
2 | 570 |
public synchronized StringBuffer insert(int offset, char c) { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
571 |
toStringCache = null; |
2 | 572 |
super.insert(offset, c); |
573 |
return this; |
|
574 |
} |
|
575 |
||
576 |
/** |
|
577 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
578 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
579 |
@Override |
2 | 580 |
public StringBuffer insert(int offset, int i) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
581 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
582 |
// after conversion of i to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
583 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
584 |
super.insert(offset, i); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
585 |
return this; |
2 | 586 |
} |
587 |
||
588 |
/** |
|
589 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
590 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
591 |
@Override |
2 | 592 |
public StringBuffer insert(int offset, long l) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
593 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
594 |
// after conversion of l to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
595 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
596 |
super.insert(offset, l); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
597 |
return this; |
2 | 598 |
} |
599 |
||
600 |
/** |
|
601 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
602 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
603 |
@Override |
2 | 604 |
public StringBuffer insert(int offset, float f) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
605 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
606 |
// after conversion of f to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
607 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
608 |
super.insert(offset, f); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
609 |
return this; |
2 | 610 |
} |
611 |
||
612 |
/** |
|
613 |
* @throws StringIndexOutOfBoundsException {@inheritDoc} |
|
614 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
615 |
@Override |
2 | 616 |
public StringBuffer insert(int offset, double d) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
617 |
// Note, synchronization achieved via invocation of StringBuffer insert(int, String) |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
618 |
// after conversion of d to String by super class method |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
619 |
// Ditto for toStringCache clearing |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
620 |
super.insert(offset, d); |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
621 |
return this; |
2 | 622 |
} |
623 |
||
624 |
/** |
|
625 |
* @since 1.4 |
|
626 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
627 |
@Override |
2 | 628 |
public int indexOf(String str) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
629 |
// Note, synchronization achieved via invocations of other StringBuffer methods |
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
630 |
return super.indexOf(str); |
2 | 631 |
} |
632 |
||
633 |
/** |
|
634 |
* @since 1.4 |
|
635 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
636 |
@Override |
2 | 637 |
public synchronized int indexOf(String str, int fromIndex) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
638 |
return super.indexOf(str, fromIndex); |
2 | 639 |
} |
640 |
||
641 |
/** |
|
642 |
* @since 1.4 |
|
643 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
644 |
@Override |
2 | 645 |
public int lastIndexOf(String str) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
646 |
// Note, synchronization achieved via invocations of other StringBuffer methods |
2 | 647 |
return lastIndexOf(str, count); |
648 |
} |
|
649 |
||
650 |
/** |
|
651 |
* @since 1.4 |
|
652 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
653 |
@Override |
2 | 654 |
public synchronized int lastIndexOf(String str, int fromIndex) { |
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
655 |
return super.lastIndexOf(str, fromIndex); |
2 | 656 |
} |
657 |
||
658 |
/** |
|
659 |
* @since JDK1.0.2 |
|
660 |
*/ |
|
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
661 |
@Override |
2 | 662 |
public synchronized StringBuffer reverse() { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
663 |
toStringCache = null; |
2 | 664 |
super.reverse(); |
665 |
return this; |
|
666 |
} |
|
667 |
||
14332
451c5dd717dc
6206780: (str) Forwarding append methods in String{Buffer,Builder} are inconsistent
jgish
parents:
13155
diff
changeset
|
668 |
@Override |
2 | 669 |
public synchronized String toString() { |
17472
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
670 |
if (toStringCache == null) { |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
671 |
toStringCache = Arrays.copyOfRange(value, 0, count); |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
672 |
} |
4ce9bd9f56ac
8013395: StringBuffer.toString performance regression impacting embedded benchmarks
dholmes
parents:
15312
diff
changeset
|
673 |
return new String(toStringCache, true); |
2 | 674 |
} |
675 |
||
676 |
/** |
|
677 |
* Serializable fields for StringBuffer. |
|
678 |
* |
|
679 |
* @serialField value char[] |
|
680 |
* The backing character array of this StringBuffer. |
|
681 |
* @serialField count int |
|
682 |
* The number of characters in this StringBuffer. |
|
683 |
* @serialField shared boolean |
|
684 |
* A flag indicating whether the backing array is shared. |
|
685 |
* The value is ignored upon deserialization. |
|
686 |
*/ |
|
687 |
private static final java.io.ObjectStreamField[] serialPersistentFields = |
|
688 |
{ |
|
689 |
new java.io.ObjectStreamField("value", char[].class), |
|
690 |
new java.io.ObjectStreamField("count", Integer.TYPE), |
|
691 |
new java.io.ObjectStreamField("shared", Boolean.TYPE), |
|
692 |
}; |
|
693 |
||
694 |
/** |
|
695 |
* readObject is called to restore the state of the StringBuffer from |
|
696 |
* a stream. |
|
697 |
*/ |
|
698 |
private synchronized void writeObject(java.io.ObjectOutputStream s) |
|
699 |
throws java.io.IOException { |
|
700 |
java.io.ObjectOutputStream.PutField fields = s.putFields(); |
|
701 |
fields.put("value", value); |
|
702 |
fields.put("count", count); |
|
703 |
fields.put("shared", false); |
|
704 |
s.writeFields(); |
|
705 |
} |
|
706 |
||
707 |
/** |
|
708 |
* readObject is called to restore the state of the StringBuffer from |
|
709 |
* a stream. |
|
710 |
*/ |
|
711 |
private void readObject(java.io.ObjectInputStream s) |
|
712 |
throws java.io.IOException, ClassNotFoundException { |
|
713 |
java.io.ObjectInputStream.GetField fields = s.readFields(); |
|
714 |
value = (char[])fields.get("value", null); |
|
715 |
count = fields.get("count", 0); |
|
716 |
} |
|
717 |
} |