All Packages This Package Class Hierarchy Class Search Index
Class calypso.util.StringBuf
java.lang.Object | +----calypso.util.StringBuf
- None of the methods are synchronized
- There is no sharing of the character array
- Converting to a String requires a copy of the character data
- Alloc and Recycle are provided to speed up allocation
- A bunch of useful operations are provided (comparisons, etc.)
This class is similar to java/lang/StringBuffer with the following changes:
public final class StringBuf extends java.lang.Object { // Fields 3 private int count; static StringBufRecycler gRecycler; private char[] value; // Constructors 4 public StringBuf(); public StringBuf(char[], int, int); public StringBuf(int); public StringBuf(String); // Methods 51 public static synchronized StringBuf Alloc(); public static synchronized void EmptyRecycler(); public static synchronized void Recycle(StringBuf); public StringBuf append(boolean); public StringBuf append(char); public StringBuf append(char[]); public StringBuf append(char[], int, int); public StringBuf append(double); public StringBuf append(float); public StringBuf append(int); public StringBuf append(Object); public StringBuf append(String); public StringBuf append(long); public StringBuf assign(char[]); public StringBuf assign(char[], int, int); public StringBuf assign(String); public int capacity(); public char charAt(int); static void classFinalize() throws Throwable; public void compressWhitespace(boolean); public void ensureCapacity(int); public boolean equals(StringBuf); public boolean equals(Object); public boolean equals(String); public boolean equalsIgnoreCase(StringBuf); public boolean equalsIgnoreCase(int, int, String); public boolean equalsIgnoreCase(String); public void getChars(int, int, char[], int); public int indexOf(int); public int indexOf(int, int); public StringBuf insert(int, boolean); public StringBuf insert(int, char); public StringBuf insert(int, char[]); public StringBuf insert(int, double); public StringBuf insert(int, float); public StringBuf insert(int, int); public StringBuf insert(int, Object); public StringBuf insert(int, String); public StringBuf insert(int, long); public boolean isWhitespace(); public int length(); public void remove(int); public void remove(int, int); public StringBuf reverse(); public void setCharAt(int, char); public void setEmpty(); public void setLength(int); public char[] toChars(); public void toLowerCase(); public String toString(); public void toUpperCase(); }
Fields
value
private char[] value
count
private int count
gRecycler
static StringBufRecycler gRecycler
Constructors
StringBuf
public StringBuf()
Constructs an empty String buffer.
StringBuf
public StringBuf(int length)
Constructs an empty String buffer with the specified initial length.
Parameter Description length the initial length
StringBuf
public StringBuf(String str)
Constructs a String buffer with the specified initial value.
Parameter Description str the initial value of the buffer
StringBuf
public StringBuf(char[] chars, int offset, int length)
Methods
Alloc
public static synchronized StringBuf Alloc()
Constructs an empty String buffer, reusing one from the recycler.
Recycle
public static synchronized void Recycle(StringBuf aBuf)
Release a StringBuf to the recycler. It is up to the caller to ensure that buffer is no longer being used otherwise unpredicatable program behavior will result.
EmptyRecycler
public static synchronized void EmptyRecycler()
Empty the recycler discarding any cached StringBuf objects
classFinalize
static void classFinalize() throws Throwable
length
public int length()
Returns the length (character count) of the buffer.
capacity
public 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.
ensureCapacity
public void ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the specified minimum.
Parameter Description minimumCapacity the minimum desired capacity
setLength
public void setLength(int newLength)
Sets the length of the String. If the length is reduced, characters are lost. If the length is extended, the values of the new characters are set to 0.
Parameter Description newLength the new length of the buffer
- Throws: StringIndexOutOfBoundsException
- If the length is invalid.
setEmpty
public void setEmpty()
Clear the content for reuse. Farster than setLength(0).
charAt
public char charAt(int index)
Returns the character at the specified index. An index ranges from 0..length()-1.
Parameter Description index the index of the desired character
- Throws: StringIndexOutOfBoundsException
- If the index is invalid.
getChars
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
Copies the characters of the specified substring (determined by srcBegin and srcEnd) into the character array, starting at the array's dstBegin location. Both srcBegin and srcEnd must be legal indexes into the buffer.
Parameter Description srcBegin begin copy at this offset in the String srcEnd stop copying at this offset in the String dst the array to copy the data into dstBegin offset into dst
- Throws: StringIndexOutOfBoundsException
- If there is an invalid index into the buffer.
setCharAt
public void setCharAt(int index, char ch)
Changes the character at the specified index to be ch.
Parameter Description index the index of the character ch the new character
- Throws: StringIndexOutOfBoundsException
- If the index is invalid.
append
public StringBuf append(Object obj)
Appends an object to the end of this buffer.
Parameter Description obj the object to be appended
- Returns:
- the StringBuf itself, NOT a new one.
append
public StringBuf append(String str)
Appends a String to the end of this buffer.
Parameter Description str the String to be appended
- Returns:
- the StringBuf itself, NOT a new one.
append
public StringBuf append(char[] str)
Appends an array of characters to the end of this buffer.
Parameter Description str the characters to be appended
- Returns:
- the StringBuf itself, NOT a new one.
assign
public StringBuf assign(char[] str)
assign
public StringBuf assign(String str)
assign
public StringBuf assign(char[] str, int offset, int len)
append
public StringBuf append(char[] str, int offset, int len)
Appends a part of an array of characters to the end of this buffer.
Parameter Description str the characters to be appended offset where to start len the number of characters to add
- Returns:
- the StringBuf itself, NOT a new one.
append
public StringBuf append(boolean b)
Appends a boolean to the end of this buffer.
Parameter Description b the boolean to be appended
- Returns:
- the StringBuf itself, NOT a new one.
append
public StringBuf append(char c)
Appends a character to the end of this buffer.
Parameter Description ch the character to be appended
- Returns:
- the StringBuf itself, NOT a new one.
append
public StringBuf append(int i)
Appends an integer to the end of this buffer.
Parameter Description i the integer to be appended
- Returns:
- the StringBuf itself, NOT a new one.
append
public StringBuf append(long l)
Appends a long to the end of this buffer.
Parameter Description l the long to be appended
- Returns:
- the StringBuf itself, NOT a new one.
append
public StringBuf append(float f)
Appends a float to the end of this buffer.
Parameter Description f the float to be appended
- Returns:
- the StringBuf itself, NOT a new one.
append
public StringBuf append(double d)
Appends a double to the end of this buffer.
Parameter Description d the double to be appended
- Returns:
- the StringBuf itself, NOT a new one.
insert
public StringBuf insert(int offset, Object obj)
Inserts an object into the String buffer.
Parameter Description offset the offset at which to insert obj the object to insert
- Returns:
- the StringBuf itself, NOT a new one.
- Throws: StringIndexOutOfBoundsException
- If the offset is invalid.
insert
public StringBuf insert(int offset, String str)
Inserts a String into the String buffer.
Parameter Description offset the offset at which to insert str the String to insert
- Returns:
- the StringBuf itself, NOT a new one.
- Throws: StringIndexOutOfBoundsException
- If the offset is invalid.
insert
public StringBuf insert(int offset, char[] str)
Inserts an array of characters into the String buffer.
Parameter Description offset the offset at which to insert str the characters to insert
- Returns:
- the StringBuf itself, NOT a new one.
- Throws: StringIndexOutOfBoundsException
- If the offset is invalid.
insert
public StringBuf insert(int offset, boolean b)
Inserts a boolean into the String buffer.
Parameter Description offset the offset at which to insert b the boolean to insert
- Returns:
- the StringBuf itself, NOT a new one.
- Throws: StringIndexOutOfBoundsException
- If the offset is invalid.
insert
public StringBuf insert(int offset, char c)
Inserts a character into the String buffer.
Parameter Description offset the offset at which to insert ch the character to insert
- Returns:
- the StringBuf itself, NOT a new one.
- Throws: StringIndexOutOfBoundsException
- If the offset invalid.
insert
public StringBuf insert(int offset, int i)
Inserts an integer into the String buffer.
Parameter Description offset the offset at which to insert i the integer to insert
- Returns:
- the StringBuf itself, NOT a new one.
- Throws: StringIndexOutOfBoundsException
- If the offset is invalid.
insert
public StringBuf insert(int offset, long l)
Inserts a long into the String buffer.
Parameter Description offset the offset at which to insert l the long to insert
- Returns:
- the StringBuf itself, NOT a new one.
- Throws: StringIndexOutOfBoundsException
- If the offset is invalid.
insert
public StringBuf insert(int offset, float f)
Inserts a float into the String buffer.
Parameter Description offset the offset at which to insert f the float to insert
- Returns:
- the StringBuf itself, NOT a new one.
- Throws: StringIndexOutOfBoundsException
- If the offset is invalid.
insert
public StringBuf insert(int offset, double d)
Inserts a double into the String buffer.
Parameter Description offset the offset at which to insert d the double to insert
- Returns:
- the StringBuf itself, NOT a new one.
- Throws: StringIndexOutOfBoundsException
- If the offset is invalid.
reverse
public StringBuf reverse()
Reverse the order of the characters in the String buffer.
toUpperCase
public void toUpperCase()
toLowerCase
public void toLowerCase()
toString
public String toString()
toChars
public char[] toChars()
compressWhitespace
public void compressWhitespace(boolean aStripLeadingWhitespace)
Compress the whitespace present in the buffer. XXX I suppose there are i18n issues with this after all a space is probably not a space...
isWhitespace
public boolean isWhitespace()
Return true if the string buffer contains nothing but whitespace as defined by Character.isWhitespace()
equalsIgnoreCase
public boolean equalsIgnoreCase(String anotherString)
Compares this StringBuf to another String. Returns true if the String is equal to this StringBuf; that is, has the same length and the same characters in the same sequence. Upper case characters are folded to lower case before they are compared.
Parameter Description anotherString the String to compare this String against
- Returns:
- true if the Strings are equal, ignoring case; false otherwise.
equalsIgnoreCase
public boolean equalsIgnoreCase(int aStart, int aLength, String anotherString)
equalsIgnoreCase
public boolean equalsIgnoreCase(StringBuf anotherString)
Compares this StringBuf to another StringBuf. Returns true if the other StringBuf is equal to this StringBuf; that is, has the same length and the same characters in the same sequence. Upper case characters are folded to lower case before they are compared.
Parameter Description anotherString the String to compare this String against
- Returns:
- true if the Strings are equal, ignoring case; false otherwise.
equals
public boolean equals(Object aObject)
equals
public boolean equals(StringBuf anotherString)
Compares this StringBuf to another StringBuf. Returns true if the other StringBuf is equal to this StringBuf; that is, has the same length and the same characters in the same sequence.
Parameter Description anotherString the String to compare this String against
- Returns:
- true if the Strings are equal, ignoring case; false otherwise.
equals
public boolean equals(String anotherString)
Compares this StringBuf to another String. Returns true if the other String is equal to this StringBuf; that is, has the same length and the same characters in the same sequence.
Parameter Description anotherString the String to compare this String against
- Returns:
- true if the Strings are equal, ignoring case; false otherwise.
indexOf
public int indexOf(int ch)
indexOf
public int indexOf(int ch, int fromIndex)
remove
public void remove(int fromIndex)
remove
public void remove(int fromIndex, int toIndex)
Remove characters from the StringBuf starting at fromIndex and up to but not including toIndex. If toIndex is beyond the length of the StringBuf then it is automatically clamped to the end of the StringBuf. If fromIndex is out of range a StringIndexOutOfBoundsException is thrown.
All Packages This Package Class Hierarchy Class Search IndexFreshly brewed Java API Documentation automatically generated with polardoc Version 1.0.4