< prev index next >

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

Print this page




 715                 inflate();
 716             }
 717             StringUTF16.putCharSB(value, count++, c);
 718         }
 719         return this;
 720     }
 721 
 722     /**
 723      * Appends the string representation of the {@code int}
 724      * argument to this sequence.
 725      * <p>
 726      * The overall effect is exactly as if the argument were converted
 727      * to a string by the method {@link String#valueOf(int)},
 728      * and the characters of that string were then
 729      * {@link #append(String) appended} to this character sequence.
 730      *
 731      * @param   i   an {@code int}.
 732      * @return  a reference to this object.
 733      */
 734     public AbstractStringBuilder append(int i) {
 735         if (i == Integer.MIN_VALUE) {
 736             append("-2147483648");
 737             return this;
 738         }
 739         int appendedLength = (i < 0) ? Integer.stringSize(-i) + 1
 740                                      : Integer.stringSize(i);
 741         int spaceNeeded = count + appendedLength;
 742         ensureCapacityInternal(spaceNeeded);
 743         if (isLatin1()) {
 744             Integer.getChars(i, spaceNeeded, value);
 745         } else {
 746             byte[] val = this.value;
 747             checkOffset(spaceNeeded, val.length >> 1);
 748             Integer.getCharsUTF16(i, spaceNeeded, val);
 749         }
 750         count = spaceNeeded;
 751         return this;
 752     }
 753 
 754     /**
 755      * Appends the string representation of the {@code long}
 756      * argument to this sequence.
 757      * <p>
 758      * The overall effect is exactly as if the argument were converted
 759      * to a string by the method {@link String#valueOf(long)},
 760      * and the characters of that string were then
 761      * {@link #append(String) appended} to this character sequence.
 762      *
 763      * @param   l   a {@code long}.
 764      * @return  a reference to this object.
 765      */
 766     public AbstractStringBuilder append(long l) {
 767         if (l == Long.MIN_VALUE) {
 768             append("-9223372036854775808");
 769             return this;
 770         }
 771         int appendedLength = (l < 0) ? Long.stringSize(-l) + 1
 772                                      : Long.stringSize(l);
 773         int spaceNeeded = count + appendedLength;
 774         ensureCapacityInternal(spaceNeeded);
 775         if (isLatin1()) {
 776             Long.getChars(l, spaceNeeded, value);
 777         } else {
 778             byte[] val = this.value;
 779             checkOffset(spaceNeeded, val.length >> 1);
 780             Long.getCharsUTF16(l, spaceNeeded, val);
 781         }
 782         count = spaceNeeded;
 783         return this;
 784     }
 785 
 786     /**
 787      * Appends the string representation of the {@code float}
 788      * argument to this sequence.
 789      * <p>
 790      * The overall effect is exactly as if the argument were converted
 791      * to a string by the method {@link String#valueOf(float)},
 792      * and the characters of that string were then
 793      * {@link #append(String) appended} to this character sequence.




 715                 inflate();
 716             }
 717             StringUTF16.putCharSB(value, count++, c);
 718         }
 719         return this;
 720     }
 721 
 722     /**
 723      * Appends the string representation of the {@code int}
 724      * argument to this sequence.
 725      * <p>
 726      * The overall effect is exactly as if the argument were converted
 727      * to a string by the method {@link String#valueOf(int)},
 728      * and the characters of that string were then
 729      * {@link #append(String) appended} to this character sequence.
 730      *
 731      * @param   i   an {@code int}.
 732      * @return  a reference to this object.
 733      */
 734     public AbstractStringBuilder append(int i) {
 735         int spaceNeeded = count + Integer.stringSize(i);






 736         ensureCapacityInternal(spaceNeeded);
 737         if (isLatin1()) {
 738             Integer.getChars(i, spaceNeeded, value);
 739         } else {
 740             byte[] val = this.value;
 741             checkOffset(spaceNeeded, val.length >> 1);
 742             Integer.getCharsUTF16(i, spaceNeeded, val);
 743         }
 744         count = spaceNeeded;
 745         return this;
 746     }
 747 
 748     /**
 749      * Appends the string representation of the {@code long}
 750      * argument to this sequence.
 751      * <p>
 752      * The overall effect is exactly as if the argument were converted
 753      * to a string by the method {@link String#valueOf(long)},
 754      * and the characters of that string were then
 755      * {@link #append(String) appended} to this character sequence.
 756      *
 757      * @param   l   a {@code long}.
 758      * @return  a reference to this object.
 759      */
 760     public AbstractStringBuilder append(long l) {
 761         int spaceNeeded = count + Long.stringSize(l);






 762         ensureCapacityInternal(spaceNeeded);
 763         if (isLatin1()) {
 764             Long.getChars(l, spaceNeeded, value);
 765         } else {
 766             byte[] val = this.value;
 767             checkOffset(spaceNeeded, val.length >> 1);
 768             Long.getCharsUTF16(l, spaceNeeded, val);
 769         }
 770         count = spaceNeeded;
 771         return this;
 772     }
 773 
 774     /**
 775      * Appends the string representation of the {@code float}
 776      * argument to this sequence.
 777      * <p>
 778      * The overall effect is exactly as if the argument were converted
 779      * to a string by the method {@link String#valueOf(float)},
 780      * and the characters of that string were then
 781      * {@link #append(String) appended} to this character sequence.


< prev index next >