jaroslav@52
|
1 |
/*
|
jaroslav@52
|
2 |
* Copyright (c) 1994, 2008, Oracle and/or its affiliates. All rights reserved.
|
jaroslav@52
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jaroslav@52
|
4 |
*
|
jaroslav@52
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
jaroslav@52
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
jaroslav@52
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
jaroslav@52
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@52
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
jaroslav@52
|
10 |
*
|
jaroslav@52
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jaroslav@52
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jaroslav@52
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jaroslav@52
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jaroslav@52
|
15 |
* accompanied this code).
|
jaroslav@52
|
16 |
*
|
jaroslav@52
|
17 |
* You should have received a copy of the GNU General Public License version
|
jaroslav@52
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jaroslav@52
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jaroslav@52
|
20 |
*
|
jaroslav@52
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jaroslav@52
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
jaroslav@52
|
23 |
* questions.
|
jaroslav@52
|
24 |
*/
|
jaroslav@52
|
25 |
|
jaroslav@52
|
26 |
package java.lang;
|
jaroslav@52
|
27 |
|
jaroslav@52
|
28 |
|
jaroslav@52
|
29 |
/**
|
jaroslav@52
|
30 |
* A thread-safe, mutable sequence of characters.
|
jaroslav@52
|
31 |
* A string buffer is like a {@link String}, but can be modified. At any
|
jaroslav@52
|
32 |
* point in time it contains some particular sequence of characters, but
|
jaroslav@52
|
33 |
* the length and content of the sequence can be changed through certain
|
jaroslav@52
|
34 |
* method calls.
|
jaroslav@52
|
35 |
* <p>
|
jaroslav@52
|
36 |
* String buffers are safe for use by multiple threads. The methods
|
jaroslav@52
|
37 |
* are synchronized where necessary so that all the operations on any
|
jaroslav@52
|
38 |
* particular instance behave as if they occur in some serial order
|
jaroslav@52
|
39 |
* that is consistent with the order of the method calls made by each of
|
jaroslav@52
|
40 |
* the individual threads involved.
|
jaroslav@52
|
41 |
* <p>
|
jaroslav@52
|
42 |
* The principal operations on a <code>StringBuffer</code> are the
|
jaroslav@52
|
43 |
* <code>append</code> and <code>insert</code> methods, which are
|
jaroslav@52
|
44 |
* overloaded so as to accept data of any type. Each effectively
|
jaroslav@52
|
45 |
* converts a given datum to a string and then appends or inserts the
|
jaroslav@52
|
46 |
* characters of that string to the string buffer. The
|
jaroslav@52
|
47 |
* <code>append</code> method always adds these characters at the end
|
jaroslav@52
|
48 |
* of the buffer; the <code>insert</code> method adds the characters at
|
jaroslav@52
|
49 |
* a specified point.
|
jaroslav@52
|
50 |
* <p>
|
jaroslav@52
|
51 |
* For example, if <code>z</code> refers to a string buffer object
|
jaroslav@52
|
52 |
* whose current contents are "<code>start</code>", then
|
jaroslav@52
|
53 |
* the method call <code>z.append("le")</code> would cause the string
|
jaroslav@52
|
54 |
* buffer to contain "<code>startle</code>", whereas
|
jaroslav@52
|
55 |
* <code>z.insert(4, "le")</code> would alter the string buffer to
|
jaroslav@52
|
56 |
* contain "<code>starlet</code>".
|
jaroslav@52
|
57 |
* <p>
|
jaroslav@52
|
58 |
* In general, if sb refers to an instance of a <code>StringBuffer</code>,
|
jaroslav@52
|
59 |
* then <code>sb.append(x)</code> has the same effect as
|
jaroslav@52
|
60 |
* <code>sb.insert(sb.length(), x)</code>.
|
jaroslav@52
|
61 |
* <p>
|
jaroslav@52
|
62 |
* Whenever an operation occurs involving a source sequence (such as
|
jaroslav@52
|
63 |
* appending or inserting from a source sequence) this class synchronizes
|
jaroslav@52
|
64 |
* only on the string buffer performing the operation, not on the source.
|
jaroslav@52
|
65 |
* <p>
|
jaroslav@52
|
66 |
* Every string buffer has a capacity. As long as the length of the
|
jaroslav@52
|
67 |
* character sequence contained in the string buffer does not exceed
|
jaroslav@52
|
68 |
* the capacity, it is not necessary to allocate a new internal
|
jaroslav@52
|
69 |
* buffer array. If the internal buffer overflows, it is
|
jaroslav@52
|
70 |
* automatically made larger.
|
jaroslav@52
|
71 |
*
|
jaroslav@52
|
72 |
* As of release JDK 5, this class has been supplemented with an equivalent
|
jaroslav@52
|
73 |
* class designed for use by a single thread, {@link StringBuilder}. The
|
jaroslav@52
|
74 |
* <tt>StringBuilder</tt> class should generally be used in preference to
|
jaroslav@52
|
75 |
* this one, as it supports all of the same operations but it is faster, as
|
jaroslav@52
|
76 |
* it performs no synchronization.
|
jaroslav@52
|
77 |
*
|
jaroslav@52
|
78 |
* @author Arthur van Hoff
|
jaroslav@52
|
79 |
* @see java.lang.StringBuilder
|
jaroslav@52
|
80 |
* @see java.lang.String
|
jaroslav@52
|
81 |
* @since JDK1.0
|
jaroslav@52
|
82 |
*/
|
jaroslav@52
|
83 |
public final class StringBuffer
|
jaroslav@52
|
84 |
extends AbstractStringBuilder
|
jaroslav@52
|
85 |
implements java.io.Serializable, CharSequence
|
jaroslav@52
|
86 |
{
|
jaroslav@52
|
87 |
|
jaroslav@52
|
88 |
/** use serialVersionUID from JDK 1.0.2 for interoperability */
|
jaroslav@52
|
89 |
static final long serialVersionUID = 3388685877147921107L;
|
jaroslav@52
|
90 |
|
jaroslav@52
|
91 |
/**
|
jaroslav@52
|
92 |
* Constructs a string buffer with no characters in it and an
|
jaroslav@52
|
93 |
* initial capacity of 16 characters.
|
jaroslav@52
|
94 |
*/
|
jaroslav@52
|
95 |
public StringBuffer() {
|
jaroslav@52
|
96 |
super(16);
|
jaroslav@52
|
97 |
}
|
jaroslav@52
|
98 |
|
jaroslav@52
|
99 |
/**
|
jaroslav@52
|
100 |
* Constructs a string buffer with no characters in it and
|
jaroslav@52
|
101 |
* the specified initial capacity.
|
jaroslav@52
|
102 |
*
|
jaroslav@52
|
103 |
* @param capacity the initial capacity.
|
jaroslav@52
|
104 |
* @exception NegativeArraySizeException if the <code>capacity</code>
|
jaroslav@52
|
105 |
* argument is less than <code>0</code>.
|
jaroslav@52
|
106 |
*/
|
jaroslav@52
|
107 |
public StringBuffer(int capacity) {
|
jaroslav@52
|
108 |
super(capacity);
|
jaroslav@52
|
109 |
}
|
jaroslav@52
|
110 |
|
jaroslav@52
|
111 |
/**
|
jaroslav@52
|
112 |
* Constructs a string buffer initialized to the contents of the
|
jaroslav@52
|
113 |
* specified string. The initial capacity of the string buffer is
|
jaroslav@52
|
114 |
* <code>16</code> plus the length of the string argument.
|
jaroslav@52
|
115 |
*
|
jaroslav@52
|
116 |
* @param str the initial contents of the buffer.
|
jaroslav@52
|
117 |
* @exception NullPointerException if <code>str</code> is <code>null</code>
|
jaroslav@52
|
118 |
*/
|
jaroslav@52
|
119 |
public StringBuffer(String str) {
|
jaroslav@52
|
120 |
super(str.length() + 16);
|
jaroslav@52
|
121 |
append(str);
|
jaroslav@52
|
122 |
}
|
jaroslav@52
|
123 |
|
jaroslav@52
|
124 |
/**
|
jaroslav@52
|
125 |
* Constructs a string buffer that contains the same characters
|
jaroslav@52
|
126 |
* as the specified <code>CharSequence</code>. The initial capacity of
|
jaroslav@52
|
127 |
* the string buffer is <code>16</code> plus the length of the
|
jaroslav@52
|
128 |
* <code>CharSequence</code> argument.
|
jaroslav@52
|
129 |
* <p>
|
jaroslav@52
|
130 |
* If the length of the specified <code>CharSequence</code> is
|
jaroslav@52
|
131 |
* less than or equal to zero, then an empty buffer of capacity
|
jaroslav@52
|
132 |
* <code>16</code> is returned.
|
jaroslav@52
|
133 |
*
|
jaroslav@52
|
134 |
* @param seq the sequence to copy.
|
jaroslav@52
|
135 |
* @exception NullPointerException if <code>seq</code> is <code>null</code>
|
jaroslav@52
|
136 |
* @since 1.5
|
jaroslav@52
|
137 |
*/
|
jaroslav@52
|
138 |
public StringBuffer(CharSequence seq) {
|
jaroslav@52
|
139 |
this(seq.length() + 16);
|
jaroslav@52
|
140 |
append(seq);
|
jaroslav@52
|
141 |
}
|
jaroslav@52
|
142 |
|
jaroslav@52
|
143 |
public synchronized int length() {
|
jaroslav@52
|
144 |
return count;
|
jaroslav@52
|
145 |
}
|
jaroslav@52
|
146 |
|
jaroslav@52
|
147 |
public synchronized int capacity() {
|
jaroslav@52
|
148 |
return value.length;
|
jaroslav@52
|
149 |
}
|
jaroslav@52
|
150 |
|
jaroslav@52
|
151 |
|
jaroslav@52
|
152 |
public synchronized void ensureCapacity(int minimumCapacity) {
|
jaroslav@52
|
153 |
if (minimumCapacity > value.length) {
|
jaroslav@52
|
154 |
expandCapacity(minimumCapacity);
|
jaroslav@52
|
155 |
}
|
jaroslav@52
|
156 |
}
|
jaroslav@52
|
157 |
|
jaroslav@52
|
158 |
/**
|
jaroslav@52
|
159 |
* @since 1.5
|
jaroslav@52
|
160 |
*/
|
jaroslav@52
|
161 |
public synchronized void trimToSize() {
|
jaroslav@52
|
162 |
super.trimToSize();
|
jaroslav@52
|
163 |
}
|
jaroslav@52
|
164 |
|
jaroslav@52
|
165 |
/**
|
jaroslav@52
|
166 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
167 |
* @see #length()
|
jaroslav@52
|
168 |
*/
|
jaroslav@52
|
169 |
public synchronized void setLength(int newLength) {
|
jaroslav@52
|
170 |
super.setLength(newLength);
|
jaroslav@52
|
171 |
}
|
jaroslav@52
|
172 |
|
jaroslav@52
|
173 |
/**
|
jaroslav@52
|
174 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
175 |
* @see #length()
|
jaroslav@52
|
176 |
*/
|
jaroslav@52
|
177 |
public synchronized char charAt(int index) {
|
jaroslav@52
|
178 |
if ((index < 0) || (index >= count))
|
jaroslav@52
|
179 |
throw new StringIndexOutOfBoundsException(index);
|
jaroslav@52
|
180 |
return value[index];
|
jaroslav@52
|
181 |
}
|
jaroslav@52
|
182 |
|
jaroslav@52
|
183 |
/**
|
jaroslav@52
|
184 |
* @since 1.5
|
jaroslav@52
|
185 |
*/
|
jaroslav@52
|
186 |
public synchronized int codePointAt(int index) {
|
jaroslav@52
|
187 |
return super.codePointAt(index);
|
jaroslav@52
|
188 |
}
|
jaroslav@52
|
189 |
|
jaroslav@52
|
190 |
/**
|
jaroslav@52
|
191 |
* @since 1.5
|
jaroslav@52
|
192 |
*/
|
jaroslav@52
|
193 |
public synchronized int codePointBefore(int index) {
|
jaroslav@52
|
194 |
return super.codePointBefore(index);
|
jaroslav@52
|
195 |
}
|
jaroslav@52
|
196 |
|
jaroslav@52
|
197 |
/**
|
jaroslav@52
|
198 |
* @since 1.5
|
jaroslav@52
|
199 |
*/
|
jaroslav@52
|
200 |
public synchronized int codePointCount(int beginIndex, int endIndex) {
|
jaroslav@52
|
201 |
return super.codePointCount(beginIndex, endIndex);
|
jaroslav@52
|
202 |
}
|
jaroslav@52
|
203 |
|
jaroslav@52
|
204 |
/**
|
jaroslav@52
|
205 |
* @since 1.5
|
jaroslav@52
|
206 |
*/
|
jaroslav@52
|
207 |
public synchronized int offsetByCodePoints(int index, int codePointOffset) {
|
jaroslav@52
|
208 |
return super.offsetByCodePoints(index, codePointOffset);
|
jaroslav@52
|
209 |
}
|
jaroslav@52
|
210 |
|
jaroslav@52
|
211 |
/**
|
jaroslav@52
|
212 |
* @throws NullPointerException {@inheritDoc}
|
jaroslav@52
|
213 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
214 |
*/
|
jaroslav@52
|
215 |
public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
|
jaroslav@52
|
216 |
int dstBegin)
|
jaroslav@52
|
217 |
{
|
jaroslav@52
|
218 |
super.getChars(srcBegin, srcEnd, dst, dstBegin);
|
jaroslav@52
|
219 |
}
|
jaroslav@52
|
220 |
|
jaroslav@52
|
221 |
/**
|
jaroslav@52
|
222 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
223 |
* @see #length()
|
jaroslav@52
|
224 |
*/
|
jaroslav@52
|
225 |
public synchronized void setCharAt(int index, char ch) {
|
jaroslav@52
|
226 |
if ((index < 0) || (index >= count))
|
jaroslav@52
|
227 |
throw new StringIndexOutOfBoundsException(index);
|
jaroslav@52
|
228 |
value[index] = ch;
|
jaroslav@52
|
229 |
}
|
jaroslav@52
|
230 |
|
jaroslav@52
|
231 |
public synchronized StringBuffer append(Object obj) {
|
jaroslav@52
|
232 |
super.append(String.valueOf(obj));
|
jaroslav@52
|
233 |
return this;
|
jaroslav@52
|
234 |
}
|
jaroslav@52
|
235 |
|
jaroslav@52
|
236 |
public synchronized StringBuffer append(String str) {
|
jaroslav@52
|
237 |
super.append(str);
|
jaroslav@52
|
238 |
return this;
|
jaroslav@52
|
239 |
}
|
jaroslav@52
|
240 |
|
jaroslav@52
|
241 |
/**
|
jaroslav@52
|
242 |
* Appends the specified <tt>StringBuffer</tt> to this sequence.
|
jaroslav@52
|
243 |
* <p>
|
jaroslav@52
|
244 |
* The characters of the <tt>StringBuffer</tt> argument are appended,
|
jaroslav@52
|
245 |
* in order, to the contents of this <tt>StringBuffer</tt>, increasing the
|
jaroslav@52
|
246 |
* length of this <tt>StringBuffer</tt> by the length of the argument.
|
jaroslav@52
|
247 |
* If <tt>sb</tt> is <tt>null</tt>, then the four characters
|
jaroslav@52
|
248 |
* <tt>"null"</tt> are appended to this <tt>StringBuffer</tt>.
|
jaroslav@52
|
249 |
* <p>
|
jaroslav@52
|
250 |
* Let <i>n</i> be the length of the old character sequence, the one
|
jaroslav@52
|
251 |
* contained in the <tt>StringBuffer</tt> just prior to execution of the
|
jaroslav@52
|
252 |
* <tt>append</tt> method. Then the character at index <i>k</i> in
|
jaroslav@52
|
253 |
* the new character sequence is equal to the character at index <i>k</i>
|
jaroslav@52
|
254 |
* in the old character sequence, if <i>k</i> is less than <i>n</i>;
|
jaroslav@52
|
255 |
* otherwise, it is equal to the character at index <i>k-n</i> in the
|
jaroslav@52
|
256 |
* argument <code>sb</code>.
|
jaroslav@52
|
257 |
* <p>
|
jaroslav@52
|
258 |
* This method synchronizes on <code>this</code> (the destination)
|
jaroslav@52
|
259 |
* object but does not synchronize on the source (<code>sb</code>).
|
jaroslav@52
|
260 |
*
|
jaroslav@52
|
261 |
* @param sb the <tt>StringBuffer</tt> to append.
|
jaroslav@52
|
262 |
* @return a reference to this object.
|
jaroslav@52
|
263 |
* @since 1.4
|
jaroslav@52
|
264 |
*/
|
jaroslav@52
|
265 |
public synchronized StringBuffer append(StringBuffer sb) {
|
jaroslav@52
|
266 |
super.append(sb);
|
jaroslav@52
|
267 |
return this;
|
jaroslav@52
|
268 |
}
|
jaroslav@52
|
269 |
|
jaroslav@52
|
270 |
|
jaroslav@52
|
271 |
/**
|
jaroslav@52
|
272 |
* Appends the specified <code>CharSequence</code> to this
|
jaroslav@52
|
273 |
* sequence.
|
jaroslav@52
|
274 |
* <p>
|
jaroslav@52
|
275 |
* The characters of the <code>CharSequence</code> argument are appended,
|
jaroslav@52
|
276 |
* in order, increasing the length of this sequence by the length of the
|
jaroslav@52
|
277 |
* argument.
|
jaroslav@52
|
278 |
*
|
jaroslav@52
|
279 |
* <p>The result of this method is exactly the same as if it were an
|
jaroslav@52
|
280 |
* invocation of this.append(s, 0, s.length());
|
jaroslav@52
|
281 |
*
|
jaroslav@52
|
282 |
* <p>This method synchronizes on this (the destination)
|
jaroslav@52
|
283 |
* object but does not synchronize on the source (<code>s</code>).
|
jaroslav@52
|
284 |
*
|
jaroslav@52
|
285 |
* <p>If <code>s</code> is <code>null</code>, then the four characters
|
jaroslav@52
|
286 |
* <code>"null"</code> are appended.
|
jaroslav@52
|
287 |
*
|
jaroslav@52
|
288 |
* @param s the <code>CharSequence</code> to append.
|
jaroslav@52
|
289 |
* @return a reference to this object.
|
jaroslav@52
|
290 |
* @since 1.5
|
jaroslav@52
|
291 |
*/
|
jaroslav@52
|
292 |
public StringBuffer append(CharSequence s) {
|
jaroslav@52
|
293 |
// Note, synchronization achieved via other invocations
|
jaroslav@52
|
294 |
if (s == null)
|
jaroslav@52
|
295 |
s = "null";
|
jaroslav@52
|
296 |
if (s instanceof String)
|
jaroslav@52
|
297 |
return this.append((String)s);
|
jaroslav@52
|
298 |
if (s instanceof StringBuffer)
|
jaroslav@52
|
299 |
return this.append((StringBuffer)s);
|
jaroslav@52
|
300 |
return this.append(s, 0, s.length());
|
jaroslav@52
|
301 |
}
|
jaroslav@52
|
302 |
|
jaroslav@52
|
303 |
/**
|
jaroslav@52
|
304 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
305 |
* @since 1.5
|
jaroslav@52
|
306 |
*/
|
jaroslav@52
|
307 |
public synchronized StringBuffer append(CharSequence s, int start, int end)
|
jaroslav@52
|
308 |
{
|
jaroslav@52
|
309 |
super.append(s, start, end);
|
jaroslav@52
|
310 |
return this;
|
jaroslav@52
|
311 |
}
|
jaroslav@52
|
312 |
|
jaroslav@52
|
313 |
public synchronized StringBuffer append(char[] str) {
|
jaroslav@52
|
314 |
super.append(str);
|
jaroslav@52
|
315 |
return this;
|
jaroslav@52
|
316 |
}
|
jaroslav@52
|
317 |
|
jaroslav@52
|
318 |
/**
|
jaroslav@52
|
319 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
320 |
*/
|
jaroslav@52
|
321 |
public synchronized StringBuffer append(char[] str, int offset, int len) {
|
jaroslav@52
|
322 |
super.append(str, offset, len);
|
jaroslav@52
|
323 |
return this;
|
jaroslav@52
|
324 |
}
|
jaroslav@52
|
325 |
|
jaroslav@52
|
326 |
public synchronized StringBuffer append(boolean b) {
|
jaroslav@52
|
327 |
super.append(b);
|
jaroslav@52
|
328 |
return this;
|
jaroslav@52
|
329 |
}
|
jaroslav@52
|
330 |
|
jaroslav@52
|
331 |
public synchronized StringBuffer append(char c) {
|
jaroslav@52
|
332 |
super.append(c);
|
jaroslav@52
|
333 |
return this;
|
jaroslav@52
|
334 |
}
|
jaroslav@52
|
335 |
|
jaroslav@52
|
336 |
public synchronized StringBuffer append(int i) {
|
jaroslav@52
|
337 |
super.append(i);
|
jaroslav@52
|
338 |
return this;
|
jaroslav@52
|
339 |
}
|
jaroslav@52
|
340 |
|
jaroslav@52
|
341 |
/**
|
jaroslav@52
|
342 |
* @since 1.5
|
jaroslav@52
|
343 |
*/
|
jaroslav@52
|
344 |
public synchronized StringBuffer appendCodePoint(int codePoint) {
|
jaroslav@52
|
345 |
super.appendCodePoint(codePoint);
|
jaroslav@52
|
346 |
return this;
|
jaroslav@52
|
347 |
}
|
jaroslav@52
|
348 |
|
jaroslav@52
|
349 |
public synchronized StringBuffer append(long lng) {
|
jaroslav@52
|
350 |
super.append(lng);
|
jaroslav@52
|
351 |
return this;
|
jaroslav@52
|
352 |
}
|
jaroslav@52
|
353 |
|
jaroslav@52
|
354 |
public synchronized StringBuffer append(float f) {
|
jaroslav@52
|
355 |
super.append(f);
|
jaroslav@52
|
356 |
return this;
|
jaroslav@52
|
357 |
}
|
jaroslav@52
|
358 |
|
jaroslav@52
|
359 |
public synchronized StringBuffer append(double d) {
|
jaroslav@52
|
360 |
super.append(d);
|
jaroslav@52
|
361 |
return this;
|
jaroslav@52
|
362 |
}
|
jaroslav@52
|
363 |
|
jaroslav@52
|
364 |
/**
|
jaroslav@52
|
365 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
366 |
* @since 1.2
|
jaroslav@52
|
367 |
*/
|
jaroslav@52
|
368 |
public synchronized StringBuffer delete(int start, int end) {
|
jaroslav@52
|
369 |
super.delete(start, end);
|
jaroslav@52
|
370 |
return this;
|
jaroslav@52
|
371 |
}
|
jaroslav@52
|
372 |
|
jaroslav@52
|
373 |
/**
|
jaroslav@52
|
374 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
375 |
* @since 1.2
|
jaroslav@52
|
376 |
*/
|
jaroslav@52
|
377 |
public synchronized StringBuffer deleteCharAt(int index) {
|
jaroslav@52
|
378 |
super.deleteCharAt(index);
|
jaroslav@52
|
379 |
return this;
|
jaroslav@52
|
380 |
}
|
jaroslav@52
|
381 |
|
jaroslav@52
|
382 |
/**
|
jaroslav@52
|
383 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
384 |
* @since 1.2
|
jaroslav@52
|
385 |
*/
|
jaroslav@52
|
386 |
public synchronized StringBuffer replace(int start, int end, String str) {
|
jaroslav@52
|
387 |
super.replace(start, end, str);
|
jaroslav@52
|
388 |
return this;
|
jaroslav@52
|
389 |
}
|
jaroslav@52
|
390 |
|
jaroslav@52
|
391 |
/**
|
jaroslav@52
|
392 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
393 |
* @since 1.2
|
jaroslav@52
|
394 |
*/
|
jaroslav@52
|
395 |
public synchronized String substring(int start) {
|
jaroslav@52
|
396 |
return substring(start, count);
|
jaroslav@52
|
397 |
}
|
jaroslav@52
|
398 |
|
jaroslav@52
|
399 |
/**
|
jaroslav@52
|
400 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
401 |
* @since 1.4
|
jaroslav@52
|
402 |
*/
|
jaroslav@52
|
403 |
public synchronized CharSequence subSequence(int start, int end) {
|
jaroslav@52
|
404 |
return super.substring(start, end);
|
jaroslav@52
|
405 |
}
|
jaroslav@52
|
406 |
|
jaroslav@52
|
407 |
/**
|
jaroslav@52
|
408 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
409 |
* @since 1.2
|
jaroslav@52
|
410 |
*/
|
jaroslav@52
|
411 |
public synchronized String substring(int start, int end) {
|
jaroslav@52
|
412 |
return super.substring(start, end);
|
jaroslav@52
|
413 |
}
|
jaroslav@52
|
414 |
|
jaroslav@52
|
415 |
/**
|
jaroslav@52
|
416 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
417 |
* @since 1.2
|
jaroslav@52
|
418 |
*/
|
jaroslav@52
|
419 |
public synchronized StringBuffer insert(int index, char[] str, int offset,
|
jaroslav@52
|
420 |
int len)
|
jaroslav@52
|
421 |
{
|
jaroslav@52
|
422 |
super.insert(index, str, offset, len);
|
jaroslav@52
|
423 |
return this;
|
jaroslav@52
|
424 |
}
|
jaroslav@52
|
425 |
|
jaroslav@52
|
426 |
/**
|
jaroslav@52
|
427 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
428 |
*/
|
jaroslav@52
|
429 |
public synchronized StringBuffer insert(int offset, Object obj) {
|
jaroslav@52
|
430 |
super.insert(offset, String.valueOf(obj));
|
jaroslav@52
|
431 |
return this;
|
jaroslav@52
|
432 |
}
|
jaroslav@52
|
433 |
|
jaroslav@52
|
434 |
/**
|
jaroslav@52
|
435 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
436 |
*/
|
jaroslav@52
|
437 |
public synchronized StringBuffer insert(int offset, String str) {
|
jaroslav@52
|
438 |
super.insert(offset, str);
|
jaroslav@52
|
439 |
return this;
|
jaroslav@52
|
440 |
}
|
jaroslav@52
|
441 |
|
jaroslav@52
|
442 |
/**
|
jaroslav@52
|
443 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
444 |
*/
|
jaroslav@52
|
445 |
public synchronized StringBuffer insert(int offset, char[] str) {
|
jaroslav@52
|
446 |
super.insert(offset, str);
|
jaroslav@52
|
447 |
return this;
|
jaroslav@52
|
448 |
}
|
jaroslav@52
|
449 |
|
jaroslav@52
|
450 |
/**
|
jaroslav@52
|
451 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
452 |
* @since 1.5
|
jaroslav@52
|
453 |
*/
|
jaroslav@52
|
454 |
public StringBuffer insert(int dstOffset, CharSequence s) {
|
jaroslav@52
|
455 |
// Note, synchronization achieved via other invocations
|
jaroslav@52
|
456 |
if (s == null)
|
jaroslav@52
|
457 |
s = "null";
|
jaroslav@52
|
458 |
if (s instanceof String)
|
jaroslav@52
|
459 |
return this.insert(dstOffset, (String)s);
|
jaroslav@52
|
460 |
return this.insert(dstOffset, s, 0, s.length());
|
jaroslav@52
|
461 |
}
|
jaroslav@52
|
462 |
|
jaroslav@52
|
463 |
/**
|
jaroslav@52
|
464 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
465 |
* @since 1.5
|
jaroslav@52
|
466 |
*/
|
jaroslav@52
|
467 |
public synchronized StringBuffer insert(int dstOffset, CharSequence s,
|
jaroslav@52
|
468 |
int start, int end)
|
jaroslav@52
|
469 |
{
|
jaroslav@52
|
470 |
super.insert(dstOffset, s, start, end);
|
jaroslav@52
|
471 |
return this;
|
jaroslav@52
|
472 |
}
|
jaroslav@52
|
473 |
|
jaroslav@52
|
474 |
/**
|
jaroslav@52
|
475 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
476 |
*/
|
jaroslav@52
|
477 |
public StringBuffer insert(int offset, boolean b) {
|
jaroslav@52
|
478 |
return insert(offset, String.valueOf(b));
|
jaroslav@52
|
479 |
}
|
jaroslav@52
|
480 |
|
jaroslav@52
|
481 |
/**
|
jaroslav@52
|
482 |
* @throws IndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
483 |
*/
|
jaroslav@52
|
484 |
public synchronized StringBuffer insert(int offset, char c) {
|
jaroslav@52
|
485 |
super.insert(offset, c);
|
jaroslav@52
|
486 |
return this;
|
jaroslav@52
|
487 |
}
|
jaroslav@52
|
488 |
|
jaroslav@52
|
489 |
/**
|
jaroslav@52
|
490 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
491 |
*/
|
jaroslav@52
|
492 |
public StringBuffer insert(int offset, int i) {
|
jaroslav@52
|
493 |
return insert(offset, String.valueOf(i));
|
jaroslav@52
|
494 |
}
|
jaroslav@52
|
495 |
|
jaroslav@52
|
496 |
/**
|
jaroslav@52
|
497 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
498 |
*/
|
jaroslav@52
|
499 |
public StringBuffer insert(int offset, long l) {
|
jaroslav@52
|
500 |
return insert(offset, String.valueOf(l));
|
jaroslav@52
|
501 |
}
|
jaroslav@52
|
502 |
|
jaroslav@52
|
503 |
/**
|
jaroslav@52
|
504 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
505 |
*/
|
jaroslav@52
|
506 |
public StringBuffer insert(int offset, float f) {
|
jaroslav@52
|
507 |
return insert(offset, String.valueOf(f));
|
jaroslav@52
|
508 |
}
|
jaroslav@52
|
509 |
|
jaroslav@52
|
510 |
/**
|
jaroslav@52
|
511 |
* @throws StringIndexOutOfBoundsException {@inheritDoc}
|
jaroslav@52
|
512 |
*/
|
jaroslav@52
|
513 |
public StringBuffer insert(int offset, double d) {
|
jaroslav@52
|
514 |
return insert(offset, String.valueOf(d));
|
jaroslav@52
|
515 |
}
|
jaroslav@52
|
516 |
|
jaroslav@52
|
517 |
/**
|
jaroslav@52
|
518 |
* @throws NullPointerException {@inheritDoc}
|
jaroslav@52
|
519 |
* @since 1.4
|
jaroslav@52
|
520 |
*/
|
jaroslav@52
|
521 |
public int indexOf(String str) {
|
jaroslav@52
|
522 |
return indexOf(str, 0);
|
jaroslav@52
|
523 |
}
|
jaroslav@52
|
524 |
|
jaroslav@52
|
525 |
/**
|
jaroslav@52
|
526 |
* @throws NullPointerException {@inheritDoc}
|
jaroslav@52
|
527 |
* @since 1.4
|
jaroslav@52
|
528 |
*/
|
jaroslav@52
|
529 |
public synchronized int indexOf(String str, int fromIndex) {
|
jaroslav@403
|
530 |
return super.indexOf(str, fromIndex);
|
jaroslav@52
|
531 |
}
|
jaroslav@52
|
532 |
|
jaroslav@52
|
533 |
/**
|
jaroslav@52
|
534 |
* @throws NullPointerException {@inheritDoc}
|
jaroslav@52
|
535 |
* @since 1.4
|
jaroslav@52
|
536 |
*/
|
jaroslav@52
|
537 |
public int lastIndexOf(String str) {
|
jaroslav@52
|
538 |
// Note, synchronization achieved via other invocations
|
jaroslav@52
|
539 |
return lastIndexOf(str, count);
|
jaroslav@52
|
540 |
}
|
jaroslav@52
|
541 |
|
jaroslav@52
|
542 |
/**
|
jaroslav@52
|
543 |
* @throws NullPointerException {@inheritDoc}
|
jaroslav@52
|
544 |
* @since 1.4
|
jaroslav@52
|
545 |
*/
|
jaroslav@52
|
546 |
public synchronized int lastIndexOf(String str, int fromIndex) {
|
jaroslav@52
|
547 |
return String.lastIndexOf(value, 0, count,
|
jaroslav@52
|
548 |
str.toCharArray(), 0, str.length(), fromIndex);
|
jaroslav@52
|
549 |
}
|
jaroslav@52
|
550 |
|
jaroslav@52
|
551 |
/**
|
jaroslav@52
|
552 |
* @since JDK1.0.2
|
jaroslav@52
|
553 |
*/
|
jaroslav@52
|
554 |
public synchronized StringBuffer reverse() {
|
jaroslav@52
|
555 |
super.reverse();
|
jaroslav@52
|
556 |
return this;
|
jaroslav@52
|
557 |
}
|
jaroslav@52
|
558 |
|
jaroslav@52
|
559 |
public synchronized String toString() {
|
jaroslav@52
|
560 |
return new String(value, 0, count);
|
jaroslav@52
|
561 |
}
|
jaroslav@52
|
562 |
|
jaroslav@65
|
563 |
// /**
|
jaroslav@65
|
564 |
// * Serializable fields for StringBuffer.
|
jaroslav@65
|
565 |
// *
|
jaroslav@65
|
566 |
// * @serialField value char[]
|
jaroslav@65
|
567 |
// * The backing character array of this StringBuffer.
|
jaroslav@65
|
568 |
// * @serialField count int
|
jaroslav@65
|
569 |
// * The number of characters in this StringBuffer.
|
jaroslav@65
|
570 |
// * @serialField shared boolean
|
jaroslav@65
|
571 |
// * A flag indicating whether the backing array is shared.
|
jaroslav@65
|
572 |
// * The value is ignored upon deserialization.
|
jaroslav@65
|
573 |
// */
|
jaroslav@65
|
574 |
// private static final java.io.ObjectStreamField[] serialPersistentFields =
|
jaroslav@65
|
575 |
// {
|
jaroslav@65
|
576 |
// new java.io.ObjectStreamField("value", char[].class),
|
jaroslav@65
|
577 |
// new java.io.ObjectStreamField("count", Integer.TYPE),
|
jaroslav@65
|
578 |
// new java.io.ObjectStreamField("shared", Boolean.TYPE),
|
jaroslav@65
|
579 |
// };
|
jaroslav@65
|
580 |
//
|
jaroslav@65
|
581 |
// /**
|
jaroslav@65
|
582 |
// * readObject is called to restore the state of the StringBuffer from
|
jaroslav@65
|
583 |
// * a stream.
|
jaroslav@65
|
584 |
// */
|
jaroslav@65
|
585 |
// private synchronized void writeObject(java.io.ObjectOutputStream s)
|
jaroslav@65
|
586 |
// throws java.io.IOException {
|
jaroslav@65
|
587 |
// java.io.ObjectOutputStream.PutField fields = s.putFields();
|
jaroslav@65
|
588 |
// fields.put("value", value);
|
jaroslav@65
|
589 |
// fields.put("count", count);
|
jaroslav@65
|
590 |
// fields.put("shared", false);
|
jaroslav@65
|
591 |
// s.writeFields();
|
jaroslav@65
|
592 |
// }
|
jaroslav@65
|
593 |
//
|
jaroslav@65
|
594 |
// /**
|
jaroslav@65
|
595 |
// * readObject is called to restore the state of the StringBuffer from
|
jaroslav@65
|
596 |
// * a stream.
|
jaroslav@65
|
597 |
// */
|
jaroslav@65
|
598 |
// private void readObject(java.io.ObjectInputStream s)
|
jaroslav@65
|
599 |
// throws java.io.IOException, ClassNotFoundException {
|
jaroslav@65
|
600 |
// java.io.ObjectInputStream.GetField fields = s.readFields();
|
jaroslav@65
|
601 |
// value = (char[])fields.get("value", null);
|
jaroslav@65
|
602 |
// count = fields.get("count", 0);
|
jaroslav@65
|
603 |
// }
|
jaroslav@52
|
604 |
}
|