132
133 /**
134 * Constructs a string buffer that contains the same characters
135 * as the specified {@code CharSequence}. The initial capacity of
136 * the string buffer is {@code 16} plus the length of the
137 * {@code CharSequence} argument.
138 * <p>
139 * If the length of the specified {@code CharSequence} is
140 * less than or equal to zero, then an empty buffer of capacity
141 * {@code 16} is returned.
142 *
143 * @param seq the sequence to copy.
144 * @exception NullPointerException if {@code seq} is {@code null}
145 * @since 1.5
146 */
147 public StringBuffer(CharSequence seq) {
148 this(seq.length() + 16);
149 append(seq);
150 }
151
152 public synchronized int length() {
153 return count;
154 }
155
156 public synchronized int capacity() {
157 return value.length;
158 }
159
160
161 public synchronized void ensureCapacity(int minimumCapacity) {
162 if (minimumCapacity > value.length) {
163 expandCapacity(minimumCapacity);
164 }
165 }
166
167 /**
168 * @since 1.5
169 */
170 public synchronized void trimToSize() {
171 super.trimToSize();
172 }
173
174 /**
175 * @throws IndexOutOfBoundsException {@inheritDoc}
176 * @see #length()
177 */
178 public synchronized void setLength(int newLength) {
179 super.setLength(newLength);
180 }
181
182 /**
183 * @throws IndexOutOfBoundsException {@inheritDoc}
184 * @see #length()
185 */
186 public synchronized char charAt(int index) {
187 if ((index < 0) || (index >= count))
188 throw new StringIndexOutOfBoundsException(index);
189 return value[index];
190 }
191
192 /**
193 * @since 1.5
194 */
195 public synchronized int codePointAt(int index) {
196 return super.codePointAt(index);
197 }
198
199 /**
200 * @since 1.5
201 */
202 public synchronized int codePointBefore(int index) {
203 return super.codePointBefore(index);
204 }
205
206 /**
207 * @since 1.5
208 */
209 public synchronized int codePointCount(int beginIndex, int endIndex) {
210 return super.codePointCount(beginIndex, endIndex);
211 }
212
213 /**
214 * @since 1.5
215 */
216 public synchronized int offsetByCodePoints(int index, int codePointOffset) {
217 return super.offsetByCodePoints(index, codePointOffset);
218 }
219
220 /**
221 * @throws NullPointerException {@inheritDoc}
222 * @throws IndexOutOfBoundsException {@inheritDoc}
223 */
224 public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
225 int dstBegin)
226 {
227 super.getChars(srcBegin, srcEnd, dst, dstBegin);
228 }
229
230 /**
231 * @throws IndexOutOfBoundsException {@inheritDoc}
232 * @see #length()
233 */
234 public synchronized void setCharAt(int index, char ch) {
235 if ((index < 0) || (index >= count))
236 throw new StringIndexOutOfBoundsException(index);
237 value[index] = ch;
238 }
239
240 public synchronized StringBuffer append(Object obj) {
241 super.append(String.valueOf(obj));
242 return this;
243 }
244
245 public synchronized StringBuffer append(String str) {
246 super.append(str);
247 return this;
248 }
249
250 /**
251 * Appends the specified <tt>StringBuffer</tt> to this sequence.
252 * <p>
253 * The characters of the <tt>StringBuffer</tt> argument are appended,
254 * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
255 * length of this <tt>StringBuffer</tt> by the length of the argument.
256 * If <tt>sb</tt> is <tt>null</tt>, then the four characters
257 * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
258 * <p>
259 * Let <i>n</i> be the length of the old character sequence, the one
260 * contained in the <tt>StringBuffer</tt> just prior to execution of the
261 * <tt>append</tt> method. Then the character at index <i>k</i> in
262 * the new character sequence is equal to the character at index <i>k</i>
263 * in the old character sequence, if <i>k</i> is less than <i>n</i>;
264 * otherwise, it is equal to the character at index <i>k-n</i> in the
265 * argument {@code sb}.
266 * <p>
267 * This method synchronizes on {@code this}, the destination
268 * object, but does not synchronize on the source ({@code sb}).
269 *
270 * @param sb the <tt>StringBuffer</tt> to append.
271 * @return a reference to this object.
272 * @since 1.4
273 */
274 public synchronized StringBuffer append(StringBuffer sb) {
275 super.append(sb);
276 return this;
277 }
278
279
280 /**
281 * Appends the specified {@code CharSequence} to this
282 * sequence.
283 * <p>
284 * The characters of the {@code CharSequence} argument are appended,
285 * in order, increasing the length of this sequence by the length of the
286 * argument.
287 *
288 * <p>The result of this method is exactly the same as if it were an
289 * invocation of this.append(s, 0, s.length());
290 *
291 * <p>This method synchronizes on {@code this}, the destination
292 * object, but does not synchronize on the source ({@code s}).
293 *
294 * <p>If {@code s} is {@code null}, then the four characters
295 * {@code "null"} are appended.
296 *
297 * @param s the {@code CharSequence} to append.
298 * @return a reference to this object.
299 * @since 1.5
300 */
301 public StringBuffer append(CharSequence s) {
302 // Note, synchronization achieved via other invocations
303 if (s == null)
304 s = "null";
305 if (s instanceof String)
306 return this.append((String)s);
307 if (s instanceof StringBuffer)
308 return this.append((StringBuffer)s);
309 return this.append(s, 0, s.length());
310 }
311
312 /**
313 * @throws IndexOutOfBoundsException {@inheritDoc}
314 * @since 1.5
315 */
316 public synchronized StringBuffer append(CharSequence s, int start, int end)
317 {
318 super.append(s, start, end);
319 return this;
320 }
321
322 public synchronized StringBuffer append(char[] str) {
323 super.append(str);
324 return this;
325 }
326
327 /**
328 * @throws IndexOutOfBoundsException {@inheritDoc}
329 */
330 public synchronized StringBuffer append(char[] str, int offset, int len) {
331 super.append(str, offset, len);
332 return this;
333 }
334
335 public synchronized StringBuffer append(boolean b) {
336 super.append(b);
337 return this;
338 }
339
340 public synchronized StringBuffer append(char c) {
341 super.append(c);
342 return this;
343 }
344
345 public synchronized StringBuffer append(int i) {
346 super.append(i);
347 return this;
348 }
349
350 /**
351 * @since 1.5
352 */
353 public synchronized StringBuffer appendCodePoint(int codePoint) {
354 super.appendCodePoint(codePoint);
355 return this;
356 }
357
358 public synchronized StringBuffer append(long lng) {
359 super.append(lng);
360 return this;
361 }
362
363 public synchronized StringBuffer append(float f) {
364 super.append(f);
365 return this;
366 }
367
368 public synchronized StringBuffer append(double d) {
369 super.append(d);
370 return this;
371 }
372
373 /**
374 * @throws StringIndexOutOfBoundsException {@inheritDoc}
375 * @since 1.2
376 */
377 public synchronized StringBuffer delete(int start, int end) {
378 super.delete(start, end);
379 return this;
380 }
381
382 /**
383 * @throws StringIndexOutOfBoundsException {@inheritDoc}
384 * @since 1.2
385 */
386 public synchronized StringBuffer deleteCharAt(int index) {
387 super.deleteCharAt(index);
388 return this;
389 }
390
391 /**
392 * @throws StringIndexOutOfBoundsException {@inheritDoc}
393 * @since 1.2
394 */
395 public synchronized StringBuffer replace(int start, int end, String str) {
396 super.replace(start, end, str);
397 return this;
398 }
399
400 /**
401 * @throws StringIndexOutOfBoundsException {@inheritDoc}
402 * @since 1.2
403 */
404 public synchronized String substring(int start) {
405 return substring(start, count);
406 }
407
408 /**
409 * @throws IndexOutOfBoundsException {@inheritDoc}
410 * @since 1.4
411 */
412 public synchronized CharSequence subSequence(int start, int end) {
413 return super.substring(start, end);
414 }
415
416 /**
417 * @throws StringIndexOutOfBoundsException {@inheritDoc}
418 * @since 1.2
419 */
420 public synchronized String substring(int start, int end) {
421 return super.substring(start, end);
422 }
423
424 /**
425 * @throws StringIndexOutOfBoundsException {@inheritDoc}
426 * @since 1.2
427 */
428 public synchronized StringBuffer insert(int index, char[] str, int offset,
429 int len)
430 {
431 super.insert(index, str, offset, len);
432 return this;
433 }
434
435 /**
436 * @throws StringIndexOutOfBoundsException {@inheritDoc}
437 */
438 public synchronized StringBuffer insert(int offset, Object obj) {
439 super.insert(offset, String.valueOf(obj));
440 return this;
441 }
442
443 /**
444 * @throws StringIndexOutOfBoundsException {@inheritDoc}
445 */
446 public synchronized StringBuffer insert(int offset, String str) {
447 super.insert(offset, str);
448 return this;
449 }
450
451 /**
452 * @throws StringIndexOutOfBoundsException {@inheritDoc}
453 */
454 public synchronized StringBuffer insert(int offset, char[] str) {
455 super.insert(offset, str);
456 return this;
457 }
458
459 /**
460 * @throws IndexOutOfBoundsException {@inheritDoc}
461 * @since 1.5
462 */
463 public StringBuffer insert(int dstOffset, CharSequence s) {
464 // Note, synchronization achieved via other invocations
465 if (s == null)
466 s = "null";
467 if (s instanceof String)
468 return this.insert(dstOffset, (String)s);
469 return this.insert(dstOffset, s, 0, s.length());
470 }
471
472 /**
473 * @throws IndexOutOfBoundsException {@inheritDoc}
474 * @since 1.5
475 */
476 public synchronized StringBuffer insert(int dstOffset, CharSequence s,
477 int start, int end)
478 {
479 super.insert(dstOffset, s, start, end);
480 return this;
481 }
482
483 /**
484 * @throws StringIndexOutOfBoundsException {@inheritDoc}
485 */
486 public StringBuffer insert(int offset, boolean b) {
487 return insert(offset, String.valueOf(b));
488 }
489
490 /**
491 * @throws IndexOutOfBoundsException {@inheritDoc}
492 */
493 public synchronized StringBuffer insert(int offset, char c) {
494 super.insert(offset, c);
495 return this;
496 }
497
498 /**
499 * @throws StringIndexOutOfBoundsException {@inheritDoc}
500 */
501 public StringBuffer insert(int offset, int i) {
502 return insert(offset, String.valueOf(i));
503 }
504
505 /**
506 * @throws StringIndexOutOfBoundsException {@inheritDoc}
507 */
508 public StringBuffer insert(int offset, long l) {
509 return insert(offset, String.valueOf(l));
510 }
511
512 /**
513 * @throws StringIndexOutOfBoundsException {@inheritDoc}
514 */
515 public StringBuffer insert(int offset, float f) {
516 return insert(offset, String.valueOf(f));
517 }
518
519 /**
520 * @throws StringIndexOutOfBoundsException {@inheritDoc}
521 */
522 public StringBuffer insert(int offset, double d) {
523 return insert(offset, String.valueOf(d));
524 }
525
526 /**
527 * @throws NullPointerException {@inheritDoc}
528 * @since 1.4
529 */
530 public int indexOf(String str) {
531 return indexOf(str, 0);
532 }
533
534 /**
535 * @throws NullPointerException {@inheritDoc}
536 * @since 1.4
537 */
538 public synchronized int indexOf(String str, int fromIndex) {
539 return String.indexOf(value, 0, count,
540 str.toCharArray(), 0, str.length(), fromIndex);
541 }
542
543 /**
544 * @throws NullPointerException {@inheritDoc}
545 * @since 1.4
546 */
547 public int lastIndexOf(String str) {
548 // Note, synchronization achieved via other invocations
549 return lastIndexOf(str, count);
550 }
551
552 /**
553 * @throws NullPointerException {@inheritDoc}
554 * @since 1.4
555 */
556 public synchronized int lastIndexOf(String str, int fromIndex) {
557 return String.lastIndexOf(value, 0, count,
558 str.toCharArray(), 0, str.length(), fromIndex);
559 }
560
561 /**
562 * @since JDK1.0.2
563 */
564 public synchronized StringBuffer reverse() {
565 super.reverse();
566 return this;
567 }
568
569 public synchronized String toString() {
570 return new String(value, 0, count);
571 }
572
573 /**
574 * Serializable fields for StringBuffer.
575 *
576 * @serialField value char[]
577 * The backing character array of this StringBuffer.
578 * @serialField count int
579 * The number of characters in this StringBuffer.
580 * @serialField shared boolean
581 * A flag indicating whether the backing array is shared.
582 * The value is ignored upon deserialization.
583 */
584 private static final java.io.ObjectStreamField[] serialPersistentFields =
585 {
586 new java.io.ObjectStreamField("value", char[].class),
587 new java.io.ObjectStreamField("count", Integer.TYPE),
588 new java.io.ObjectStreamField("shared", Boolean.TYPE),
|
132
133 /**
134 * Constructs a string buffer that contains the same characters
135 * as the specified {@code CharSequence}. The initial capacity of
136 * the string buffer is {@code 16} plus the length of the
137 * {@code CharSequence} argument.
138 * <p>
139 * If the length of the specified {@code CharSequence} is
140 * less than or equal to zero, then an empty buffer of capacity
141 * {@code 16} is returned.
142 *
143 * @param seq the sequence to copy.
144 * @exception NullPointerException if {@code seq} is {@code null}
145 * @since 1.5
146 */
147 public StringBuffer(CharSequence seq) {
148 this(seq.length() + 16);
149 append(seq);
150 }
151
152 @Override
153 public synchronized int length() {
154 return count;
155 }
156
157 @Override
158 public synchronized int capacity() {
159 return value.length;
160 }
161
162
163 @Override
164 public synchronized void ensureCapacity(int minimumCapacity) {
165 if (minimumCapacity > value.length) {
166 expandCapacity(minimumCapacity);
167 }
168 }
169
170 /**
171 * @since 1.5
172 */
173 @Override
174 public synchronized void trimToSize() {
175 super.trimToSize();
176 }
177
178 /**
179 * @throws IndexOutOfBoundsException {@inheritDoc}
180 * @see #length()
181 */
182 @Override
183 public synchronized void setLength(int newLength) {
184 super.setLength(newLength);
185 }
186
187 /**
188 * @throws IndexOutOfBoundsException {@inheritDoc}
189 * @see #length()
190 */
191 @Override
192 public synchronized char charAt(int index) {
193 if ((index < 0) || (index >= count))
194 throw new StringIndexOutOfBoundsException(index);
195 return value[index];
196 }
197
198 /**
199 * @since 1.5
200 */
201 @Override
202 public synchronized int codePointAt(int index) {
203 return super.codePointAt(index);
204 }
205
206 /**
207 * @since 1.5
208 */
209 @Override
210 public synchronized int codePointBefore(int index) {
211 return super.codePointBefore(index);
212 }
213
214 /**
215 * @since 1.5
216 */
217 @Override
218 public synchronized int codePointCount(int beginIndex, int endIndex) {
219 return super.codePointCount(beginIndex, endIndex);
220 }
221
222 /**
223 * @since 1.5
224 */
225 @Override
226 public synchronized int offsetByCodePoints(int index, int codePointOffset) {
227 return super.offsetByCodePoints(index, codePointOffset);
228 }
229
230 /**
231 * @throws NullPointerException {@inheritDoc}
232 * @throws IndexOutOfBoundsException {@inheritDoc}
233 */
234 @Override
235 public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
236 int dstBegin)
237 {
238 super.getChars(srcBegin, srcEnd, dst, dstBegin);
239 }
240
241 /**
242 * @throws IndexOutOfBoundsException {@inheritDoc}
243 * @see #length()
244 */
245 @Override
246 public synchronized void setCharAt(int index, char ch) {
247 if ((index < 0) || (index >= count))
248 throw new StringIndexOutOfBoundsException(index);
249 value[index] = ch;
250 }
251
252 @Override
253 public synchronized StringBuffer append(Object obj) {
254 super.append(String.valueOf(obj));
255 return this;
256 }
257
258 @Override
259 public synchronized StringBuffer append(String str) {
260 super.append(str);
261 return this;
262 }
263
264 /**
265 * Appends the specified <tt>StringBuffer</tt> to this sequence.
266 * <p>
267 * The characters of the <tt>StringBuffer</tt> argument are appended,
268 * in order, to the contents of this <tt>StringBuffer</tt>, increasing the
269 * length of this <tt>StringBuffer</tt> by the length of the argument.
270 * If <tt>sb</tt> is <tt>null</tt>, then the four characters
271 * <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
272 * <p>
273 * Let <i>n</i> be the length of the old character sequence, the one
274 * contained in the <tt>StringBuffer</tt> just prior to execution of the
275 * <tt>append</tt> method. Then the character at index <i>k</i> in
276 * the new character sequence is equal to the character at index <i>k</i>
277 * in the old character sequence, if <i>k</i> is less than <i>n</i>;
278 * otherwise, it is equal to the character at index <i>k-n</i> in the
279 * argument {@code sb}.
280 * <p>
281 * This method synchronizes on {@code this}, the destination
282 * object, but does not synchronize on the source ({@code sb}).
283 *
284 * @param sb the <tt>StringBuffer</tt> to append.
285 * @return a reference to this object.
286 * @since 1.4
287 */
288 public synchronized StringBuffer append(StringBuffer sb) {
289 super.append(sb);
290 return this;
291 }
292
293 /**
294 * @since 1.8
295 */
296 @Override
297 synchronized StringBuffer append(AbstractStringBuilder asb) {
298 super.append(asb);
299 return this;
300 }
301
302 /**
303 * Appends the specified {@code CharSequence} to this
304 * sequence.
305 * <p>
306 * The characters of the {@code CharSequence} argument are appended,
307 * in order, increasing the length of this sequence by the length of the
308 * argument.
309 *
310 * <p>The result of this method is exactly the same as if it were an
311 * invocation of this.append(s, 0, s.length());
312 *
313 * <p>This method synchronizes on {@code this}, the destination
314 * object, but does not synchronize on the source ({@code s}).
315 *
316 * <p>If {@code s} is {@code null}, then the four characters
317 * {@code "null"} are appended.
318 *
319 * @param s the {@code CharSequence} to append.
320 * @return a reference to this object.
321 * @since 1.5
322 */
323 @Override
324 public StringBuffer append(CharSequence s) {
325 // Note, synchronization achieved via invocations of other StringBuffer methods after
326 // narrowing of s to specific type
327 super.append(s);
328 return this;
329 }
330
331 /**
332 * @throws IndexOutOfBoundsException {@inheritDoc}
333 * @since 1.5
334 */
335 @Override
336 public synchronized StringBuffer append(CharSequence s, int start, int end)
337 {
338 super.append(s, start, end);
339 return this;
340 }
341
342 @Override
343 public synchronized StringBuffer append(char[] str) {
344 super.append(str);
345 return this;
346 }
347
348 /**
349 * @throws IndexOutOfBoundsException {@inheritDoc}
350 */
351 @Override
352 public synchronized StringBuffer append(char[] str, int offset, int len) {
353 super.append(str, offset, len);
354 return this;
355 }
356
357 @Override
358 public synchronized StringBuffer append(boolean b) {
359 super.append(b);
360 return this;
361 }
362
363 @Override
364 public synchronized StringBuffer append(char c) {
365 super.append(c);
366 return this;
367 }
368
369 @Override
370 public synchronized StringBuffer append(int i) {
371 super.append(i);
372 return this;
373 }
374
375 /**
376 * @since 1.5
377 */
378 @Override
379 public synchronized StringBuffer appendCodePoint(int codePoint) {
380 super.appendCodePoint(codePoint);
381 return this;
382 }
383
384 @Override
385 public synchronized StringBuffer append(long lng) {
386 super.append(lng);
387 return this;
388 }
389
390 @Override
391 public synchronized StringBuffer append(float f) {
392 super.append(f);
393 return this;
394 }
395
396 @Override
397 public synchronized StringBuffer append(double d) {
398 super.append(d);
399 return this;
400 }
401
402 /**
403 * @throws StringIndexOutOfBoundsException {@inheritDoc}
404 * @since 1.2
405 */
406 @Override
407 public synchronized StringBuffer delete(int start, int end) {
408 super.delete(start, end);
409 return this;
410 }
411
412 /**
413 * @throws StringIndexOutOfBoundsException {@inheritDoc}
414 * @since 1.2
415 */
416 @Override
417 public synchronized StringBuffer deleteCharAt(int index) {
418 super.deleteCharAt(index);
419 return this;
420 }
421
422 /**
423 * @throws StringIndexOutOfBoundsException {@inheritDoc}
424 * @since 1.2
425 */
426 @Override
427 public synchronized StringBuffer replace(int start, int end, String str) {
428 super.replace(start, end, str);
429 return this;
430 }
431
432 /**
433 * @throws StringIndexOutOfBoundsException {@inheritDoc}
434 * @since 1.2
435 */
436 @Override
437 public synchronized String substring(int start) {
438 return substring(start, count);
439 }
440
441 /**
442 * @throws IndexOutOfBoundsException {@inheritDoc}
443 * @since 1.4
444 */
445 @Override
446 public synchronized CharSequence subSequence(int start, int end) {
447 return super.substring(start, end);
448 }
449
450 /**
451 * @throws StringIndexOutOfBoundsException {@inheritDoc}
452 * @since 1.2
453 */
454 @Override
455 public synchronized String substring(int start, int end) {
456 return super.substring(start, end);
457 }
458
459 /**
460 * @throws StringIndexOutOfBoundsException {@inheritDoc}
461 * @since 1.2
462 */
463 @Override
464 public synchronized StringBuffer insert(int index, char[] str, int offset,
465 int len)
466 {
467 super.insert(index, str, offset, len);
468 return this;
469 }
470
471 /**
472 * @throws StringIndexOutOfBoundsException {@inheritDoc}
473 */
474 @Override
475 public synchronized StringBuffer insert(int offset, Object obj) {
476 super.insert(offset, String.valueOf(obj));
477 return this;
478 }
479
480 /**
481 * @throws StringIndexOutOfBoundsException {@inheritDoc}
482 */
483 @Override
484 public synchronized StringBuffer insert(int offset, String str) {
485 super.insert(offset, str);
486 return this;
487 }
488
489 /**
490 * @throws StringIndexOutOfBoundsException {@inheritDoc}
491 */
492 @Override
493 public synchronized StringBuffer insert(int offset, char[] str) {
494 super.insert(offset, str);
495 return this;
496 }
497
498 /**
499 * @throws IndexOutOfBoundsException {@inheritDoc}
500 * @since 1.5
501 */
502 @Override
503 public StringBuffer insert(int dstOffset, CharSequence s) {
504 // Note, synchronization achieved via invocations of other StringBuffer methods
505 // after narrowing of s to specific type
506 super.insert(dstOffset, s);
507 return this;
508 }
509
510 /**
511 * @throws IndexOutOfBoundsException {@inheritDoc}
512 * @since 1.5
513 */
514 @Override
515 public synchronized StringBuffer insert(int dstOffset, CharSequence s,
516 int start, int end)
517 {
518 super.insert(dstOffset, s, start, end);
519 return this;
520 }
521
522 /**
523 * @throws StringIndexOutOfBoundsException {@inheritDoc}
524 */
525 @Override
526 public StringBuffer insert(int offset, boolean b) {
527 // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
528 // after conversion of b to String by super class method
529 super.insert(offset, b);
530 return this;
531 }
532
533 /**
534 * @throws IndexOutOfBoundsException {@inheritDoc}
535 */
536 @Override
537 public synchronized StringBuffer insert(int offset, char c) {
538 super.insert(offset, c);
539 return this;
540 }
541
542 /**
543 * @throws StringIndexOutOfBoundsException {@inheritDoc}
544 */
545 @Override
546 public StringBuffer insert(int offset, int i) {
547 // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
548 // after conversion of i to String by super class method
549 super.insert(offset, i);
550 return this;
551 }
552
553 /**
554 * @throws StringIndexOutOfBoundsException {@inheritDoc}
555 */
556 @Override
557 public StringBuffer insert(int offset, long l) {
558 // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
559 // after conversion of l to String by super class method
560 super.insert(offset, l);
561 return this;
562 }
563
564 /**
565 * @throws StringIndexOutOfBoundsException {@inheritDoc}
566 */
567 @Override
568 public StringBuffer insert(int offset, float f) {
569 // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
570 // after conversion of f to String by super class method
571 super.insert(offset, f);
572 return this;
573 }
574
575 /**
576 * @throws StringIndexOutOfBoundsException {@inheritDoc}
577 */
578 @Override
579 public StringBuffer insert(int offset, double d) {
580 // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
581 // after conversion of d to String by super class method
582 super.insert(offset, d);
583 return this;
584 }
585
586 /**
587 * @throws NullPointerException {@inheritDoc}
588 * @since 1.4
589 */
590 @Override
591 public int indexOf(String str) {
592 // Note, synchronization achieved via invocations of other StringBuffer methods
593 return super.indexOf(str);
594 }
595
596 /**
597 * @throws NullPointerException {@inheritDoc}
598 * @since 1.4
599 */
600 @Override
601 public synchronized int indexOf(String str, int fromIndex) {
602 return super.indexOf(str, fromIndex);
603 }
604
605 /**
606 * @throws NullPointerException {@inheritDoc}
607 * @since 1.4
608 */
609 @Override
610 public int lastIndexOf(String str) {
611 // Note, synchronization achieved via invocations of other StringBuffer methods
612 return lastIndexOf(str, count);
613 }
614
615 /**
616 * @throws NullPointerException {@inheritDoc}
617 * @since 1.4
618 */
619 @Override
620 public synchronized int lastIndexOf(String str, int fromIndex) {
621 return super.lastIndexOf(str, fromIndex);
622 }
623
624 /**
625 * @since JDK1.0.2
626 */
627 @Override
628 public synchronized StringBuffer reverse() {
629 super.reverse();
630 return this;
631 }
632
633 @Override
634 public synchronized String toString() {
635 return new String(value, 0, count);
636 }
637
638 /**
639 * Serializable fields for StringBuffer.
640 *
641 * @serialField value char[]
642 * The backing character array of this StringBuffer.
643 * @serialField count int
644 * The number of characters in this StringBuffer.
645 * @serialField shared boolean
646 * A flag indicating whether the backing array is shared.
647 * The value is ignored upon deserialization.
648 */
649 private static final java.io.ObjectStreamField[] serialPersistentFields =
650 {
651 new java.io.ObjectStreamField("value", char[].class),
652 new java.io.ObjectStreamField("count", Integer.TYPE),
653 new java.io.ObjectStreamField("shared", Boolean.TYPE),
|