1 /*
2 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
69 */
70 int count;
71
72 /**
73 * This no-arg constructor is necessary for serialization of subclasses.
74 */
75 AbstractStringBuilder() {
76 }
77
78 /**
79 * Creates an AbstractStringBuilder of the specified capacity.
80 */
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 * Returns the length (character count).
93 *
94 * @return the length of the sequence of characters currently
95 * represented by this object
96 */
97 @Override
98 public int length() {
99 return count;
100 }
101
102 /**
103 * Returns the current capacity. The capacity is the amount of storage
104 * available for newly inserted characters, beyond which an allocation
105 * will occur.
106 *
107 * @return the current capacity
108 */
|
1 /*
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
69 */
70 int count;
71
72 /**
73 * This no-arg constructor is necessary for serialization of subclasses.
74 */
75 AbstractStringBuilder() {
76 }
77
78 /**
79 * Creates an AbstractStringBuilder of the specified capacity.
80 */
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;
123 }
124
125 /**
126 * Returns the current capacity. The capacity is the amount of storage
127 * available for newly inserted characters, beyond which an allocation
128 * will occur.
129 *
130 * @return the current capacity
131 */
|