public class XStringBuilder extends XStringBufBase
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
METACHAR_SEQUENCE_START
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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
public XStringBuilder()
public XStringBuilder(int length)
length
- The initial capacitypublic XStringBuilder(java.lang.String initialContents)
initialContents
- The initial contentspublic int capacity()
XStringBufBase.length()
public XStringBuilder deleteCharAt(int index) throws java.lang.StringIndexOutOfBoundsException
index
- Index of the character to removejava.lang.StringIndexOutOfBoundsException
- if index is negative,
or greater than or equal to
length().public void ensureCapacity(int minimumCapacity)
minimumCapacity
- The minimum desirec capacitypublic void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) throws java.lang.IndexOutOfBoundsException
getChars
in class XStringBufBase
srcBegin
- 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 dstjava.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 storejava.lang.StringIndexOutOfBoundsException
- index out of rangepublic void setLength(int newLength) throws java.lang.IndexOutOfBoundsException
newLength
- the new length of the bufferjava.lang.IndexOutOfBoundsException
- newLength is negativepublic void trimToSize()
capacity()
method.protected java.lang.Appendable getBufferAsAppendable()
getBufferAsAppendable
in class XStringBufBase
protected java.lang.CharSequence newBufferAsCharSequence()
newBufferAsCharSequence
in class XStringBufBase
protected java.lang.CharSequence getBufferAsCharSequence()
getBufferAsCharSequence
in class XStringBufBase
protected void deleteCharacters(int start, int end) throws java.lang.IndexOutOfBoundsException
deleteCharacters
in class XStringBufBase
start
- The beginning index, inclusiveend
- The ending index, exclusivejava.lang.IndexOutOfBoundsException
- if start is negative,
greater than length(),
or greater than endprotected void insertCharacter(int index, char ch)
insertCharacter
in class XStringBufBase
index
- Where to start inserting in the string bufferch
- The character to insertprotected void insertCharacters(int index, char[] chars, int offset, int len)
insertCharacters
in class XStringBufBase
index
- 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 insertprotected void replaceString(int start, int end, java.lang.String str) throws java.lang.IndexOutOfBoundsException
replaceString
in class XStringBufBase
start
- The beginning index, inclusiveend
- The ending index, exclusivestr
- The string that will replace the previous contentsjava.lang.IndexOutOfBoundsException
- if start is negative,
or greater than
length(), or greater
than end