com.ibm.commons.util
Class FastStringBuffer

java.lang.Object
  extended by com.ibm.commons.util.FastStringBuffer

public class FastStringBuffer
extends java.lang.Object

Fast String buffer.

This class has almost all the methods found in the standard StringBuffer but is faster for many reasons :
It also has bonus methods which are very helpful.


Constructor Summary
FastStringBuffer()
          Constructs a string buffer with no characters in it and an initial capacity of DELTA characters.
FastStringBuffer(char[] buffer, int count)
          Constructs a string buffer from an array of characters.
FastStringBuffer(int length)
          Constructs a string buffer with no characters in it and an initial capacity specified by the length argument.
FastStringBuffer(java.lang.String str)
          Constructs a string buffer so that it represents the same sequence of characters as the string argument.
FastStringBuffer(java.lang.String str, int srcBegin, int srcEnd)
          Constructs a string buffer so that it represents the same sequence of characters as the string argument.
 
Method Summary
 FastStringBuffer append(boolean b)
          Appends the string representation of the boolean argument to the string buffer.
 FastStringBuffer append(char c)
          Appends the string representation of the char argument to this string buffer.
 FastStringBuffer append(char[] str)
          Appends the string representation of the char array argument to this string buffer.
 FastStringBuffer append(char[] str, int offset, int len)
          Appends the string representation of a subarray of the char array argument to this string buffer.
 FastStringBuffer append(double d)
          Appends the string representation of the double argument to this string buffer.
 FastStringBuffer append(FastStringBuffer b)
           
 FastStringBuffer append(FastStringBuffer b, int srcBegin, int srcEnd)
           
 FastStringBuffer append(float f)
          Appends the string representation of the float argument to this string buffer.
 FastStringBuffer append(int i)
          Appends the string representation of the int argument to this string buffer.
 FastStringBuffer append(long l)
          Appends the string representation of the long argument to this string buffer.
 FastStringBuffer append(java.lang.Object obj)
          Appends the string representation of the Object argument to this string buffer.
 FastStringBuffer append(java.io.Reader r)
          Append the content of a IO reader.
 FastStringBuffer append(java.lang.String str)
          Appends the string to this string buffer.
 FastStringBuffer append(java.lang.String str, int srcBegin, int srcEnd)
           
 FastStringBuffer appendFormat(java.lang.String fmt, java.lang.Object... args)
          Append a formatted string.
 FastStringBuffer appendJavaString(java.lang.String s, boolean addQuotes)
          Append a java string to the buffer.
 int capacity()
          Returns the current capacity of the String buffer.
 char charAt(int index)
          Returns the character at a specific index in this string buffer.
 void clear()
          Clear the content of the buffer.
 void delete(int begin, int end)
          Delete a part of the buffer.
 boolean equals(java.lang.String str)
          Compare the buffer to a string.
 void flush(java.io.Writer w)
           
 void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
          Characters are copied from this string buffer into the destination character array dst.
 char getLastChar()
          Get the last character contained in the buffer
 int indexOf(char c)
           
 int indexOf(char c, int begin)
          Search an instance of a char.
 int indexOf(java.lang.String string)
           
 int indexOf(java.lang.String string, int begin)
          Search an instance of a string.
 FastStringBuffer insert(int offset, boolean b)
          Inserts the string representation of the boolean argument into this string buffer.
 FastStringBuffer insert(int offset, char c)
          Inserts the string representation of the char argument into this string buffer.
 FastStringBuffer insert(int offset, char[] str)
          Inserts the string representation of the char array argument into this string buffer.
 FastStringBuffer insert(int offset, double d)
          Inserts the string representation of the double argument into this string buffer.
 FastStringBuffer insert(int offset, float f)
          Inserts the string representation of the float argument into this string buffer.
 FastStringBuffer insert(int offset, int i)
          Inserts the string representation of the second int argument into this string buffer.
 FastStringBuffer insert(int offset, long l)
          Inserts the string representation of the long argument into this string buffer.
 FastStringBuffer insert(int offset, java.lang.Object obj)
          Inserts the string representation of the Object argument into this string buffer.
 FastStringBuffer insert(int offset, java.lang.String str)
          Inserts the string into this string buffer.
 int lastIndexOf(char c)
           
 int lastIndexOf(char c, int end)
          Search the last instance of a char.
 int length()
          Returns the length (character count) of this string buffer.
 FastStringBuffer load(java.io.Reader r)
          Load the content of a IO reader.
 FastStringBuffer prt(java.lang.String fmt)
           
 FastStringBuffer prt(java.lang.String fmt, java.lang.Object p1)
           
 FastStringBuffer prt(java.lang.String fmt, java.lang.Object p1, java.lang.Object p2)
           
 FastStringBuffer prt(java.lang.String fmt, java.lang.Object p1, java.lang.Object p2, java.lang.Object p3)
           
 FastStringBuffer prt(java.lang.String fmt, java.lang.Object p1, java.lang.Object p2, java.lang.Object p3, java.lang.Object p4)
           
 FastStringBuffer prt(java.lang.String fmt, java.lang.Object p1, java.lang.Object p2, java.lang.Object p3, java.lang.Object p4, java.lang.Object p5)
           
 void repeat(char toRepeat, int count)
          Append a repeated character.
 void repeat(java.lang.String toRepeat, int count)
          Append a repeated character string.
 void replace(int begin, int end, char[] replace)
          Replace a buffer part.
 void replace(int begin, int end, FastStringBuffer replace)
          Replace a buffer part.
 void replace(int begin, int end, java.lang.String replace)
          Replace a buffer part.
 void replace(java.lang.String oldString, java.lang.String newString)
          Replace a set of Strings.
 FastStringBuffer reverse()
          The character sequence contained in this string buffer is replaced by the reverse of the sequence.
 void save(java.io.Writer w)
          Save the content to a writer.
 void setCharAt(int index, char ch)
          The character at the specified index of tiis string buffer is set to ch.
 boolean startsWith(char c)
           
 java.lang.String substring(int first, int last)
          Extract a part of the string buffer to a string.
 char[] toCharArray()
          Convert the buffer to an array of chars.
 java.lang.String toString()
          Converts to a string representing the data in this string buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FastStringBuffer

public FastStringBuffer()
Constructs a string buffer with no characters in it and an initial capacity of DELTA characters.


FastStringBuffer

public FastStringBuffer(int length)
Constructs a string buffer with no characters in it and an initial capacity specified by the length argument.

Parameters:
length - the initial capacity.

FastStringBuffer

public FastStringBuffer(char[] buffer,
                        int count)
Constructs a string buffer from an array of characters. The array is not initially copied into the string buffer, but rather referenced.

Parameters:
buffer - of characters to be managed by this class
count, - the number (in char) of useful information contained in the array.
Throws:
java.lang.IllegalArgumentException - , if buffer parameter is null.

FastStringBuffer

public FastStringBuffer(java.lang.String str)
Constructs a string buffer so that it represents the same sequence of characters as the string argument. The initial capacity of the string buffer is DELTA plus the length of the string argument.

Parameters:
str - the initial contents of the buffer.

FastStringBuffer

public FastStringBuffer(java.lang.String str,
                        int srcBegin,
                        int srcEnd)
Constructs a string buffer so that it represents the same sequence of characters as the string argument. The initial capacity of the string buffer is DELTA plus the length of the string argument.

Parameters:
str - the initial contents of the buffer.
srcBegin - start copying at this offset in the string.
srcEnd - stop copying at this offset in the string.
Method Detail

length

public final int length()
Returns the length (character count) of this string buffer.

Returns:
the number of characters in this string buffer.

capacity

public final int capacity()
Returns the current capacity of the String buffer. The capacity is the amount of storage available for newly inserted characters; beyond which an allocation will occur.

Returns:
the current capacity of this string buffer.

charAt

public final char charAt(int index)
Returns the character at a specific index in this string buffer.

The first character of a string buffer is at index 0, the next at index 1, and so on, for array indexing.

The index argument must be greater than or equal to 0, and less than the length of this string buffer.

Parameters:
index - the index of the desired character.
Returns:
the character at the specified index of this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the index is invalid.
See Also:
com.ibm.jscript.util.FastStringBuffer#length(), com.ibm.jscript.util.StringBuffer#length()

getChars

public final void getChars(int srcBegin,
                           int srcEnd,
                           char[] dst,
                           int dstBegin)
Characters are copied from this string buffer into the destination character array dst. The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. The total number of characters to be copied is srcEnd-srcBegin. The characters are copied into the subarray of dst starting at index dstBegin and ending at index:

     dstbegin + (srcEnd-srcBegin) - 1
 

Parameters:
srcBegin - start copying at this offset in the string buffer.
srcEnd - stop copying at this offset in the string buffer.
dst - the array to copy the data into.
dstBegin - offset into dst.
Throws:
java.lang.StringIndexOutOfBoundsException - if there is an invalid index into the buffer.

setCharAt

public final void setCharAt(int index,
                            char ch)
The character at the specified index of tiis string buffer is set to ch.

The offset argument must be greater than or equal to 0, and less than the length of this string buffer.

Parameters:
index - the index of the character to modify.
ch - the new character.
Throws:
java.lang.StringIndexOutOfBoundsException - if the index is invalid.
See Also:
com.ibm.jscript.util.StringBuffer#length()

append

public final FastStringBuffer append(java.lang.Object obj)
Appends the string representation of the Object argument to this string buffer.

The argument is converted to a string as if by the method String.valueOf, and the characters of that string are then appended to this string buffer.

Parameters:
obj - an Object.
Returns:
this string buffer.
See Also:
com.ibm.jscript.util.String#valueOf(java.lang.Object), com.ibm.jscript.util.StringBuffer#append(java.lang.String)

append

public final FastStringBuffer append(java.lang.String str)
Appends the string to this string buffer.

The characters of the String argument are appended, in order, to the contents of this string buffer, increasing the length of this string buffer by the length of the argument.

Parameters:
str - a string.
Returns:
this string buffer.

append

public final FastStringBuffer append(char[] str)
Appends the string representation of the char array argument to this string buffer.

The characters of the array argument are appended, in order, to the contents of this string buffer. The length of this string buffer increases by the length of the argument.

Parameters:
str - the characters to be appended.
Returns:
this string buffer.

append

public final FastStringBuffer append(char[] str,
                                     int offset,
                                     int len)
Appends the string representation of a subarray of the char array argument to this string buffer.

Characters of the character array str, starting at index offset, are appended, in order, to the contents of this string buffer. The length of this string buffer increases by the value of len.

Parameters:
str - the characters to be appended.
offset - the index of the first character to append.
len - the number of characters to append.
Returns:
this string buffer.

append

public final FastStringBuffer append(boolean b)
Appends the string representation of the boolean argument to the string buffer.

The argument is converted to a string as if by the method String.valueOf, and the characters of that string are then appended to this string buffer.

Parameters:
b - a boolean.
Returns:
this string buffer.
See Also:
com.ibm.jscript.util.String#valueOf(boolean), com.ibm.jscript.util.StringBuffer#append(java.lang.String)

append

public final FastStringBuffer append(char c)
Appends the string representation of the char argument to this string buffer.

The argument is appended to the contents of this string buffer. The length of this string buffer increases by 1.

Parameters:
ch - a char.
Returns:
this string buffer.

append

public final FastStringBuffer append(int i)
Appends the string representation of the int argument to this string buffer.

The argument is converted to a string as if by the method String.valueOf, and the characters of that string are then appended to this string buffer.

Parameters:
i - an int.
Returns:
this string buffer.
See Also:
com.ibm.jscript.util.String#valueOf(int), com.ibm.jscript.util.StringBuffer#append(java.lang.String)

append

public final FastStringBuffer append(long l)
Appends the string representation of the long argument to this string buffer.

The argument is converted to a string as if by the method String.valueOf, and the characters of that string are then appended to this string buffer.

Parameters:
l - a long.
Returns:
this string buffer.

append

public final FastStringBuffer append(float f)
Appends the string representation of the float argument to this string buffer.

The argument is converted to a string as if by the method String.valueOf, and the characters of that string are then appended to this string buffer.

Parameters:
f - a float.
Returns:
this string buffer.

append

public final FastStringBuffer append(double d)
Appends the string representation of the double argument to this string buffer.

The argument is converted to a string as if by the method String.valueOf, and the characters of that string are then appended to this string buffer.

Parameters:
d - a double.
Returns:
this string buffer.

insert

public final FastStringBuffer insert(int offset,
                                     java.lang.Object obj)
Inserts the string representation of the Object argument into this string buffer.

The second argument is converted to a string as if by the method String.valueOf, and the characters of that string are then inserted into this string buffer at the indicated offset.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
b - an Object.
Returns:
this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the offset is invalid.

insert

public final FastStringBuffer insert(int offset,
                                     java.lang.String str)
Inserts the string into this string buffer.

The characters of the String argument are inserted, in order, into this string buffer at the indicated offset. The length of this string buffer is increased by the length of the argument.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
str - a string.
Returns:
this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the offset is invalid.

insert

public final FastStringBuffer insert(int offset,
                                     char[] str)
Inserts the string representation of the char array argument into this string buffer.

The characters of the array argument are inserted into the contents of this string buffer at the position indicated by offset. The length of this string buffer increases by the length of the argument.

Parameters:
offset - the offset.
ch - a character array.
Returns:
this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the offset is invalid.

insert

public final FastStringBuffer insert(int offset,
                                     boolean b)
Inserts the string representation of the boolean argument into this string buffer.

The second argument is converted to a string as if by the method String.valueOf, and the characters of that string are then inserted into this string buffer at the indicated offset.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
b - a boolean.
Returns:
this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the offset is invalid.

insert

public final FastStringBuffer insert(int offset,
                                     char c)
Inserts the string representation of the char argument into this string buffer.

The second argument is inserted into the contents of this string buffer at the position indicated by offset. The length of this string buffer increases by one.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
ch - a char.
Returns:
this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the offset is invalid.

insert

public final FastStringBuffer insert(int offset,
                                     int i)
Inserts the string representation of the second int argument into this string buffer.

The second argument is converted to a string as if by the method String.valueOf, and the characters of that string are then inserted into this string buffer at the indicated offset.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
b - an int.
Returns:
this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the offset is invalid.

insert

public final FastStringBuffer insert(int offset,
                                     long l)
Inserts the string representation of the long argument into this string buffer.

The second argument is converted to a string as if by the method String.valueOf, and the characters of that string are then inserted into this string buffer at the indicated offset.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
b - a long.
Returns:
this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the offset is invalid.

insert

public final FastStringBuffer insert(int offset,
                                     float f)
Inserts the string representation of the float argument into this string buffer.

The second argument is converted to a string as if by the method String.valueOf, and the characters of that string are then inserted into this string buffer at the indicated offset.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
b - a float.
Returns:
this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the offset is invalid.

insert

public final FastStringBuffer insert(int offset,
                                     double d)
Inserts the string representation of the double argument into this string buffer.

The second argument is converted to a string as if by the method String.valueOf, and the characters of that string are then inserted into this string buffer at the indicated offset.

The offset argument must be greater than or equal to 0, and less than or equal to the length of this string buffer.

Parameters:
offset - the offset.
b - a double.
Returns:
this string buffer.
Throws:
java.lang.StringIndexOutOfBoundsException - if the offset is invalid.

reverse

public final FastStringBuffer reverse()
The character sequence contained in this string buffer is replaced by the reverse of the sequence.

Returns:
this string buffer.

toString

public java.lang.String toString()
Converts to a string representing the data in this string buffer. A new String object is allocated and initialized to contain the character sequence currently represented by this string buffer. This String is then returned. Subsequent changes to the string buffer do not affect the contents of the String.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the string buffer.

clear

public final void clear()
Clear the content of the buffer. Simply the count is reseted. No allocation is done.


equals

public boolean equals(java.lang.String str)
Compare the buffer to a string.


startsWith

public final boolean startsWith(char c)

repeat

public final void repeat(java.lang.String toRepeat,
                         int count)
Append a repeated character string.

Parameters:
toRepeat - the string to repeat
count - the number of repetition

repeat

public final void repeat(char toRepeat,
                         int count)
Append a repeated character.

Parameters:
toRepeat - the character to repeat
count - the number of repetition

append

public final FastStringBuffer append(FastStringBuffer b,
                                     int srcBegin,
                                     int srcEnd)

append

public final FastStringBuffer append(FastStringBuffer b)

append

public final FastStringBuffer append(java.lang.String str,
                                     int srcBegin,
                                     int srcEnd)

load

public final FastStringBuffer load(java.io.Reader r)
Load the content of a IO reader.


append

public final FastStringBuffer append(java.io.Reader r)
Append the content of a IO reader.


save

public final void save(java.io.Writer w)
Save the content to a writer.


flush

public final void flush(java.io.Writer w)
                 throws java.io.IOException
Throws:
java.io.IOException

toCharArray

public final char[] toCharArray()
Convert the buffer to an array of chars.

Returns:
an array of chars containing all the chars

substring

public final java.lang.String substring(int first,
                                        int last)
Extract a part of the string buffer to a string.

Returns:
the substring

delete

public final void delete(int begin,
                         int end)
Delete a part of the buffer.


replace

public final void replace(int begin,
                          int end,
                          java.lang.String replace)
Replace a buffer part.


replace

public final void replace(int begin,
                          int end,
                          char[] replace)
Replace a buffer part.


replace

public final void replace(int begin,
                          int end,
                          FastStringBuffer replace)
Replace a buffer part.


replace

public final void replace(java.lang.String oldString,
                          java.lang.String newString)
Replace a set of Strings.


indexOf

public int indexOf(char c,
                   int begin)
Search an instance of a char.


indexOf

public int indexOf(char c)

indexOf

public int indexOf(java.lang.String string,
                   int begin)
Search an instance of a string.


indexOf

public int indexOf(java.lang.String string)

lastIndexOf

public int lastIndexOf(char c,
                       int end)
Search the last instance of a char.


lastIndexOf

public int lastIndexOf(char c)

getLastChar

public char getLastChar()
Get the last character contained in the buffer

Returns:
the last character, '\0' if the buffer is empty

appendFormat

public final FastStringBuffer appendFormat(java.lang.String fmt,
                                           java.lang.Object... args)
Append a formatted string. A call to TString.toString() is made for each object. By this way, arrays are properly dumped. modified by dhan


prt

public final FastStringBuffer prt(java.lang.String fmt,
                                  java.lang.Object p1,
                                  java.lang.Object p2,
                                  java.lang.Object p3,
                                  java.lang.Object p4,
                                  java.lang.Object p5)

prt

public final FastStringBuffer prt(java.lang.String fmt,
                                  java.lang.Object p1,
                                  java.lang.Object p2,
                                  java.lang.Object p3,
                                  java.lang.Object p4)

prt

public final FastStringBuffer prt(java.lang.String fmt,
                                  java.lang.Object p1,
                                  java.lang.Object p2,
                                  java.lang.Object p3)

prt

public final FastStringBuffer prt(java.lang.String fmt,
                                  java.lang.Object p1,
                                  java.lang.Object p2)

prt

public final FastStringBuffer prt(java.lang.String fmt,
                                  java.lang.Object p1)

prt

public final FastStringBuffer prt(java.lang.String fmt)

appendJavaString

public FastStringBuffer appendJavaString(java.lang.String s,
                                         boolean addQuotes)
Append a java string to the buffer. All the java escape charcters are transformed.