< prev index next >

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

Print this page




 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




 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 = Integer.stringSize(i);

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

 771         int spaceNeeded = count + appendedLength;
 772         ensureCapacityInternal(spaceNeeded);
 773         if (isLatin1()) {
 774             Long.getChars(l, spaceNeeded, value);
 775         } else {
 776             byte[] val = this.value;
 777             checkOffset(spaceNeeded, val.length >> 1);
 778             Long.getCharsUTF16(l, spaceNeeded, val);
 779         }
 780         count = spaceNeeded;
 781         return this;
 782     }
 783 
 784     /**
 785      * Appends the string representation of the {@code float}
 786      * argument to this sequence.
 787      * <p>
 788      * The overall effect is exactly as if the argument were converted
 789      * to a string by the method {@link String#valueOf(float)},
 790      * and the characters of that string were then


< prev index next >