< prev index next >

src/java.base/share/classes/java/lang/StringBuffer.java

Print this page
rev 13124 : [mq]: XXXXXXX-ASB-shared-value


  83  * Unless otherwise noted, passing a {@code null} argument to a constructor
  84  * or method in this class will cause a {@link NullPointerException} to be
  85  * thrown.
  86  * <p>
  87  * As of  release JDK 5, this class has been supplemented with an equivalent
  88  * class designed for use by a single thread, {@link StringBuilder}.  The
  89  * {@code StringBuilder} class should generally be used in preference to
  90  * this one, as it supports all of the same operations but it is faster, as
  91  * it performs no synchronization.
  92  *
  93  * @author      Arthur van Hoff
  94  * @see     java.lang.StringBuilder
  95  * @see     java.lang.String
  96  * @since   1.0
  97  */
  98  public final class StringBuffer
  99     extends AbstractStringBuilder
 100     implements java.io.Serializable, CharSequence
 101 {
 102 
 103     /**
 104      * A cache of the last value returned by toString. Cleared
 105      * whenever the StringBuffer is modified.
 106      */
 107     private transient String toStringCache;
 108 
 109     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 110     static final long serialVersionUID = 3388685877147921107L;
 111 
 112     /**
 113      * Constructs a string buffer with no characters in it and an
 114      * initial capacity of 16 characters.
 115      */
 116     @HotSpotIntrinsicCandidate
 117     public StringBuffer() {
 118         super(16);
 119     }
 120 
 121     /**
 122      * Constructs a string buffer with no characters in it and
 123      * the specified initial capacity.
 124      *
 125      * @param      capacity  the initial capacity.
 126      * @exception  NegativeArraySizeException  if the {@code capacity}
 127      *               argument is less than {@code 0}.
 128      */


 175 
 176     @Override
 177     public synchronized void ensureCapacity(int minimumCapacity) {
 178         super.ensureCapacity(minimumCapacity);
 179     }
 180 
 181     /**
 182      * @since      1.5
 183      */
 184     @Override
 185     public synchronized void trimToSize() {
 186         super.trimToSize();
 187     }
 188 
 189     /**
 190      * @throws IndexOutOfBoundsException {@inheritDoc}
 191      * @see        #length()
 192      */
 193     @Override
 194     public synchronized void setLength(int newLength) {
 195         toStringCache = null;
 196         super.setLength(newLength);
 197     }
 198 
 199     /**
 200      * @throws IndexOutOfBoundsException {@inheritDoc}
 201      * @see        #length()
 202      */
 203     @Override
 204     public synchronized char charAt(int index) {
 205         return super.charAt(index);
 206     }
 207 
 208     /**
 209      * @throws IndexOutOfBoundsException {@inheritDoc}
 210      * @since      1.5
 211      */
 212     @Override
 213     public synchronized int codePointAt(int index) {
 214         return super.codePointAt(index);
 215     }


 240     public synchronized int offsetByCodePoints(int index, int codePointOffset) {
 241         return super.offsetByCodePoints(index, codePointOffset);
 242     }
 243 
 244     /**
 245      * @throws IndexOutOfBoundsException {@inheritDoc}
 246      */
 247     @Override
 248     public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
 249                                       int dstBegin)
 250     {
 251         super.getChars(srcBegin, srcEnd, dst, dstBegin);
 252     }
 253 
 254     /**
 255      * @throws IndexOutOfBoundsException {@inheritDoc}
 256      * @see        #length()
 257      */
 258     @Override
 259     public synchronized void setCharAt(int index, char ch) {
 260         toStringCache = null;
 261         super.setCharAt(index, ch);
 262     }
 263 
 264     @Override
 265     public synchronized StringBuffer append(Object obj) {
 266         toStringCache = null;
 267         super.append(String.valueOf(obj));
 268         return this;
 269     }
 270 
 271     @Override
 272     @HotSpotIntrinsicCandidate
 273     public synchronized StringBuffer append(String str) {
 274         toStringCache = null;
 275         super.append(str);
 276         return this;
 277     }
 278 
 279     /**
 280      * Appends the specified {@code StringBuffer} to this sequence.
 281      * <p>
 282      * The characters of the {@code StringBuffer} argument are appended,
 283      * in order, to the contents of this {@code StringBuffer}, increasing the
 284      * length of this {@code StringBuffer} by the length of the argument.
 285      * If {@code sb} is {@code null}, then the four characters
 286      * {@code "null"} are appended to this {@code StringBuffer}.
 287      * <p>
 288      * Let <i>n</i> be the length of the old character sequence, the one
 289      * contained in the {@code StringBuffer} just prior to execution of the
 290      * {@code append} method. Then the character at index <i>k</i> in
 291      * the new character sequence is equal to the character at index <i>k</i>
 292      * in the old character sequence, if <i>k</i> is less than <i>n</i>;
 293      * otherwise, it is equal to the character at index <i>k-n</i> in the
 294      * argument {@code sb}.
 295      * <p>
 296      * This method synchronizes on {@code this}, the destination
 297      * object, but does not synchronize on the source ({@code sb}).
 298      *
 299      * @param   sb   the {@code StringBuffer} to append.
 300      * @return  a reference to this object.
 301      * @since 1.4
 302      */
 303     public synchronized StringBuffer append(StringBuffer sb) {
 304         toStringCache = null;
 305         super.append(sb);
 306         return this;
 307     }
 308 
 309     /**
 310      * @since 1.8
 311      */
 312     @Override
 313     synchronized StringBuffer append(AbstractStringBuilder asb) {
 314         toStringCache = null;
 315         super.append(asb);
 316         return this;
 317     }
 318 
 319     /**
 320      * Appends the specified {@code CharSequence} to this
 321      * sequence.
 322      * <p>
 323      * The characters of the {@code CharSequence} argument are appended,
 324      * in order, increasing the length of this sequence by the length of the
 325      * argument.
 326      *
 327      * <p>The result of this method is exactly the same as if it were an
 328      * invocation of this.append(s, 0, s.length());
 329      *
 330      * <p>This method synchronizes on {@code this}, the destination
 331      * object, but does not synchronize on the source ({@code s}).
 332      *
 333      * <p>If {@code s} is {@code null}, then the four characters
 334      * {@code "null"} are appended.
 335      *
 336      * @param   s the {@code CharSequence} to append.
 337      * @return  a reference to this object.
 338      * @since 1.5
 339      */
 340     @Override
 341     public synchronized StringBuffer append(CharSequence s) {
 342         toStringCache = null;
 343         super.append(s);
 344         return this;
 345     }
 346 
 347     /**
 348      * @throws IndexOutOfBoundsException {@inheritDoc}
 349      * @since      1.5
 350      */
 351     @Override
 352     public synchronized StringBuffer append(CharSequence s, int start, int end)
 353     {
 354         toStringCache = null;
 355         super.append(s, start, end);
 356         return this;
 357     }
 358 
 359     @Override
 360     public synchronized StringBuffer append(char[] str) {
 361         toStringCache = null;
 362         super.append(str);
 363         return this;
 364     }
 365 
 366     /**
 367      * @throws IndexOutOfBoundsException {@inheritDoc}
 368      */
 369     @Override
 370     public synchronized StringBuffer append(char[] str, int offset, int len) {
 371         toStringCache = null;
 372         super.append(str, offset, len);
 373         return this;
 374     }
 375 
 376     @Override
 377     public synchronized StringBuffer append(boolean b) {
 378         toStringCache = null;
 379         super.append(b);
 380         return this;
 381     }
 382 
 383     @Override
 384     @HotSpotIntrinsicCandidate
 385     public synchronized StringBuffer append(char c) {
 386         toStringCache = null;
 387         super.append(c);
 388         return this;
 389     }
 390 
 391     @Override
 392     @HotSpotIntrinsicCandidate
 393     public synchronized StringBuffer append(int i) {
 394         toStringCache = null;
 395         super.append(i);
 396         return this;
 397     }
 398 
 399     /**
 400      * @since 1.5
 401      */
 402     @Override
 403     public synchronized StringBuffer appendCodePoint(int codePoint) {
 404         toStringCache = null;
 405         super.appendCodePoint(codePoint);
 406         return this;
 407     }
 408 
 409     @Override
 410     public synchronized StringBuffer append(long lng) {
 411         toStringCache = null;
 412         super.append(lng);
 413         return this;
 414     }
 415 
 416     @Override
 417     public synchronized StringBuffer append(float f) {
 418         toStringCache = null;
 419         super.append(f);
 420         return this;
 421     }
 422 
 423     @Override
 424     public synchronized StringBuffer append(double d) {
 425         toStringCache = null;
 426         super.append(d);
 427         return this;
 428     }
 429 
 430     /**
 431      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 432      * @since      1.2
 433      */
 434     @Override
 435     public synchronized StringBuffer delete(int start, int end) {
 436         toStringCache = null;
 437         super.delete(start, end);
 438         return this;
 439     }
 440 
 441     /**
 442      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 443      * @since      1.2
 444      */
 445     @Override
 446     public synchronized StringBuffer deleteCharAt(int index) {
 447         toStringCache = null;
 448         super.deleteCharAt(index);
 449         return this;
 450     }
 451 
 452     /**
 453      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 454      * @since      1.2
 455      */
 456     @Override
 457     public synchronized StringBuffer replace(int start, int end, String str) {
 458         toStringCache = null;
 459         super.replace(start, end, str);
 460         return this;
 461     }
 462 
 463     /**
 464      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 465      * @since      1.2
 466      */
 467     @Override
 468     public synchronized String substring(int start) {
 469         return substring(start, count);
 470     }
 471 
 472     /**
 473      * @throws IndexOutOfBoundsException {@inheritDoc}
 474      * @since      1.4
 475      */
 476     @Override
 477     public synchronized CharSequence subSequence(int start, int end) {
 478         return super.substring(start, end);
 479     }
 480 
 481     /**
 482      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 483      * @since      1.2
 484      */
 485     @Override
 486     public synchronized String substring(int start, int end) {
 487         return super.substring(start, end);
 488     }
 489 
 490     /**
 491      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 492      * @since      1.2
 493      */
 494     @Override
 495     public synchronized StringBuffer insert(int index, char[] str, int offset,
 496                                             int len)
 497     {
 498         toStringCache = null;
 499         super.insert(index, str, offset, len);
 500         return this;
 501     }
 502 
 503     /**
 504      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 505      */
 506     @Override
 507     public synchronized StringBuffer insert(int offset, Object obj) {
 508         toStringCache = null;
 509         super.insert(offset, String.valueOf(obj));
 510         return this;
 511     }
 512 
 513     /**
 514      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 515      */
 516     @Override
 517     public synchronized StringBuffer insert(int offset, String str) {
 518         toStringCache = null;
 519         super.insert(offset, str);
 520         return this;
 521     }
 522 
 523     /**
 524      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 525      */
 526     @Override
 527     public synchronized StringBuffer insert(int offset, char[] str) {
 528         toStringCache = null;
 529         super.insert(offset, str);
 530         return this;
 531     }
 532 
 533     /**
 534      * @throws IndexOutOfBoundsException {@inheritDoc}
 535      * @since      1.5
 536      */
 537     @Override
 538     public StringBuffer insert(int dstOffset, CharSequence s) {
 539         // Note, synchronization achieved via invocations of other StringBuffer methods
 540         // after narrowing of s to specific type
 541         // Ditto for toStringCache clearing
 542         super.insert(dstOffset, s);
 543         return this;
 544     }
 545 
 546     /**
 547      * @throws IndexOutOfBoundsException {@inheritDoc}
 548      * @since      1.5
 549      */
 550     @Override
 551     public synchronized StringBuffer insert(int dstOffset, CharSequence s,
 552             int start, int end)
 553     {
 554         toStringCache = null;
 555         super.insert(dstOffset, s, start, end);
 556         return this;
 557     }
 558 
 559     /**
 560      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 561      */
 562     @Override
 563     public  StringBuffer insert(int offset, boolean b) {
 564         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 565         // after conversion of b to String by super class method
 566         // Ditto for toStringCache clearing
 567         super.insert(offset, b);
 568         return this;
 569     }
 570 
 571     /**
 572      * @throws IndexOutOfBoundsException {@inheritDoc}
 573      */
 574     @Override
 575     public synchronized StringBuffer insert(int offset, char c) {
 576         toStringCache = null;
 577         super.insert(offset, c);
 578         return this;
 579     }
 580 
 581     /**
 582      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 583      */
 584     @Override
 585     public StringBuffer insert(int offset, int i) {
 586         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 587         // after conversion of i to String by super class method
 588         // Ditto for toStringCache clearing
 589         super.insert(offset, i);
 590         return this;
 591     }
 592 
 593     /**
 594      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 595      */
 596     @Override
 597     public StringBuffer insert(int offset, long l) {
 598         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 599         // after conversion of l to String by super class method
 600         // Ditto for toStringCache clearing
 601         super.insert(offset, l);
 602         return this;
 603     }
 604 
 605     /**
 606      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 607      */
 608     @Override
 609     public StringBuffer insert(int offset, float f) {
 610         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 611         // after conversion of f to String by super class method
 612         // Ditto for toStringCache clearing
 613         super.insert(offset, f);
 614         return this;
 615     }
 616 
 617     /**
 618      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 619      */
 620     @Override
 621     public StringBuffer insert(int offset, double d) {
 622         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 623         // after conversion of d to String by super class method
 624         // Ditto for toStringCache clearing
 625         super.insert(offset, d);
 626         return this;
 627     }
 628 
 629     /**
 630      * @since      1.4
 631      */
 632     @Override
 633     public int indexOf(String str) {
 634         // Note, synchronization achieved via invocations of other StringBuffer methods
 635         return super.indexOf(str);
 636     }
 637 
 638     /**
 639      * @since      1.4
 640      */
 641     @Override
 642     public synchronized int indexOf(String str, int fromIndex) {
 643         return super.indexOf(str, fromIndex);
 644     }


 648      */
 649     @Override
 650     public int lastIndexOf(String str) {
 651         // Note, synchronization achieved via invocations of other StringBuffer methods
 652         return lastIndexOf(str, count);
 653     }
 654 
 655     /**
 656      * @since      1.4
 657      */
 658     @Override
 659     public synchronized int lastIndexOf(String str, int fromIndex) {
 660         return super.lastIndexOf(str, fromIndex);
 661     }
 662 
 663     /**
 664      * @since   1.0.2
 665      */
 666     @Override
 667     public synchronized StringBuffer reverse() {
 668         toStringCache = null;
 669         super.reverse();
 670         return this;
 671     }
 672 
 673     @Override
 674     @HotSpotIntrinsicCandidate
 675     public synchronized String toString() {
 676         if (toStringCache == null) {
 677             return toStringCache =
 678                     isLatin1() ? StringLatin1.newString(value, 0, count)
 679                                : StringUTF16.newString(value, 0, count);



 680         }
 681         return new String(toStringCache);
 682     }
 683 
 684     /**
 685      * Serializable fields for StringBuffer.
 686      *
 687      * @serialField value  char[]
 688      *              The backing character array of this StringBuffer.
 689      * @serialField count int
 690      *              The number of characters in this StringBuffer.
 691      * @serialField shared  boolean
 692      *              A flag indicating whether the backing array is shared.
 693      *              The value is ignored upon deserialization.
 694      */
 695     private static final java.io.ObjectStreamField[] serialPersistentFields =
 696     {
 697         new java.io.ObjectStreamField("value", char[].class),
 698         new java.io.ObjectStreamField("count", Integer.TYPE),
 699         new java.io.ObjectStreamField("shared", Boolean.TYPE),
 700     };
 701 


 711             StringLatin1.getChars(value, 0, count, val, 0);
 712         } else {
 713             StringUTF16.getChars(value, 0, count, val, 0);
 714         }
 715         fields.put("value", val);
 716         fields.put("count", count);
 717         fields.put("shared", false);
 718         s.writeFields();
 719     }
 720 
 721     /**
 722      * readObject is called to restore the state of the StringBuffer from
 723      * a stream.
 724      */
 725     private void readObject(java.io.ObjectInputStream s)
 726         throws java.io.IOException, ClassNotFoundException {
 727         java.io.ObjectInputStream.GetField fields = s.readFields();
 728         char[] val = (char[])fields.get("value", null);
 729         initBytes(val, 0, val.length);
 730         count = fields.get("count", 0);

 731     }
 732 
 733     synchronized void getBytes(byte dst[], int dstBegin, byte coder) {
 734         super.getBytes(dst, dstBegin, coder);
 735     }
 736 }


  83  * Unless otherwise noted, passing a {@code null} argument to a constructor
  84  * or method in this class will cause a {@link NullPointerException} to be
  85  * thrown.
  86  * <p>
  87  * As of  release JDK 5, this class has been supplemented with an equivalent
  88  * class designed for use by a single thread, {@link StringBuilder}.  The
  89  * {@code StringBuilder} class should generally be used in preference to
  90  * this one, as it supports all of the same operations but it is faster, as
  91  * it performs no synchronization.
  92  *
  93  * @author      Arthur van Hoff
  94  * @see     java.lang.StringBuilder
  95  * @see     java.lang.String
  96  * @since   1.0
  97  */
  98  public final class StringBuffer
  99     extends AbstractStringBuilder
 100     implements java.io.Serializable, CharSequence
 101 {
 102 






 103     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 104     static final long serialVersionUID = 3388685877147921107L;
 105 
 106     /**
 107      * Constructs a string buffer with no characters in it and an
 108      * initial capacity of 16 characters.
 109      */
 110     @HotSpotIntrinsicCandidate
 111     public StringBuffer() {
 112         super(16);
 113     }
 114 
 115     /**
 116      * Constructs a string buffer with no characters in it and
 117      * the specified initial capacity.
 118      *
 119      * @param      capacity  the initial capacity.
 120      * @exception  NegativeArraySizeException  if the {@code capacity}
 121      *               argument is less than {@code 0}.
 122      */


 169 
 170     @Override
 171     public synchronized void ensureCapacity(int minimumCapacity) {
 172         super.ensureCapacity(minimumCapacity);
 173     }
 174 
 175     /**
 176      * @since      1.5
 177      */
 178     @Override
 179     public synchronized void trimToSize() {
 180         super.trimToSize();
 181     }
 182 
 183     /**
 184      * @throws IndexOutOfBoundsException {@inheritDoc}
 185      * @see        #length()
 186      */
 187     @Override
 188     public synchronized void setLength(int newLength) {

 189         super.setLength(newLength);
 190     }
 191 
 192     /**
 193      * @throws IndexOutOfBoundsException {@inheritDoc}
 194      * @see        #length()
 195      */
 196     @Override
 197     public synchronized char charAt(int index) {
 198         return super.charAt(index);
 199     }
 200 
 201     /**
 202      * @throws IndexOutOfBoundsException {@inheritDoc}
 203      * @since      1.5
 204      */
 205     @Override
 206     public synchronized int codePointAt(int index) {
 207         return super.codePointAt(index);
 208     }


 233     public synchronized int offsetByCodePoints(int index, int codePointOffset) {
 234         return super.offsetByCodePoints(index, codePointOffset);
 235     }
 236 
 237     /**
 238      * @throws IndexOutOfBoundsException {@inheritDoc}
 239      */
 240     @Override
 241     public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
 242                                       int dstBegin)
 243     {
 244         super.getChars(srcBegin, srcEnd, dst, dstBegin);
 245     }
 246 
 247     /**
 248      * @throws IndexOutOfBoundsException {@inheritDoc}
 249      * @see        #length()
 250      */
 251     @Override
 252     public synchronized void setCharAt(int index, char ch) {

 253         super.setCharAt(index, ch);
 254     }
 255 
 256     @Override
 257     public synchronized StringBuffer append(Object obj) {

 258         super.append(String.valueOf(obj));
 259         return this;
 260     }
 261 
 262     @Override
 263     @HotSpotIntrinsicCandidate
 264     public synchronized StringBuffer append(String str) {

 265         super.append(str);
 266         return this;
 267     }
 268 
 269     /**
 270      * Appends the specified {@code StringBuffer} to this sequence.
 271      * <p>
 272      * The characters of the {@code StringBuffer} argument are appended,
 273      * in order, to the contents of this {@code StringBuffer}, increasing the
 274      * length of this {@code StringBuffer} by the length of the argument.
 275      * If {@code sb} is {@code null}, then the four characters
 276      * {@code "null"} are appended to this {@code StringBuffer}.
 277      * <p>
 278      * Let <i>n</i> be the length of the old character sequence, the one
 279      * contained in the {@code StringBuffer} just prior to execution of the
 280      * {@code append} method. Then the character at index <i>k</i> in
 281      * the new character sequence is equal to the character at index <i>k</i>
 282      * in the old character sequence, if <i>k</i> is less than <i>n</i>;
 283      * otherwise, it is equal to the character at index <i>k-n</i> in the
 284      * argument {@code sb}.
 285      * <p>
 286      * This method synchronizes on {@code this}, the destination
 287      * object, but does not synchronize on the source ({@code sb}).
 288      *
 289      * @param   sb   the {@code StringBuffer} to append.
 290      * @return  a reference to this object.
 291      * @since 1.4
 292      */
 293     public synchronized StringBuffer append(StringBuffer sb) {

 294         super.append(sb);
 295         return this;
 296     }
 297 
 298     /**
 299      * @since 1.8
 300      */
 301     @Override
 302     synchronized StringBuffer append(AbstractStringBuilder asb) {

 303         super.append(asb);
 304         return this;
 305     }
 306 
 307     /**
 308      * Appends the specified {@code CharSequence} to this
 309      * sequence.
 310      * <p>
 311      * The characters of the {@code CharSequence} argument are appended,
 312      * in order, increasing the length of this sequence by the length of the
 313      * argument.
 314      *
 315      * <p>The result of this method is exactly the same as if it were an
 316      * invocation of this.append(s, 0, s.length());
 317      *
 318      * <p>This method synchronizes on {@code this}, the destination
 319      * object, but does not synchronize on the source ({@code s}).
 320      *
 321      * <p>If {@code s} is {@code null}, then the four characters
 322      * {@code "null"} are appended.
 323      *
 324      * @param   s the {@code CharSequence} to append.
 325      * @return  a reference to this object.
 326      * @since 1.5
 327      */
 328     @Override
 329     public synchronized StringBuffer append(CharSequence s) {

 330         super.append(s);
 331         return this;
 332     }
 333 
 334     /**
 335      * @throws IndexOutOfBoundsException {@inheritDoc}
 336      * @since      1.5
 337      */
 338     @Override
 339     public synchronized StringBuffer append(CharSequence s, int start, int end)
 340     {

 341         super.append(s, start, end);
 342         return this;
 343     }
 344 
 345     @Override
 346     public synchronized StringBuffer append(char[] str) {

 347         super.append(str);
 348         return this;
 349     }
 350 
 351     /**
 352      * @throws IndexOutOfBoundsException {@inheritDoc}
 353      */
 354     @Override
 355     public synchronized StringBuffer append(char[] str, int offset, int len) {

 356         super.append(str, offset, len);
 357         return this;
 358     }
 359 
 360     @Override
 361     public synchronized StringBuffer append(boolean b) {

 362         super.append(b);
 363         return this;
 364     }
 365 
 366     @Override
 367     @HotSpotIntrinsicCandidate
 368     public synchronized StringBuffer append(char c) {

 369         super.append(c);
 370         return this;
 371     }
 372 
 373     @Override
 374     @HotSpotIntrinsicCandidate
 375     public synchronized StringBuffer append(int i) {

 376         super.append(i);
 377         return this;
 378     }
 379 
 380     /**
 381      * @since 1.5
 382      */
 383     @Override
 384     public synchronized StringBuffer appendCodePoint(int codePoint) {

 385         super.appendCodePoint(codePoint);
 386         return this;
 387     }
 388 
 389     @Override
 390     public synchronized StringBuffer append(long lng) {

 391         super.append(lng);
 392         return this;
 393     }
 394 
 395     @Override
 396     public synchronized StringBuffer append(float f) {

 397         super.append(f);
 398         return this;
 399     }
 400 
 401     @Override
 402     public synchronized StringBuffer append(double d) {

 403         super.append(d);
 404         return this;
 405     }
 406 
 407     /**
 408      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 409      * @since      1.2
 410      */
 411     @Override
 412     public synchronized StringBuffer delete(int start, int end) {

 413         super.delete(start, end);
 414         return this;
 415     }
 416 
 417     /**
 418      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 419      * @since      1.2
 420      */
 421     @Override
 422     public synchronized StringBuffer deleteCharAt(int index) {

 423         super.deleteCharAt(index);
 424         return this;
 425     }
 426 
 427     /**
 428      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 429      * @since      1.2
 430      */
 431     @Override
 432     public synchronized StringBuffer replace(int start, int end, String str) {

 433         super.replace(start, end, str);
 434         return this;
 435     }
 436 
 437     /**
 438      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 439      * @since      1.2
 440      */
 441     @Override
 442     public synchronized String substring(int start) {
 443         return substring(start, count);
 444     }
 445 
 446     /**
 447      * @throws IndexOutOfBoundsException {@inheritDoc}
 448      * @since      1.4
 449      */
 450     @Override
 451     public synchronized CharSequence subSequence(int start, int end) {
 452         return super.substring(start, end);
 453     }
 454 
 455     /**
 456      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 457      * @since      1.2
 458      */
 459     @Override
 460     public synchronized String substring(int start, int end) {
 461         return super.substring(start, end);
 462     }
 463 
 464     /**
 465      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 466      * @since      1.2
 467      */
 468     @Override
 469     public synchronized StringBuffer insert(int index, char[] str, int offset,
 470                                             int len)
 471     {

 472         super.insert(index, str, offset, len);
 473         return this;
 474     }
 475 
 476     /**
 477      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 478      */
 479     @Override
 480     public synchronized StringBuffer insert(int offset, Object obj) {

 481         super.insert(offset, String.valueOf(obj));
 482         return this;
 483     }
 484 
 485     /**
 486      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 487      */
 488     @Override
 489     public synchronized StringBuffer insert(int offset, String str) {

 490         super.insert(offset, str);
 491         return this;
 492     }
 493 
 494     /**
 495      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 496      */
 497     @Override
 498     public synchronized StringBuffer insert(int offset, char[] str) {

 499         super.insert(offset, str);
 500         return this;
 501     }
 502 
 503     /**
 504      * @throws IndexOutOfBoundsException {@inheritDoc}
 505      * @since      1.5
 506      */
 507     @Override
 508     public StringBuffer insert(int dstOffset, CharSequence s) {
 509         // Note, synchronization achieved via invocations of other StringBuffer methods
 510         // after narrowing of s to specific type

 511         super.insert(dstOffset, s);
 512         return this;
 513     }
 514 
 515     /**
 516      * @throws IndexOutOfBoundsException {@inheritDoc}
 517      * @since      1.5
 518      */
 519     @Override
 520     public synchronized StringBuffer insert(int dstOffset, CharSequence s,
 521             int start, int end)
 522     {

 523         super.insert(dstOffset, s, start, end);
 524         return this;
 525     }
 526 
 527     /**
 528      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 529      */
 530     @Override
 531     public  StringBuffer insert(int offset, boolean b) {
 532         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 533         // after conversion of b to String by super class method

 534         super.insert(offset, b);
 535         return this;
 536     }
 537 
 538     /**
 539      * @throws IndexOutOfBoundsException {@inheritDoc}
 540      */
 541     @Override
 542     public synchronized StringBuffer insert(int offset, char c) {

 543         super.insert(offset, c);
 544         return this;
 545     }
 546 
 547     /**
 548      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 549      */
 550     @Override
 551     public StringBuffer insert(int offset, int i) {
 552         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 553         // after conversion of i to String by super class method

 554         super.insert(offset, i);
 555         return this;
 556     }
 557 
 558     /**
 559      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 560      */
 561     @Override
 562     public StringBuffer insert(int offset, long l) {
 563         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 564         // after conversion of l to String by super class method

 565         super.insert(offset, l);
 566         return this;
 567     }
 568 
 569     /**
 570      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 571      */
 572     @Override
 573     public StringBuffer insert(int offset, float f) {
 574         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 575         // after conversion of f to String by super class method

 576         super.insert(offset, f);
 577         return this;
 578     }
 579 
 580     /**
 581      * @throws StringIndexOutOfBoundsException {@inheritDoc}
 582      */
 583     @Override
 584     public StringBuffer insert(int offset, double d) {
 585         // Note, synchronization achieved via invocation of StringBuffer insert(int, String)
 586         // after conversion of d to String by super class method

 587         super.insert(offset, d);
 588         return this;
 589     }
 590 
 591     /**
 592      * @since      1.4
 593      */
 594     @Override
 595     public int indexOf(String str) {
 596         // Note, synchronization achieved via invocations of other StringBuffer methods
 597         return super.indexOf(str);
 598     }
 599 
 600     /**
 601      * @since      1.4
 602      */
 603     @Override
 604     public synchronized int indexOf(String str, int fromIndex) {
 605         return super.indexOf(str, fromIndex);
 606     }


 610      */
 611     @Override
 612     public int lastIndexOf(String str) {
 613         // Note, synchronization achieved via invocations of other StringBuffer methods
 614         return lastIndexOf(str, count);
 615     }
 616 
 617     /**
 618      * @since      1.4
 619      */
 620     @Override
 621     public synchronized int lastIndexOf(String str, int fromIndex) {
 622         return super.lastIndexOf(str, fromIndex);
 623     }
 624 
 625     /**
 626      * @since   1.0.2
 627      */
 628     @Override
 629     public synchronized StringBuffer reverse() {

 630         super.reverse();
 631         return this;
 632     }
 633 
 634     @Override
 635     @HotSpotIntrinsicCandidate
 636     public synchronized String toString() {
 637         final byte[] value = this.value;
 638         if (isLatin1()) {
 639             if ((count << coder) < value.length) {
 640                 return StringLatin1.newString(value, 0, count);
 641             }
 642             shared = true;
 643             return new String(value, String.LATIN1);
 644         }
 645         return StringUTF16.newString(value, 0, count);
 646     }
 647 
 648     /**
 649      * Serializable fields for StringBuffer.
 650      *
 651      * @serialField value  char[]
 652      *              The backing character array of this StringBuffer.
 653      * @serialField count int
 654      *              The number of characters in this StringBuffer.
 655      * @serialField shared  boolean
 656      *              A flag indicating whether the backing array is shared.
 657      *              The value is ignored upon deserialization.
 658      */
 659     private static final java.io.ObjectStreamField[] serialPersistentFields =
 660     {
 661         new java.io.ObjectStreamField("value", char[].class),
 662         new java.io.ObjectStreamField("count", Integer.TYPE),
 663         new java.io.ObjectStreamField("shared", Boolean.TYPE),
 664     };
 665 


 675             StringLatin1.getChars(value, 0, count, val, 0);
 676         } else {
 677             StringUTF16.getChars(value, 0, count, val, 0);
 678         }
 679         fields.put("value", val);
 680         fields.put("count", count);
 681         fields.put("shared", false);
 682         s.writeFields();
 683     }
 684 
 685     /**
 686      * readObject is called to restore the state of the StringBuffer from
 687      * a stream.
 688      */
 689     private void readObject(java.io.ObjectInputStream s)
 690         throws java.io.IOException, ClassNotFoundException {
 691         java.io.ObjectInputStream.GetField fields = s.readFields();
 692         char[] val = (char[])fields.get("value", null);
 693         initBytes(val, 0, val.length);
 694         count = fields.get("count", 0);
 695         shared = false;
 696     }
 697 
 698     synchronized void getBytes(byte dst[], int dstBegin, byte coder) {
 699         super.getBytes(dst, dstBegin, coder);
 700     }
 701 }
< prev index next >