79 }
80
81 /**
82 * Creates an AbstractStringBuilder of the specified capacity.
83 */
84 AbstractStringBuilder(int capacity) {
85 if (COMPACT_STRINGS) {
86 value = new byte[capacity];
87 coder = LATIN1;
88 } else {
89 value = StringUTF16.newBytesFor(capacity);
90 coder = UTF16;
91 }
92 }
93
94 /**
95 * Creates an AbstractStringBuilder with the specified coder and with
96 * the initial capacity equal to the smaller of (length + addition)
97 * and Integer.MAX_VALUE.
98 */
99 AbstractStringBuilder(byte coder, int length, int addition) {
100 if (length < 0) {
101 throw new NegativeArraySizeException("Negative length: " + length);
102 }
103 this.coder = coder;
104 int capacity = (length < Integer.MAX_VALUE - addition)
105 ? length + addition : Integer.MAX_VALUE;
106 value = (coder == LATIN1)
107 ? new byte[capacity] : StringUTF16.newBytesFor(capacity);
108 }
109
110 /**
111 * Compares the objects of two AbstractStringBuilder implementations lexicographically.
112 *
113 * @since 11
114 */
115 int compareTo(AbstractStringBuilder another) {
116 if (this == another) {
117 return 0;
118 }
119
120 byte val1[] = value;
121 byte val2[] = another.value;
122 int count1 = this.count;
123 int count2 = another.count;
124
125 if (coder == another.coder) {
126 return isLatin1() ? StringLatin1.compareTo(val1, val2, count1, count2)
127 : StringUTF16.compareTo(val1, val2, count1, count2);
|
79 }
80
81 /**
82 * Creates an AbstractStringBuilder of the specified capacity.
83 */
84 AbstractStringBuilder(int capacity) {
85 if (COMPACT_STRINGS) {
86 value = new byte[capacity];
87 coder = LATIN1;
88 } else {
89 value = StringUTF16.newBytesFor(capacity);
90 coder = UTF16;
91 }
92 }
93
94 /**
95 * Creates an AbstractStringBuilder with the specified coder and with
96 * the initial capacity equal to the smaller of (length + addition)
97 * and Integer.MAX_VALUE.
98 */
99 AbstractStringBuilder(byte coderHint, int length, int addition) {
100 if (length < 0) {
101 throw new NegativeArraySizeException("Negative length: " + length);
102 }
103 int capacity = (length < Integer.MAX_VALUE - addition)
104 ? length + addition : Integer.MAX_VALUE;
105 if (COMPACT_STRINGS && coderHint == LATIN1) {
106 value = new byte[capacity];
107 coder = LATIN1;
108 } else {
109 value = StringUTF16.newBytesFor(capacity);
110 coder = UTF16;
111 }
112 }
113
114 /**
115 * Compares the objects of two AbstractStringBuilder implementations lexicographically.
116 *
117 * @since 11
118 */
119 int compareTo(AbstractStringBuilder another) {
120 if (this == another) {
121 return 0;
122 }
123
124 byte val1[] = value;
125 byte val2[] = another.value;
126 int count1 = this.count;
127 int count2 = another.count;
128
129 if (coder == another.coder) {
130 return isLatin1() ? StringLatin1.compareTo(val1, val2, count1, count2)
131 : StringUTF16.compareTo(val1, val2, count1, count2);
|