81 AbstractStringBuilder(int capacity) {
82 if (COMPACT_STRINGS) {
83 value = new byte[capacity];
84 coder = LATIN1;
85 } else {
86 value = StringUTF16.newBytesFor(capacity);
87 coder = UTF16;
88 }
89 }
90
91 /**
92 * Compares the objects of two AbstractStringBuilder implementations lexicographically.
93 *
94 * @since 11
95 */
96 int compareTo(AbstractStringBuilder another) {
97 if (this == another) {
98 return 0;
99 }
100
101 byte val1[] = value;
102 byte val2[] = another.value;
103 int count1 = this.count;
104 int count2 = another.count;
105
106 if (coder == another.coder) {
107 return isLatin1() ? StringLatin1.compareTo(val1, val2, count1, count2)
108 : StringUTF16.compareTo(val1, val2, count1, count2);
109 }
110 return isLatin1() ? StringLatin1.compareToUTF16(val1, val2, count1, count2)
111 : StringUTF16.compareToLatin1(val1, val2, count1, count2);
112 }
113
114 /**
115 * Returns the length (character count).
116 *
117 * @return the length of the sequence of characters currently
118 * represented by this object
119 */
120 @Override
121 public int length() {
122 return count;
660 * {@code char} array argument to this sequence.
661 * <p>
662 * Characters of the {@code char} array {@code str}, starting at
663 * index {@code offset}, are appended, in order, to the contents
664 * of this sequence. The length of this sequence increases
665 * by the value of {@code len}.
666 * <p>
667 * The overall effect is exactly as if the arguments were converted
668 * to a string by the method {@link String#valueOf(char[],int,int)},
669 * and the characters of that string were then
670 * {@link #append(String) appended} to this character sequence.
671 *
672 * @param str the characters to be appended.
673 * @param offset the index of the first {@code char} to append.
674 * @param len the number of {@code char}s to append.
675 * @return a reference to this object.
676 * @throws IndexOutOfBoundsException
677 * if {@code offset < 0} or {@code len < 0}
678 * or {@code offset+len > str.length}
679 */
680 public AbstractStringBuilder append(char str[], int offset, int len) {
681 int end = offset + len;
682 checkRange(offset, end, str.length);
683 ensureCapacityInternal(count + len);
684 appendChars(str, offset, end);
685 return this;
686 }
687
688 /**
689 * Appends the string representation of the {@code boolean}
690 * argument to the sequence.
691 * <p>
692 * The overall effect is exactly as if the argument were converted
693 * to a string by the method {@link String#valueOf(boolean)},
694 * and the characters of that string were then
695 * {@link #append(String) appended} to this character sequence.
696 *
697 * @param b a {@code boolean}.
698 * @return a reference to this object.
699 */
700 public AbstractStringBuilder append(boolean b) {
1575 : new StringUTF16.CodePointsSpliterator(val, 0, count, 0);
1576 },
1577 Spliterator.ORDERED,
1578 false);
1579 }
1580
1581 /**
1582 * Needed by {@code String} for the contentEquals method.
1583 */
1584 final byte[] getValue() {
1585 return value;
1586 }
1587
1588 /*
1589 * Invoker guarantees it is in UTF16 (inflate itself for asb), if two
1590 * coders are different and the dstBegin has enough space
1591 *
1592 * @param dstBegin the char index, not offset of byte[]
1593 * @param coder the coder of dst[]
1594 */
1595 void getBytes(byte dst[], int dstBegin, byte coder) {
1596 if (this.coder == coder) {
1597 System.arraycopy(value, 0, dst, dstBegin << coder, count << coder);
1598 } else { // this.coder == LATIN && coder == UTF16
1599 StringLatin1.inflate(value, 0, dst, dstBegin, count);
1600 }
1601 }
1602
1603 /* for readObject() */
1604 void initBytes(char[] value, int off, int len) {
1605 if (String.COMPACT_STRINGS) {
1606 this.value = StringUTF16.compress(value, off, len);
1607 if (this.value != null) {
1608 this.coder = LATIN1;
1609 return;
1610 }
1611 }
1612 this.coder = UTF16;
1613 this.value = StringUTF16.toBytes(value, off, len);
1614 }
1615
|
81 AbstractStringBuilder(int capacity) {
82 if (COMPACT_STRINGS) {
83 value = new byte[capacity];
84 coder = LATIN1;
85 } else {
86 value = StringUTF16.newBytesFor(capacity);
87 coder = UTF16;
88 }
89 }
90
91 /**
92 * Compares the objects of two AbstractStringBuilder implementations lexicographically.
93 *
94 * @since 11
95 */
96 int compareTo(AbstractStringBuilder another) {
97 if (this == another) {
98 return 0;
99 }
100
101 byte[] val1 = value;
102 byte[] val2 = another.value;
103 int count1 = this.count;
104 int count2 = another.count;
105
106 if (coder == another.coder) {
107 return isLatin1() ? StringLatin1.compareTo(val1, val2, count1, count2)
108 : StringUTF16.compareTo(val1, val2, count1, count2);
109 }
110 return isLatin1() ? StringLatin1.compareToUTF16(val1, val2, count1, count2)
111 : StringUTF16.compareToLatin1(val1, val2, count1, count2);
112 }
113
114 /**
115 * Returns the length (character count).
116 *
117 * @return the length of the sequence of characters currently
118 * represented by this object
119 */
120 @Override
121 public int length() {
122 return count;
660 * {@code char} array argument to this sequence.
661 * <p>
662 * Characters of the {@code char} array {@code str}, starting at
663 * index {@code offset}, are appended, in order, to the contents
664 * of this sequence. The length of this sequence increases
665 * by the value of {@code len}.
666 * <p>
667 * The overall effect is exactly as if the arguments were converted
668 * to a string by the method {@link String#valueOf(char[],int,int)},
669 * and the characters of that string were then
670 * {@link #append(String) appended} to this character sequence.
671 *
672 * @param str the characters to be appended.
673 * @param offset the index of the first {@code char} to append.
674 * @param len the number of {@code char}s to append.
675 * @return a reference to this object.
676 * @throws IndexOutOfBoundsException
677 * if {@code offset < 0} or {@code len < 0}
678 * or {@code offset+len > str.length}
679 */
680 public AbstractStringBuilder append(char[] str, int offset, int len) {
681 int end = offset + len;
682 checkRange(offset, end, str.length);
683 ensureCapacityInternal(count + len);
684 appendChars(str, offset, end);
685 return this;
686 }
687
688 /**
689 * Appends the string representation of the {@code boolean}
690 * argument to the sequence.
691 * <p>
692 * The overall effect is exactly as if the argument were converted
693 * to a string by the method {@link String#valueOf(boolean)},
694 * and the characters of that string were then
695 * {@link #append(String) appended} to this character sequence.
696 *
697 * @param b a {@code boolean}.
698 * @return a reference to this object.
699 */
700 public AbstractStringBuilder append(boolean b) {
1575 : new StringUTF16.CodePointsSpliterator(val, 0, count, 0);
1576 },
1577 Spliterator.ORDERED,
1578 false);
1579 }
1580
1581 /**
1582 * Needed by {@code String} for the contentEquals method.
1583 */
1584 final byte[] getValue() {
1585 return value;
1586 }
1587
1588 /*
1589 * Invoker guarantees it is in UTF16 (inflate itself for asb), if two
1590 * coders are different and the dstBegin has enough space
1591 *
1592 * @param dstBegin the char index, not offset of byte[]
1593 * @param coder the coder of dst[]
1594 */
1595 void getBytes(byte[] dst, int dstBegin, byte coder) {
1596 if (this.coder == coder) {
1597 System.arraycopy(value, 0, dst, dstBegin << coder, count << coder);
1598 } else { // this.coder == LATIN && coder == UTF16
1599 StringLatin1.inflate(value, 0, dst, dstBegin, count);
1600 }
1601 }
1602
1603 /* for readObject() */
1604 void initBytes(char[] value, int off, int len) {
1605 if (String.COMPACT_STRINGS) {
1606 this.value = StringUTF16.compress(value, off, len);
1607 if (this.value != null) {
1608 this.coder = LATIN1;
1609 return;
1610 }
1611 }
1612 this.coder = UTF16;
1613 this.value = StringUTF16.toBytes(value, off, len);
1614 }
1615
|