Class calypso.util.StringBuf
All Packages This Package Class Hierarchy Class Search Index
Class calypso.util.StringBuf
java.lang.Object
|
+----calypso.util.StringBuf
This class is similar to java/lang/StringBuffer with the following changes:
- 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.)
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
private char[] value
private int count
static StringBufRecycler gRecycler
Constructors
public StringBuf()
Constructs an empty String buffer.
public StringBuf(int length)
Constructs an empty String buffer with the specified initial length.
| Parameter | Description |
| length | the initial length |
public StringBuf(String str)
Constructs a String buffer with the specified initial value.
| Parameter | Description |
| str | the initial value of the buffer |
public StringBuf(char[] chars,
int offset,
int length)
Methods
public static synchronized StringBuf Alloc()
Constructs an empty String buffer, reusing one from the
recycler.
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.
public static synchronized void EmptyRecycler()
Empty the recycler discarding any cached StringBuf objects
static void classFinalize() throws Throwable
public int length()
Returns the length (character count) of the buffer.
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.
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 |
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.
public void setEmpty()
Clear the content for reuse. Farster than setLength(0).
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.
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.
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.
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.
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.
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.
public StringBuf assign(char[] str)
public StringBuf assign(String str)
public StringBuf assign(char[] str,
int offset,
int len)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
public StringBuf reverse()
Reverse the order of the characters in the String buffer.
public void toUpperCase()
public void toLowerCase()
public String toString()
Converts to a String representing the data in the buffer.
- Overrides:
- toString in class Object
public char[] toChars()
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...
public boolean isWhitespace()
Return true if the string buffer contains nothing but whitespace
as defined by Character.isWhitespace()
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.
public boolean equalsIgnoreCase(int aStart,
int aLength,
String anotherString)
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.
public boolean equals(Object aObject)
- Overrides:
- equals in class Object
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.
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.
public int indexOf(int ch)
public int indexOf(int ch,
int fromIndex)
public void remove(int fromIndex)
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 Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.4
|