|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.clapper.util.text.XStringBufBase
org.clapper.util.text.XStringBuilder
public class XStringBuilder
An XStringBuilder objects wraps a standard Java StringBuilder object, providing a superset of StringBuilder's functionality. (XStringBuilder cannot actually subclass StringBuilder, since StringBuilder is final.) Among the additional methods that this class provides are:
XStringBufBase.split() methods, to split the contents of the
buffer on a delimiter
delete() method that deletes the first
occurrence of a substring. (StringBuilder only provides
a delete() method that takes a starting and ending index.)
replace() method that replaces
the first occurrence of a substring. (StringBuilder only
provides a replace() method that takes a starting and
ending index.)
replaceAll() method to
replace all occurrences of a substring with something else
XStringBufBase.encodeMetacharacters() and
XStringBufBase.decodeMetacharacters().)
Because XStringBuilder wraps a StringBuilder, it is
not thread-safe; but, it is likely to be faster than a
StringBuffer or an XStringBuffer. For applications or
methods that must to worry about multiple threads modifying the buffer
concurrently, consider using the XStringBuffer class, instead.
StringBuilder,
XStringBuffer| Field Summary |
|---|
| Fields inherited from class org.clapper.util.text.XStringBufBase |
|---|
METACHAR_SEQUENCE_START |
| Constructor Summary | |
|---|---|
XStringBuilder()
Construct an empty XStringBuilder object with a default initial capacity (the same initial capacity as an empty StringBuilder object). |
|
XStringBuilder(int length)
Construct an empty XStringBuilder object with the specified initial capacity. |
|
XStringBuilder(java.lang.String initialContents)
Construct a XStringBuilder object so that it represents the same sequence of characters as the String argument. |
|
| Method Summary | |
|---|---|
int |
capacity()
Return the current capacity of the buffer (i.e., the number of characters left before truncation will occur). |
protected void |
deleteCharacters(int start,
int end)
Remove the characters in a substring of this XStringBuilder. |
XStringBuilder |
deleteCharAt(int index)
Remove the character at the specified position in this object, shortening this object by one character. |
void |
ensureCapacity(int minimumCapacity)
Ensure that the capacity of the buffer is at least equal to the specified minimum. |
protected java.lang.Appendable |
getBufferAsAppendable()
Get the underlying buffer (e.g., StringBuilder, StringBuilder) as an Appender object. |
protected java.lang.CharSequence |
getBufferAsCharSequence()
Get the underlying buffer (e.g., StringBuilder, StringBuilder) as a CharSequence object. |
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Copy the some or all of the contents of the buffer into a character array. |
protected void |
insertCharacter(int index,
char ch)
Insert a single character into the buffer at a specified position. |
protected void |
insertCharacters(int index,
char[] chars,
int offset,
int len)
Insert characters from a character array into the buffer at a specified position. |
protected java.lang.CharSequence |
newBufferAsCharSequence()
Get a new instance of the underlying buffer type (e.g., StringBuilder, StringBuilder) as a CharSequence object. |
protected void |
replaceString(int start,
int end,
java.lang.String str)
Replace the characters in a substring of this buffer with characters in the specified String. |
void |
reverse()
Reverse the contents of the buffer. |
void |
setCharAt(int index,
char ch)
Set the character at a specified index. |
void |
setLength(int newLength)
Set the length of this XStringBuilder. |
void |
trimToSize()
Attempts to reduce storage used for the character sequence. |
| Methods inherited from class org.clapper.util.text.XStringBufBase |
|---|
append, append, append, append, append, append, append, append, append, append, append, append, append, charAt, clear, decodeMetacharacters, decodeMetacharacters, delete, delete, encodeMetacharacters, encodeMetacharacters, indexOf, indexOf, indexOf, insert, insert, insert, insert, insert, insert, insert, insert, insert, insert, insert, length, replace, replace, replace, replaceAll, replaceAll, replaceAll, reset, split, split, split, split, split, subSequence, substring, substring, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public XStringBuilder()
public XStringBuilder(int length)
length - The initial capacitypublic XStringBuilder(java.lang.String initialContents)
initialContents - The initial contents| Method Detail |
|---|
public int capacity()
XStringBufBase.length()
public XStringBuilder deleteCharAt(int index)
throws java.lang.StringIndexOutOfBoundsException
index - Index of the character to remove
java.lang.StringIndexOutOfBoundsException - if index is negative,
or greater than or equal to
length().public void ensureCapacity(int minimumCapacity)
minimumCapacity - The minimum desirec capacity
public void getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
throws java.lang.IndexOutOfBoundsException
getChars in class XStringBufBasesrcBegin - Start copy from this offset in the string buffersrcEnd - Stop copy from this offset in the string bufferdst - Where to copy the characters.dstBegin - Offset into dst
java.lang.IndexOutOfBoundsException - invalid indexpublic void reverse()
public void setCharAt(int index,
char ch)
throws java.lang.StringIndexOutOfBoundsException
index - The index at which to set the value.ch - The character to store
java.lang.StringIndexOutOfBoundsException - index out of range
public void setLength(int newLength)
throws java.lang.IndexOutOfBoundsException
newLength - the new length of the buffer
java.lang.IndexOutOfBoundsException - newLength is negativepublic void trimToSize()
capacity() method.
protected java.lang.Appendable getBufferAsAppendable()
getBufferAsAppendable in class XStringBufBaseprotected java.lang.CharSequence newBufferAsCharSequence()
newBufferAsCharSequence in class XStringBufBaseprotected java.lang.CharSequence getBufferAsCharSequence()
getBufferAsCharSequence in class XStringBufBase
protected void deleteCharacters(int start,
int end)
throws java.lang.IndexOutOfBoundsException
deleteCharacters in class XStringBufBasestart - The beginning index, inclusiveend - The ending index, exclusive
java.lang.IndexOutOfBoundsException - if start is negative,
greater than length(),
or greater than end
protected void insertCharacter(int index,
char ch)
insertCharacter in class XStringBufBaseindex - Where to start inserting in the string bufferch - The character to insert
protected void insertCharacters(int index,
char[] chars,
int offset,
int len)
insertCharacters in class XStringBufBaseindex - Where to start inserting in the string bufferchars - The character(s) to insertoffset - The starting position in the chars arraylen - The number of characters to insert
protected void replaceString(int start,
int end,
java.lang.String str)
throws java.lang.IndexOutOfBoundsException
replaceString in class XStringBufBasestart - The beginning index, inclusiveend - The ending index, exclusivestr - The string that will replace the previous contents
java.lang.IndexOutOfBoundsException - if start is negative,
or greater than
length(), or greater
than end
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||