Source Code Cross Referenced for StringBuffer.java in  » Apache-Harmony-Java-SE » java-package » java » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        package java.lang;
019:
020:        import java.io.IOException;
021:        import java.io.ObjectInputStream;
022:        import java.io.ObjectOutputStream;
023:        import java.io.ObjectStreamField;
024:        import java.io.Serializable;
025:
026:        /**
027:         * StringBuffer is a variable size contiguous indexable array of characters. The
028:         * length of the StringBuffer is the number of characters it contains. The
029:         * capacity of the StringBuffer is the number of characters it can hold.
030:         * <p>
031:         * Characters may be inserted at any position up to the length of the
032:         * StringBuffer, increasing the length of the StringBuffer. Characters at any
033:         * position in the StringBuffer may be replaced, which does not affect the
034:         * StringBuffer length.
035:         * <p>
036:         * The capacity of a StringBuffer may be specified when the StringBuffer is
037:         * created. If the capacity of the StringBuffer is exceeded, the capacity is
038:         * increased.
039:         * 
040:         * @see String
041:         * @see StringBuilder
042:         * @since 1.0
043:         */
044:        public final class StringBuffer extends AbstractStringBuilder implements 
045:                Appendable, Serializable, CharSequence {
046:
047:            private static final long serialVersionUID = 3388685877147921107L;
048:
049:            private static final ObjectStreamField serialPersistentFields[] = {
050:                    new ObjectStreamField("count", int.class), //$NON-NLS-1$
051:                    new ObjectStreamField("shared", boolean.class), //$NON-NLS-1$
052:                    new ObjectStreamField("value", char[].class), }; //$NON-NLS-1$
053:
054:            /**
055:             * Constructs a new StringBuffer using the default capacity.
056:             */
057:            public StringBuffer() {
058:                super ();
059:            }
060:
061:            /**
062:             * Constructs a new StringBuffer using the specified capacity.
063:             * 
064:             * @param capacity
065:             *            the initial capacity
066:             */
067:            public StringBuffer(int capacity) {
068:                super (capacity);
069:            }
070:
071:            /**
072:             * Constructs a new StringBuffer containing the characters in the specified
073:             * string and the default capacity.
074:             * 
075:             * @param string
076:             *            the string content with which to initialize the new
077:             *            <code>StringBuffer</code> instance
078:             * @throws NullPointerException
079:             *             on supplying a <code>null</code> value of
080:             *             <code>string</code>
081:             */
082:            public StringBuffer(String string) {
083:                super (string);
084:            }
085:
086:            /**
087:             * <p>
088:             * Constructs a StringBuffer and initializes it with the characters in the
089:             * <code>CharSequence</code>.
090:             * </p>
091:             * 
092:             * @param cs
093:             *            The <code>CharSequence</code> to initialize the instance.
094:             * @throws NullPointerException
095:             *             if the <code>cs</code> parameter is <code>null</code>.
096:             * @since 1.5
097:             */
098:            public StringBuffer(CharSequence cs) {
099:                super (cs.toString());
100:            }
101:
102:            /**
103:             * Adds the string representation of the specified boolean to the end of
104:             * this StringBuffer.
105:             * 
106:             * @param b
107:             *            the boolean
108:             * @return this StringBuffer
109:             */
110:            public StringBuffer append(boolean b) {
111:                return append(b ? "true" : "false"); //$NON-NLS-1$//$NON-NLS-2$
112:            }
113:
114:            /**
115:             * Adds the specified character to the end of this StringBuffer.
116:             * 
117:             * @param ch
118:             *            a character
119:             * @return this StringBuffer
120:             */
121:            public synchronized StringBuffer append(char ch) {
122:                append0(ch);
123:                return this ;
124:            }
125:
126:            /**
127:             * Adds the string representation of the specified double to the end of this
128:             * StringBuffer.
129:             * 
130:             * @param d
131:             *            the double
132:             * @return this StringBuffer
133:             */
134:            public StringBuffer append(double d) {
135:                return append(Double.toString(d));
136:            }
137:
138:            /**
139:             * Adds the string representation of the specified float to the end of this
140:             * StringBuffer.
141:             * 
142:             * @param f
143:             *            the float
144:             * @return this StringBuffer
145:             */
146:            public StringBuffer append(float f) {
147:                return append(Float.toString(f));
148:            }
149:
150:            /**
151:             * Adds the string representation of the specified integer to the end of
152:             * this StringBuffer.
153:             * 
154:             * @param value
155:             *            the integer
156:             * @return this StringBuffer
157:             */
158:            public StringBuffer append(int value) {
159:                return append(Integer.toString(value));
160:            }
161:
162:            /**
163:             * Adds the string representation of the specified long to the end of this
164:             * StringBuffer.
165:             * 
166:             * @param l
167:             *            the long
168:             * @return this StringBuffer
169:             */
170:            public StringBuffer append(long l) {
171:                return append(Long.toString(l));
172:            }
173:
174:            /**
175:             * Adds the string representation of the specified object to the end of this
176:             * StringBuffer.
177:             * 
178:             * @param obj
179:             *            the object
180:             * @return this StringBuffer
181:             */
182:            public synchronized StringBuffer append(Object obj) {
183:                if (obj == null) {
184:                    appendNull();
185:                } else {
186:                    append0(obj.toString());
187:                }
188:                return this ;
189:            }
190:
191:            /**
192:             * Adds the specified string to the end of this StringBuffer.
193:             * 
194:             * @param string
195:             *            the string
196:             * @return this StringBuffer
197:             */
198:            public synchronized StringBuffer append(String string) {
199:                append0(string);
200:                return this ;
201:            }
202:
203:            /**
204:             * Adds the specified StringBuffer to the end of this StringBuffer.
205:             * 
206:             * @param sb
207:             *            the StringBuffer
208:             * @return this StringBuffer
209:             * 
210:             * @since 1.4
211:             */
212:            public synchronized StringBuffer append(StringBuffer sb) {
213:                if (sb == null) {
214:                    appendNull();
215:                } else {
216:                    synchronized (sb) {
217:                        append0(sb.getValue(), 0, sb.length());
218:                    }
219:                }
220:                return this ;
221:            }
222:
223:            /**
224:             * Adds the character array to the end of this StringBuffer.
225:             * 
226:             * @param chars
227:             *            the character array
228:             * @return this StringBuffer
229:             * 
230:             * @throws NullPointerException
231:             *             when chars is null
232:             */
233:            public synchronized StringBuffer append(char chars[]) {
234:                append0(chars);
235:                return this ;
236:            }
237:
238:            /**
239:             * Adds the specified sequence of characters to the end of this
240:             * StringBuffer.
241:             * 
242:             * @param chars
243:             *            a character array
244:             * @param start
245:             *            the starting offset
246:             * @param length
247:             *            the number of characters
248:             * @return this StringBuffer
249:             * 
250:             * @throws ArrayIndexOutOfBoundsException
251:             *             when <code>length < 0, start < 0</code> or
252:             *             <code>start + length > chars.length</code>
253:             * @throws NullPointerException
254:             *             when chars is null
255:             */
256:            public synchronized StringBuffer append(char chars[], int start,
257:                    int length) {
258:                append0(chars, start, length);
259:                return this ;
260:            }
261:
262:            /**
263:             * <p>
264:             * Appends the <code>CharSequence</code> to this buffer. If the
265:             * <code>CharSequence</code> is <code>null</code>, then the string
266:             * <code>"null"</code> is appended.
267:             * </p>
268:             * 
269:             * @param s
270:             *            The <code>CharSequence</code> to append.
271:             * @return A reference to this object.
272:             * @since 1.5
273:             */
274:            public synchronized StringBuffer append(CharSequence s) {
275:                if (s == null) {
276:                    appendNull();
277:                } else {
278:                    append0(s.toString());
279:                }
280:                return this ;
281:            }
282:
283:            /**
284:             * <p>
285:             * Appends the subsequence of the <code>CharSequence</code> to this
286:             * buffer. If the <code>CharSequence</code> is <code>null</code>, then
287:             * the string <code>"null"</code> is used to extract a subsequence.
288:             * </p>
289:             * 
290:             * @param s
291:             *            The <code>CharSequence</code> to append.
292:             * @param start
293:             *            The inclusive start index of the subsequence of the
294:             *            <code>CharSequence</code>.
295:             * @param end
296:             *            The exclusive end index of the subsequence of the
297:             *            <code>CharSequence</code>.
298:             * @return A reference to this object.
299:             * @since 1.5
300:             * @throws IndexOutOfBoundsException
301:             *             if <code>start</code> or <code>end</code> are negative,
302:             *             <code>start</code> is greater than <code>end</code> or
303:             *             <code>end</code> is greater than the length of
304:             *             <code>s</code>.
305:             */
306:            public synchronized StringBuffer append(CharSequence s, int start,
307:                    int end) {
308:                append0(s, start, end);
309:                return this ;
310:            }
311:
312:            /**
313:             * <p>
314:             * Appends the encoded Unicode code point to this object. The code point is
315:             * converted to a <code>char[]</code> as defined by
316:             * {@link Character#toChars(int)}.
317:             * </p>
318:             * 
319:             * @param codePoint
320:             *            The Unicode code point to encode and append.
321:             * @return A reference to this object.
322:             * @see Character#toChars(int)
323:             * @since 1.5
324:             */
325:            public StringBuffer appendCodePoint(int codePoint) {
326:                return append(Character.toChars(codePoint));
327:            }
328:
329:            /**
330:             * Answers the character at the specified offset in this StringBuffer.
331:             * 
332:             * @param index
333:             *            the zero-based index in this StringBuffer
334:             * @return the character at the index
335:             * 
336:             * @throws IndexOutOfBoundsException
337:             *             when <code>index < 0</code> or
338:             *             <code>index >= length()</code>
339:             */
340:            @Override
341:            public synchronized char charAt(int index) {
342:                return super .charAt(index);
343:            }
344:
345:            /**
346:             * <p>
347:             * Retrieves the Unicode code point value at the <code>index</code>.
348:             * </p>
349:             * 
350:             * @param index
351:             *            The index to the <code>char</code> code unit within this
352:             *            object.
353:             * @return The Unicode code point value.
354:             * @throws IndexOutOfBoundsException
355:             *             if <code>index</code> is negative or greater than or equal
356:             *             to {@link #length()}.
357:             * @see Character
358:             * @see Character#codePointAt(char[], int, int)
359:             * @since 1.5
360:             */
361:            @Override
362:            public synchronized int codePointAt(int index) {
363:                return super .codePointAt(index);
364:            }
365:
366:            /**
367:             * <p>
368:             * Retrieves the Unicode code point value that precedes the
369:             * <code>index</code>.
370:             * </p>
371:             * 
372:             * @param index
373:             *            The index to the <code>char</code> code unit within this
374:             *            object.
375:             * @return The Unicode code point value.
376:             * @throws IndexOutOfBoundsException
377:             *             if <code>index</code> is less than 1 or greater than
378:             *             {@link #length()}.
379:             * @see Character
380:             * @see Character#codePointBefore(char[], int, int)
381:             * @since 1.5
382:             */
383:            @Override
384:            public synchronized int codePointBefore(int index) {
385:                return super .codePointBefore(index);
386:            }
387:
388:            /**
389:             * <p>
390:             * Calculates the number of Unicode code points between
391:             * <code>beginIndex</code> and <code>endIndex</code>.
392:             * </p>
393:             * 
394:             * @param beginIndex
395:             *            The inclusive beginning index of the subsequence.
396:             * @param endIndex
397:             *            The exclusive end index of the subsequence.
398:             * @return The number of Unicode code points in the subsequence.
399:             * @throws IndexOutOfBoundsException
400:             *             if <code>beginIndex</code> is negative or greater than
401:             *             <code>endIndex</code> or <code>endIndex</code> is greater
402:             *             than {@link #length()}.
403:             * @since 1.5
404:             */
405:            @Override
406:            public synchronized int codePointCount(int beginIndex, int endIndex) {
407:                return super .codePointCount(beginIndex, endIndex);
408:            }
409:
410:            /**
411:             * Deletes a range of characters.
412:             * 
413:             * @param start
414:             *            the offset of the first character
415:             * @param end
416:             *            the offset one past the last character
417:             * @return this StringBuffer
418:             * 
419:             * @throws StringIndexOutOfBoundsException
420:             *             when <code>start < 0, start > end</code> or
421:             *             <code>end > length()</code>
422:             */
423:            public synchronized StringBuffer delete(int start, int end) {
424:                delete0(start, end);
425:                return this ;
426:            }
427:
428:            /**
429:             * Deletes a single character
430:             * 
431:             * @param location
432:             *            the offset of the character to delete
433:             * @return this StringBuffer
434:             * 
435:             * @throws StringIndexOutOfBoundsException
436:             *             when <code>location < 0</code> or
437:             *             <code>location >= length()</code>
438:             */
439:            public synchronized StringBuffer deleteCharAt(int location) {
440:                deleteCharAt0(location);
441:                return this ;
442:            }
443:
444:            /**
445:             * Ensures that this StringBuffer can hold the specified number of
446:             * characters without growing.
447:             * 
448:             * @param min
449:             *            the minimum number of elements that this StringBuffer will
450:             *            hold before growing
451:             */
452:            @Override
453:            public synchronized void ensureCapacity(int min) {
454:                super .ensureCapacity(min);
455:            }
456:
457:            /**
458:             * Copies the specified characters in this StringBuffer to the character
459:             * array starting at the specified offset in the character array.
460:             * 
461:             * @param start
462:             *            the starting offset of characters to copy
463:             * @param end
464:             *            the ending offset of characters to copy
465:             * @param buffer
466:             *            the destination character array
467:             * @param index
468:             *            the starting offset in the character array
469:             * 
470:             * @throws IndexOutOfBoundsException
471:             *             when <code>start < 0, end > length(),
472:             *				start > end, index < 0, end - start > buffer.length - index</code>
473:             * @throws NullPointerException
474:             *             when buffer is null
475:             */
476:            @Override
477:            public synchronized void getChars(int start, int end,
478:                    char[] buffer, int index) {
479:                super .getChars(start, end, buffer, index);
480:            }
481:
482:            /**
483:             * Searches in this StringBuffer for the index of the specified character.
484:             * The search for the character starts at the specified offset and moves
485:             * towards the end.
486:             * 
487:             * @param subString
488:             *            the string to find
489:             * @param start
490:             *            the starting offset
491:             * @return the index in this StringBuffer of the specified character, -1 if
492:             *         the character isn't found
493:             * 
494:             * @see #lastIndexOf(String,int)
495:             * 
496:             * @since 1.4
497:             */
498:            @Override
499:            public synchronized int indexOf(String subString, int start) {
500:                return super .indexOf(subString, start);
501:            }
502:
503:            /**
504:             * Inserts the character at the specified offset in this StringBuffer.
505:             * 
506:             * @param index
507:             *            the index at which to insert
508:             * @param ch
509:             *            the character to insert
510:             * @return this StringBuffer
511:             * 
512:             * @throws ArrayIndexOutOfBoundsException
513:             *             when <code>index < 0</code> or
514:             *             <code>index > length()</code>
515:             */
516:            public synchronized StringBuffer insert(int index, char ch) {
517:                insert0(index, ch);
518:                return this ;
519:            }
520:
521:            /**
522:             * Inserts the string representation of the specified boolean at the
523:             * specified offset in this StringBuffer.
524:             * 
525:             * @param index
526:             *            the index at which to insert
527:             * @param b
528:             *            the boolean to insert
529:             * @return this StringBuffer
530:             * 
531:             * @throws StringIndexOutOfBoundsException
532:             *             when <code>index < 0</code> or
533:             *             <code>index > length()</code>
534:             */
535:            public StringBuffer insert(int index, boolean b) {
536:                return insert(index, b ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
537:            }
538:
539:            /**
540:             * Inserts the string representation of the specified integer at the
541:             * specified offset in this StringBuffer.
542:             * 
543:             * @param index
544:             *            the index at which to insert
545:             * @param i
546:             *            the integer to insert
547:             * @return this StringBuffer
548:             * 
549:             * @throws StringIndexOutOfBoundsException
550:             *             when <code>index < 0</code> or
551:             *             <code>index > length()</code>
552:             */
553:            public StringBuffer insert(int index, int i) {
554:                return insert(index, Integer.toString(i));
555:            }
556:
557:            /**
558:             * Inserts the string representation of the specified long at the specified
559:             * offset in this StringBuffer.
560:             * 
561:             * @param index
562:             *            the index at which to insert
563:             * @param l
564:             *            the long to insert
565:             * @return this StringBuffer
566:             * 
567:             * @throws StringIndexOutOfBoundsException
568:             *             when <code>index < 0</code> or
569:             *             <code>index > length()</code>
570:             */
571:            public StringBuffer insert(int index, long l) {
572:                return insert(index, Long.toString(l));
573:            }
574:
575:            /**
576:             * Inserts the string representation of the specified double at the
577:             * specified offset in this StringBuffer.
578:             * 
579:             * @param index
580:             *            the index at which to insert
581:             * @param d
582:             *            the double to insert
583:             * @return this StringBuffer
584:             * 
585:             * @throws StringIndexOutOfBoundsException
586:             *             when <code>index < 0</code> or
587:             *             <code>index > length()</code>
588:             */
589:            public StringBuffer insert(int index, double d) {
590:                return insert(index, Double.toString(d));
591:            }
592:
593:            /**
594:             * Inserts the string representation of the specified float at the specified
595:             * offset in this StringBuffer.
596:             * 
597:             * @param index
598:             *            the index at which to insert
599:             * @param f
600:             *            the float to insert
601:             * @return this StringBuffer
602:             * 
603:             * @throws StringIndexOutOfBoundsException
604:             *             when <code>index < 0</code> or
605:             *             <code>index > length()</code>
606:             */
607:            public StringBuffer insert(int index, float f) {
608:                return insert(index, Float.toString(f));
609:            }
610:
611:            /**
612:             * Inserts the string representation of the specified object at the
613:             * specified offset in this StringBuffer.
614:             * 
615:             * @param index
616:             *            the index at which to insert
617:             * @param obj
618:             *            the object to insert
619:             * @return this StringBuffer
620:             * 
621:             * @throws StringIndexOutOfBoundsException
622:             *             when <code>index < 0</code> or
623:             *             <code>index > length()</code>
624:             */
625:            public StringBuffer insert(int index, Object obj) {
626:                return insert(index, obj == null ? "null" : obj.toString()); //$NON-NLS-1$
627:            }
628:
629:            /**
630:             * Inserts the string at the specified offset in this StringBuffer.
631:             * 
632:             * @param index
633:             *            the index at which to insert
634:             * @param string
635:             *            the string to insert
636:             * @return this StringBuffer
637:             * 
638:             * @throws StringIndexOutOfBoundsException
639:             *             when <code>index < 0</code> or
640:             *             <code>index > length()</code>
641:             */
642:            public synchronized StringBuffer insert(int index, String string) {
643:                insert0(index, string);
644:                return this ;
645:            }
646:
647:            /**
648:             * Inserts the character array at the specified offset in this StringBuffer.
649:             * 
650:             * @param index
651:             *            the index at which to insert
652:             * @param chars
653:             *            the character array to insert
654:             * @return this StringBuffer
655:             * 
656:             * @throws StringIndexOutOfBoundsException
657:             *             when <code>index < 0</code> or
658:             *             <code>index > length()</code>
659:             * @throws NullPointerException
660:             *             when chars is null
661:             */
662:            public synchronized StringBuffer insert(int index, char[] chars) {
663:                insert0(index, chars);
664:                return this ;
665:            }
666:
667:            /**
668:             * Inserts the specified sequence of characters at the specified offset in
669:             * this StringBuffer.
670:             * 
671:             * @param index
672:             *            the index at which to insert
673:             * @param chars
674:             *            a character array
675:             * @param start
676:             *            the starting offset
677:             * @param length
678:             *            the number of characters
679:             * @return this StringBuffer
680:             * 
681:             * @throws StringIndexOutOfBoundsException
682:             *             when <code>length < 0, start < 0,</code>
683:             *				<code>start + length > chars.length, index < 0</code>
684:             *             or <code>index > length()</code>
685:             * @throws NullPointerException
686:             *             when chars is null
687:             */
688:            public synchronized StringBuffer insert(int index, char chars[],
689:                    int start, int length) {
690:                insert0(index, chars, start, length);
691:                return this ;
692:            }
693:
694:            /**
695:             * <p>
696:             * Inserts the <code>CharSequence</code> into this buffer at the
697:             * <code>index</code>. If <code>CharSequence</code> is
698:             * <code>null</code>, then the string <code>"null"</code> is inserted.
699:             * </p>
700:             * 
701:             * @param index
702:             *            The index of this buffer to insert the sequence.
703:             * @param s
704:             *            The <code>CharSequence</code> to insert.
705:             * @return A reference to this object.
706:             * @since 1.5
707:             * @throws IndexOutOfBoundsException
708:             *             if the index is invalid.
709:             */
710:            public synchronized StringBuffer insert(int index, CharSequence s) {
711:                insert0(index, s == null ? "null" : s.toString()); //$NON-NLS-1$
712:                return this ;
713:            }
714:
715:            /**
716:             * <p>
717:             * Inserts the <code>CharSequence</code> into this buffer at the
718:             * <code>index</code>. If <code>CharSequence</code> is
719:             * <code>null</code>, then the string <code>"null"</code> is inserted.
720:             * </p>
721:             * 
722:             * @param index
723:             *            The index of this buffer to insert the sequence.
724:             * @param s
725:             *            The <code>CharSequence</code> to insert.
726:             * @param start
727:             *            The inclusive start index of the subsequence of the
728:             *            <code>CharSequence</code>.
729:             * @param end
730:             *            The exclusive end index of the subsequence of the
731:             *            <code>CharSequence</code>.
732:             * @return A reference to this object.
733:             * @since 1.5
734:             * @throws IndexOutOfBoundsException
735:             *             if <code>index</code> is negative or greater than the
736:             *             current length, <code>start</code> or <code>end</code>
737:             *             are negative, <code>start</code> is greater than
738:             *             <code>end</code> or <code>end</code> is greater than the
739:             *             length of <code>s</code>.
740:             */
741:            public synchronized StringBuffer insert(int index, CharSequence s,
742:                    int start, int end) {
743:                insert0(index, s, start, end);
744:                return this ;
745:            }
746:
747:            /**
748:             * Searches in this StringBuffer for the index of the specified character.
749:             * The search for the character starts at the specified offset and moves
750:             * towards the beginning.
751:             * 
752:             * @param subString
753:             *            the string to find
754:             * @param start
755:             *            the starting offset
756:             * @return the index in this StringBuffer of the specified character, -1 if
757:             *         the character isn't found
758:             * 
759:             * @see #indexOf(String,int)
760:             * 
761:             * @since 1.4
762:             */
763:            @Override
764:            public synchronized int lastIndexOf(String subString, int start) {
765:                return super .lastIndexOf(subString, start);
766:            }
767:
768:            /**
769:             * <p>
770:             * Returns the index within this object that is offset from
771:             * <code>index</code> by <code>codePointOffset</code> code points.
772:             * </p>
773:             * 
774:             * @param index
775:             *            The index within this object to calculate the offset from.
776:             * @param codePointOffset
777:             *            The number of code points to count.
778:             * @return The index within this object that is the offset.
779:             * @throws IndexOutOfBoundsException
780:             *             if <code>index</code> is negative or greater than
781:             *             {@link #length()} or if there aren't enough code points
782:             *             before or after <code>index</code> to match
783:             *             <code>codePointOffset</code>.
784:             * @since 1.5
785:             */
786:            @Override
787:            public synchronized int offsetByCodePoints(int index,
788:                    int codePointOffset) {
789:                return super .offsetByCodePoints(index, codePointOffset);
790:            }
791:
792:            /**
793:             * Replace a range of characters with the characters in the specified
794:             * String.
795:             * 
796:             * @param start
797:             *            the offset of the first character
798:             * @param end
799:             *            the offset one past the last character
800:             * @param string
801:             *            a String
802:             * @return this StringBuffer
803:             * 
804:             * @throws StringIndexOutOfBoundsException
805:             *             when <code>start < 0</code> or <code>start > end</code>
806:             */
807:            public synchronized StringBuffer replace(int start, int end,
808:                    String string) {
809:                replace0(start, end, string);
810:                return this ;
811:            }
812:
813:            /**
814:             * Reverses the order of characters in this StringBuffer.
815:             * 
816:             * @return this StringBuffer
817:             */
818:            public synchronized StringBuffer reverse() {
819:                reverse0();
820:                return this ;
821:            }
822:
823:            /**
824:             * Sets the character at the specified offset in this StringBuffer.
825:             * 
826:             * @param index
827:             *            the zero-based index in this StringBuffer
828:             * @param ch
829:             *            the character
830:             * 
831:             * @throws IndexOutOfBoundsException
832:             *             when <code>index < 0</code> or
833:             *             <code>index >= length()</code>
834:             */
835:            @Override
836:            public synchronized void setCharAt(int index, char ch) {
837:                super .setCharAt(index, ch);
838:            }
839:
840:            /**
841:             * Sets the length of this StringBuffer to the specified length. If there
842:             * are more than length characters in this StringBuffer, the characters at
843:             * end are lost. If there are less than length characters in the
844:             * StringBuffer, the additional characters are set to <code>&#92;u0000</code>.
845:             * 
846:             * @param length
847:             *            the new length of this StringBuffer
848:             * 
849:             * @throws IndexOutOfBoundsException
850:             *             when <code>length < 0</code>
851:             * 
852:             * @see #length()
853:             */
854:            @Override
855:            public synchronized void setLength(int length) {
856:                super .setLength(length);
857:            }
858:
859:            /**
860:             * Copies a range of characters into a new String.
861:             * 
862:             * @param start
863:             *            the offset of the first character
864:             * @param end
865:             *            the offset one past the last character
866:             * @return a new String containing the characters from start to end - 1
867:             * 
868:             * @throws IndexOutOfBoundsException
869:             *             when <code>start < 0, start > end</code> or
870:             *             <code>end > length()</code>
871:             * 
872:             * @since 1.4
873:             */
874:            @Override
875:            public synchronized CharSequence subSequence(int start, int end) {
876:                return super .substring(start, end);
877:            }
878:
879:            /**
880:             * Copies a range of characters into a new String.
881:             * 
882:             * @param start
883:             *            the offset of the first character
884:             * @return a new String containing the characters from start to the end of
885:             *         the string
886:             * 
887:             * @throws StringIndexOutOfBoundsException
888:             *             when <code>start < 0</code> or
889:             *             <code>start > length()</code>
890:             */
891:            @Override
892:            public synchronized String substring(int start) {
893:                return super .substring(start);
894:            }
895:
896:            /**
897:             * Copies a range of characters into a new String.
898:             * 
899:             * @param start
900:             *            the offset of the first character
901:             * @param end
902:             *            the offset one past the last character
903:             * @return a new String containing the characters from start to end - 1
904:             * 
905:             * @throws StringIndexOutOfBoundsException
906:             *             when <code>start < 0, start > end</code> or
907:             *             <code>end > length()</code>
908:             */
909:            @Override
910:            public synchronized String substring(int start, int end) {
911:                return super .substring(start, end);
912:            }
913:
914:            /**
915:             * Answers the contents of this StringBuffer.
916:             * 
917:             * @return a String containing the characters in this StringBuffer
918:             */
919:            @Override
920:            public synchronized String toString() {
921:                return super .toString();
922:            }
923:
924:            /**
925:             * <p>
926:             * Trims the storage capacity of this buffer down to the size of the current
927:             * character sequence. Execution of this method may change the results
928:             * returned by the {@link #capacity()} method, but this is not required.
929:             * </p>
930:             * 
931:             * @since 1.5
932:             */
933:            @Override
934:            public synchronized void trimToSize() {
935:                super .trimToSize();
936:            }
937:
938:            private synchronized void writeObject(ObjectOutputStream out)
939:                    throws IOException {
940:                ObjectOutputStream.PutField fields = out.putFields();
941:                fields.put("count", length()); //$NON-NLS-1$
942:                fields.put("shared", false); //$NON-NLS-1$
943:                fields.put("value", getValue()); //$NON-NLS-1$
944:                out.writeFields();
945:            }
946:
947:            private void readObject(ObjectInputStream in) throws IOException,
948:                    ClassNotFoundException {
949:                ObjectInputStream.GetField fields = in.readFields();
950:                int count = fields.get("count", 0); //$NON-NLS-1$
951:                char[] value = (char[]) fields.get("value", null); //$NON-NLS-1$
952:                set(value, count);
953:            }
954:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.