public final class CStringBuilder
- Object
- CStringBuilder
Deprecated. we will be moving to the proper string builder very soon
This is generally the Apache String builder class refactored here so we can
use it regardless of vm limitations/differences for increased performance.
A modifiable sequence of characters for use in creating
and modifying Strings. This class is intended as a direct replacement of
StringBuffer for non-concurrent use; unlike StringBuffer this
class is not synchronized for thread safety.
The majority of the modification methods on this class return StringBuilder, so that, like StringBuffers, they can be used in
chaining method calls together. For example, new StringBuilder("One should ").append("always strive ").append("to achieve Harmony").
Constructors
public CStringBuilder() | Constructs an instance with an initial capacity of 16. |
public CStringBuilder(int capacity) | Constructs an instance with the specified capacity. |
public CStringBuilder(String str) | Constructs an instance that’s initialized with the contents of the specified String. |
Methods
public CStringBuilder append(boolean b) | Appends the string representation of the specified boolean value. |
public CStringBuilder append(char c) | Appends the string representation of the specified char value. |
public CStringBuilder append(int i) | Appends the string representation of the specified int value. |
public CStringBuilder append(long lng) | Appends the string representation of the specified long value. |
public CStringBuilder append(float f) | Appends the string representation of the specified float value. |
public CStringBuilder append(double d) | Appends the string representation of the specified double value. |
public CStringBuilder append(Object obj) | Appends the string representation of the specified Object. |
public CStringBuilder append(String str) | Appends the contents of the specified string. |
public CStringBuilder append(char[] ch) | Appends the string representation of the specified char[]. |
public CStringBuilder append(char[] str, int offset, int len) | Appends the string representation of the specified subset of the char[]. |
public CStringBuilder appendCodePoint(int codePoint) | Appends the encoded Unicode code point. |
public CStringBuilder delete(int start, int end) | Deletes a sequence of characters specified by start and end. |
public CStringBuilder deleteCharAt(int index) | Deletes the character at the specified index. |
public CStringBuilder insert(int offset, boolean b) | Inserts the string representation of the specified boolean value at the specified offset. |
public CStringBuilder insert(int offset, char c) | Inserts the string representation of the specified char value at the specified offset. |
public CStringBuilder insert(int offset, int i) | Inserts the string representation of the specified int value at the specified offset. |
public CStringBuilder insert(int offset, long l) | Inserts the string representation of the specified long value at the specified offset. |
public CStringBuilder insert(int offset, float f) | Inserts the string representation of the specified float value at the specified offset. |
public CStringBuilder insert(int offset, double d) | Inserts the string representation of the specified double value at the specified offset. |
public CStringBuilder insert(int offset, Object obj) | Inserts the string representation of the specified Object at the specified offset. |
public CStringBuilder insert(int offset, String str) | Inserts the specified string at the specified offset. |
public CStringBuilder insert(int offset, char[] ch) | Inserts the string representation of the specified char[] at the specified offset. |
public CStringBuilder insert(int offset, char[] str, int strOffset, int strLen) | Inserts the string representation of the specified subsequence of the char[] at the specified offset. |
public CStringBuilder replace(int start, int end, String str) | Replaces the specified subsequence in this builder with the specified string. |
public CStringBuilder reverse() | Reverses the order of characters in this builder. |
public String toString() | Returns the contents of this builder. |
public int capacity() | Returns the number of characters that can be held without growing. |
public char charAt(int index) | Retrieves the character at the index. |
public void ensureCapacity(int min) | Ensures that this object has a minimum capacity available before requiring the internal buffer to be enlarged. |
public void getChars(int start, int end, char[] dest, int destStart) | Copies the requested sequence of characters to the char[] passed starting at destStart. |
public int length() | The current length. |
public void setCharAt(int index, char ch) | Sets the character at the index. |
public void setLength(int length) | Sets the current length to a new value. |
public String substring(int start) | Returns the String value of the subsequence from the start index to the current end. |
public String substring(int start, int end) | Returns the String value of the subsequence from the start index to the end index. |
public int indexOf(String string) | Searches for the first index of the specified character. |
public int indexOf(String subString, int start) | Searches for the index of the specified character. |
public int lastIndexOf(String string) | Searches for the last index of the specified character. |
public int lastIndexOf(String subString, int start) | Searches for the index of the specified character. |
public void trimToSize() | Trims off any extra capacity beyond the current length. |
public int codePointAt(int index) | Retrieves the Unicode code point value at the index. |
public int codePointBefore(int index) | Retrieves the Unicode code point value that precedes the index. |
public int codePointCount(int beginIndex, int endIndex) | Calculates the number of Unicode code points between beginIndex and endIndex. |
public int offsetByCodePoints(int index, int codePointOffset) | Returns the index that is offset codePointOffset code points from index. |
Inherited methods
Constructor details
CStringBuilder
public CStringBuilder()Constructs an instance with an initial capacity of
16.See also
CStringBuilder
public CStringBuilder(int capacity)Constructs an instance with the specified capacity.
Parameters
capacityint- the initial capacity to use.
Throws
NegativeArraySizeException- if the specified
capacityis negative.
See also
CStringBuilder
public CStringBuilder(String str)Constructs an instance that’s initialized with the contents of the
specified
String. The capacity of the new builder will be the
length of the String plus 16.Parameters
strString- the
Stringto copy into the builder.
Throws
NullPointerException- if
strisnull.
Method details
append
public CStringBuilder append(boolean b)Appends the string representation of the specified
boolean value.
The boolean value is converted to a String according to the rule
defined by String#valueOf(boolean).Parameters
bboolean- the
booleanvalue to append.
Returns
this builder.
See also
append
public CStringBuilder append(char c)Appends the string representation of the specified
char value.
The char value is converted to a string according to the rule
defined by String#valueOf(char).Parameters
cchar- the
charvalue to append.
Returns
this builder.
See also
append
public CStringBuilder append(int i)Appends the string representation of the specified
int value. The
int value is converted to a string according to the rule defined
by String#valueOf(int).Parameters
iint- the
intvalue to append.
Returns
this builder.
See also
append
public CStringBuilder append(long lng)Appends the string representation of the specified
long value.
The long value is converted to a string according to the rule
defined by String#valueOf(long).Parameters
lnglong- the
longvalue.
Returns
this builder.
See also
append
public CStringBuilder append(float f)Appends the string representation of the specified
float value.
The float value is converted to a string according to the rule
defined by String#valueOf(float).Parameters
ffloat- the
floatvalue to append.
Returns
this builder.
See also
append
public CStringBuilder append(double d)Appends the string representation of the specified
double value.
The double value is converted to a string according to the rule
defined by String#valueOf(double).Parameters
ddouble- the
doublevalue to append.
Returns
this builder.
See also
append
public CStringBuilder append(Object obj)Appends the string representation of the specified
Object.
The Object value is converted to a string according to the rule
defined by String#valueOf(Object).Parameters
objObject- the
Objectto append.
Returns
this builder.
See also
append
public CStringBuilder append(String str)Appends the contents of the specified string. If the string is
null, then the string "null" is appended.Parameters
strString- the string to append.
Returns
this builder.
append
public CStringBuilder append(char[] ch)Appends the string representation of the specified
char[].
The char[] is converted to a string according to the rule
defined by String#valueOf(char[]).Parameters
chchar[]- the
char[]to append..
Returns
this builder.
See also
String#valueOf(char[])
append
public CStringBuilder append(char[] str, int offset, int len)Appends the string representation of the specified subset of the
char[]. The char[] value is converted to a String according to
the rule defined by int, int).Parameters
strchar[]- the
char[]to append. offsetint- the inclusive offset index.
lenint- the number of characters.
Returns
this builder.
Throws
ArrayIndexOutOfBoundsException- if
offsetandlendo not specify a valid subsequence.
See also
appendCodePoint
public CStringBuilder appendCodePoint(int codePoint)Appends the encoded Unicode code point. The code point is converted to a
char[] as defined by Character#toChars(int).Parameters
codePointint- the Unicode code point to encode and append.
Returns
this builder.
See also
delete
public CStringBuilder delete(int start, int end)Deletes a sequence of characters specified by
start and end. Shifts any remaining characters to the left.Parameters
startint- the inclusive start index.
endint- the exclusive end index.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
startis less than zero, greater than the current length or greater thanend.
deleteCharAt
public CStringBuilder deleteCharAt(int index)Deletes the character at the specified index. shifts any remaining
characters to the left.
Parameters
indexint- the index of the character to delete.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
indexis less than zero or is greater than or equal to the current length.
insert
public CStringBuilder insert(int offset, boolean b)Inserts the string representation of the specified
boolean value
at the specified offset. The boolean value is converted
to a string according to the rule defined by
String#valueOf(boolean).Parameters
offsetint- the index to insert at.
bboolean- the
booleanvalue to insert.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
offsetis negative or greater than the currentlength.
See also
insert
public CStringBuilder insert(int offset, char c)Inserts the string representation of the specified
char value at
the specified offset. The char value is converted to a
string according to the rule defined by String#valueOf(char).Parameters
offsetint- the index to insert at.
cchar- the
charvalue to insert.
Returns
this builder.
Throws
IndexOutOfBoundsException- if
offsetis negative or greater than the currentlength().
See also
insert
public CStringBuilder insert(int offset, int i)Inserts the string representation of the specified
int value at
the specified offset. The int value is converted to a
String according to the rule defined by String#valueOf(int).Parameters
offsetint- the index to insert at.
iint- the
intvalue to insert.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
offsetis negative or greater than the currentlength().
See also
insert
public CStringBuilder insert(int offset, long l)Inserts the string representation of the specified
long value at
the specified offset. The long value is converted to a
String according to the rule defined by String#valueOf(long).Parameters
offsetint- the index to insert at.
llong- the
longvalue to insert.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
offsetis negative or greater than the current {code length()}.
See also
insert
public CStringBuilder insert(int offset, float f)Inserts the string representation of the specified
float value at
the specified offset. The float value is converted to a
string according to the rule defined by String#valueOf(float).Parameters
offsetint- the index to insert at.
ffloat- the
floatvalue to insert.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
offsetis negative or greater than the currentlength().
See also
insert
public CStringBuilder insert(int offset, double d)Inserts the string representation of the specified
double value
at the specified offset. The double value is converted
to a String according to the rule defined by
String#valueOf(double).Parameters
offsetint- the index to insert at.
ddouble- the
doublevalue to insert.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
offsetis negative or greater than the currentlength().
See also
insert
public CStringBuilder insert(int offset, Object obj)Inserts the string representation of the specified
Object at the
specified offset. The Object value is converted to a
String according to the rule defined by String#valueOf(Object).Parameters
offsetint- the index to insert at.
objObject- the
Objectto insert.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
offsetis negative or greater than the currentlength().
See also
insert
public CStringBuilder insert(int offset, String str)Inserts the specified string at the specified
offset. If the
specified string is null, then the String "null" is inserted.Parameters
offsetint- the index to insert at.
strString- the
Stringto insert.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
offsetis negative or greater than the currentlength().
insert
public CStringBuilder insert(int offset, char[] ch)Inserts the string representation of the specified
char[] at the
specified offset. The char[] value is converted to a
String according to the rule defined by String#valueOf(char[]).Parameters
offsetint- the index to insert at.
chchar[]- the
char[]to insert.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
offsetis negative or greater than the currentlength().
See also
String#valueOf(char[])
insert
public CStringBuilder insert(int offset, char[] str, int strOffset, int strLen)Inserts the string representation of the specified subsequence of the
char[] at the specified offset. The char[] value
is converted to a String according to the rule defined by
int, int).Parameters
offsetint- the index to insert at.
strchar[]- the
char[]to insert. strOffsetint- the inclusive index.
strLenint- the number of characters.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
offsetis negative or greater than the currentlength(), orstrOffsetandstrLendo not specify a valid subsequence.
See also
replace
public CStringBuilder replace(int start, int end, String str)Replaces the specified subsequence in this builder with the specified
string.
Parameters
startint- the inclusive begin index.
endint- the exclusive end index.
strString- the replacement string.
Returns
this builder.
Throws
StringIndexOutOfBoundsException- if
startis negative, greater than the currentlength()or greater thanend. NullPointerException- if
strisnull.
reverse
public CStringBuilder reverse()Reverses the order of characters in this builder.
Returns
this buffer.
toString
public String toString()Returns the contents of this builder.
Returns
the string representation of the data in this builder.
capacity
public int capacity()Returns the number of characters that can be held without growing.
Returns
the capacity
See also
charAt
public char charAt(int index)Retrieves the character at the
index.Parameters
indexint- the index of the character to retrieve.
Returns
the char value.
Throws
IndexOutOfBoundsException- if
indexis negative or greater than or equal to the current#length().
ensureCapacity
public void ensureCapacity(int min)Ensures that this object has a minimum capacity available before
requiring the internal buffer to be enlarged. The general policy of this
method is that if the
minimumCapacity is larger than the current
#capacity(), then the capacity will be increased to the largest
value of either the minimumCapacity or the current capacity
multiplied by two plus two. Although this is the general policy, there is
no guarantee that the capacity will change.Parameters
minint- the new minimum capacity to set.
getChars
public void getChars(int start, int end, char[] dest, int destStart)Copies the requested sequence of characters to the
char[] passed
starting at destStart.Parameters
startint- the inclusive start index of the characters to copy.
endint- the exclusive end index of the characters to copy.
destchar[]- the
char[]to copy the characters to. destStartint- the inclusive start index of
destto begin copying to.
Throws
IndexOutOfBoundsException- if the
startis negative, thedestStartis negative, thestartis greater thanend, theendis greater than the current#length()ordestStart + end - beginis greater thandest.length.
length
public int length()The current length.
Returns
the number of characters contained in this instance.
setCharAt
public void setCharAt(int index, char ch)Sets the character at the
index.Parameters
indexint- the zero-based index of the character to replace.
chchar- the character to set.
Throws
IndexOutOfBoundsException- if
indexis negative or greater than or equal to the current#length().
setLength
public void setLength(int length)Sets the current length to a new value. If the new length is larger than
the current length, then the new characters at the end of this object
will contain the
char value of �.Parameters
lengthint- the new length of this StringBuffer.
Throws
IndexOutOfBoundsException- if
length < 0.
See also
substring
public String substring(int start)Returns the String value of the subsequence from the
start index
to the current end.Parameters
startint- the inclusive start index to begin the subsequence.
Returns
a String containing the subsequence.
Throws
StringIndexOutOfBoundsException- if
startis negative or greater than the current#length().
substring
public String substring(int start, int end)Returns the String value of the subsequence from the
start index
to the end index.Parameters
startint- the inclusive start index to begin the subsequence.
endint- the exclusive end index to end the subsequence.
Returns
a String containing the subsequence.
Throws
StringIndexOutOfBoundsException- if
startis negative, greater thanendor ifendis greater than the current#length().
indexOf
public int indexOf(String string)Searches for the first index of the specified character. The search for
the character starts at the beginning and moves towards the end.
Parameters
stringString- the string to find.
Returns
the index of the specified character, -1 if the character isn’t
found.
See also
indexOf
public int indexOf(String subString, int start)Searches for the index of the specified character. The search for the
character starts at the specified offset and moves towards the end.
Parameters
subStringString- the string to find.
startint- the starting offset.
Returns
the index of the specified character, -1 if the character isn’t
found
See also
lastIndexOf
public int lastIndexOf(String string)Searches for the last index of the specified character. The search for
the character starts at the end and moves towards the beginning.
Parameters
stringString- the string to find.
Returns
the index of the specified character, -1 if the character isn’t
found.
Throws
NullPointerException- if
stringisnull.
lastIndexOf
public int lastIndexOf(String subString, int start)Searches for the index of the specified character. The search for the
character starts at the specified offset and moves towards the beginning.
Parameters
subStringString- the string to find.
startint- the starting offset.
Returns
the index of the specified character, -1 if the character isn’t
found.
Throws
NullPointerException- if
subStringisnull.
See also
trimToSize
public void trimToSize()Trims off any extra capacity beyond the current length. Note, this method
is NOT guaranteed to change the capacity of this object.
codePointAt
public int codePointAt(int index)Retrieves the Unicode code point value at the
index.Parameters
indexint- the index to the
charcode unit.
Returns
the Unicode code point value.
Throws
IndexOutOfBoundsException- if
indexis negative or greater than or equal to#length().
codePointBefore
public int codePointBefore(int index)Retrieves the Unicode code point value that precedes the
index.Parameters
indexint- the index to the
charcode unit within this object.
Returns
the Unicode code point value.
Throws
IndexOutOfBoundsException- if
indexis less than 1 or greater than#length().
codePointCount
public int codePointCount(int beginIndex, int endIndex)Calculates the number of Unicode code points between
beginIndex
and endIndex.Parameters
beginIndexint- the inclusive beginning index of the subsequence.
endIndexint- the exclusive end index of the subsequence.
Returns
the number of Unicode code points in the subsequence.
Throws
IndexOutOfBoundsException- if
beginIndexis negative or greater thanendIndexorendIndexis greater than#length().
offsetByCodePoints
public int offsetByCodePoints(int index, int codePointOffset)Returns the index that is offset
codePointOffset code points from
index.Parameters
indexint- the index to calculate the offset from.
codePointOffsetint- the number of code points to count.
Returns
the index that is
codePointOffset code points away from
index.Throws
IndexOutOfBoundsException- if
indexis negative or greater than#length()or if there aren’t enough code points before or afterindexto matchcodePointOffset.