public class TextBuilder extends Object implements Appendable, CharSequence, Serializable
An Appendable text whose capacity expands
gently without incurring expensive resize/copy operations ever.
This class is not intended for large documents manipulations which
should be performed with the Text class directly
(O(Log(n)) insertion and
deletion capabilities).
The textual format of any appended object is retrieved
from the current TextContext.
| Constructor and Description |
|---|
TextBuilder()
Creates a text builder of small initial capacity.
|
TextBuilder(int capacity)
Creates a text builder of specified initial capacity.
|
TextBuilder(String str)
Creates a text builder holding the specified
String
(convenience method). |
| Modifier and Type | Method and Description |
|---|---|
TextBuilder |
append(boolean b)
Appends the textual representation of the specified
boolean
argument. |
TextBuilder |
append(char c)
Appends the specified character.
|
TextBuilder |
append(char[] chars)
Appends the characters from the char array argument.
|
TextBuilder |
append(char[] chars,
int offset,
int length)
Appends the characters from a subarray of the char array argument.
|
TextBuilder |
append(CharSequence csq)
Appends the specified character sequence.
|
TextBuilder |
append(CharSequence csq,
int start,
int end)
Appends a subsequence of the specified character sequence.
|
TextBuilder |
append(double d)
Appends the textual representation of the specified
double;
the number of digits is 17 or 16 when the 16 digits representation
can be parsed back to the same double (mimic the standard
library formatting). |
TextBuilder |
append(double d,
int digits,
boolean scientific,
boolean showZero)
Appends the textual representation of the specified
double
according to the specified formatting arguments. |
TextBuilder |
append(float f)
Appends the textual representation of the specified
float. |
TextBuilder |
append(int i)
Appends the decimal representation of the specified
int
argument. |
TextBuilder |
append(int i,
int radix)
Appends the radix representation of the specified
int
argument. |
TextBuilder |
append(long l)
Appends the decimal representation of the specified
long
argument. |
TextBuilder |
append(long l,
int radix)
Appends the radix representation of the specified
long
argument. |
TextBuilder |
append(Object obj)
Appends the textual representation of the specified object.
|
TextBuilder |
append(String str)
Appends the specified string to this text builder.
|
TextBuilder |
append(String str,
int start,
int end)
Appends a subsequence of the specified string.
|
TextBuilder |
append(Text txt)
Appends the specified text to this text builder.
|
TextBuilder |
append(Text txt,
int start,
int end)
Appends a subsequence of the specified text.
|
char |
charAt(int index)
Returns the character at the specified index.
|
TextBuilder |
clear()
Removes all the characters of this text builder
(equivalent to
this.delete(start, this.length())). |
boolean |
contentEquals(CharSequence csq)
Indicates if this text builder has the same character content as the
specified character sequence.
|
TextBuilder |
delete(int start,
int end)
Removes the characters between the specified indices.
|
boolean |
equals(Object obj)
Compares this text builder against the specified object for equality.
|
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Copies the character from this text builder into the destination
character array.
|
int |
hashCode()
Returns the hash code for this text builder.
|
TextBuilder |
insert(int index,
CharSequence csq)
Inserts the specified character sequence at the specified location.
|
int |
length()
Returns the length (character count) of this text builder.
|
TextBuilder |
reverse()
Reverses this character sequence.
|
void |
setCharAt(int index,
char c)
Sets the character at the specified position.
|
void |
setLength(int newLength)
Convenience method equivalent to
setLength(newLength, ' '). |
void |
setLength(int newLength,
char fillChar)
Sets the length of this character builder.
|
CharSequence |
subSequence(int start,
int end)
Returns a
CharSequence corresponding
to the character sequence between the specified indexes. |
CharArray |
toCharArray()
Returns the
CharArray representation of this
TextBuilder. |
String |
toString()
Returns the
String representation of this
TextBuilder. |
Text |
toText()
Returns the
Text corresponding to this TextBuilder. |
public TextBuilder()
public TextBuilder(String str)
String
(convenience method).str - the initial string content of this text builder.public TextBuilder(int capacity)
capacity - the initial capacity.public final int length()
length in interface CharSequencepublic final char charAt(int index)
charAt in interface CharSequenceindex - the index of the character.IndexOutOfBoundsException - if
(index < 0) || (index >= this.length()).public final void getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
srcBegin - this text start index.srcEnd - this text end index (not included).dst - the destination array to copy the data into.dstBegin - the offset into the destination array.IndexOutOfBoundsException - if (srcBegin < 0) ||
(dstBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this.length())
|| ((dstBegin + srcEnd - srcBegin) > dst.length)public final void setCharAt(int index,
char c)
index - the index of the character to modify.c - the new character.IndexOutOfBoundsException - if (index < 0) ||
(index >= this.length())public final void setLength(int newLength)
setLength(newLength, ' ').newLength - the new length of this builder.IndexOutOfBoundsException - if (newLength < 0)public final void setLength(int newLength,
char fillChar)
newLength - the new length of this builder.fillChar - the character to be appended if required.IndexOutOfBoundsException - if (newLength < 0)public final CharSequence subSequence(int start, int end)
CharSequence corresponding
to the character sequence between the specified indexes.subSequence in interface CharSequencestart - the index of the first character inclusive.end - the index of the last character exclusive.IndexOutOfBoundsException - if (start < 0) || (end < 0) ||
(start > end) || (end > this.length())public final TextBuilder append(char c)
append in interface Appendablec - the character to append.thispublic final TextBuilder append(Object obj)
TextContext.getFormat(obj.getClass()).format(obj, this)public final TextBuilder append(CharSequence csq)
null this method is equivalent to
append("null").append in interface Appendablecsq - the character sequence to append or null.thispublic final TextBuilder append(CharSequence csq, int start, int end)
null this method
is equivalent to append("null").append in interface Appendablecsq - the character sequence to append or null.start - the index of the first character to append.end - the index after the last character to append.thisIndexOutOfBoundsException - if (start < 0) || (end < 0)
|| (start > end) || (end > csq.length())public final TextBuilder append(String str)
null this method
is equivalent to append("null").str - the string to append or null.thispublic final TextBuilder append(String str, int start, int end)
null this method
is equivalent to append("null").str - the string to append or null.start - the index of the first character to append.end - the index after the last character to append.thisIndexOutOfBoundsException - if (start < 0) || (end < 0)
|| (start > end) || (end > str.length())public final TextBuilder append(Text txt)
null this method
is equivalent to append("null").txt - the text to append or null.thispublic final TextBuilder append(Text txt, int start, int end)
null this method
is equivalent to append("null").txt - the text to append or null.start - the index of the first character to append.end - the index after the last character to append.thisIndexOutOfBoundsException - if (start < 0) || (end < 0)
|| (start > end) || (end > txt.length())public final TextBuilder append(char[] chars)
chars - the character array source.thispublic final TextBuilder append(char[] chars, int offset, int length)
chars - the character array source.offset - the index of the first character to append.length - the number of character to append.thisIndexOutOfBoundsException - if (offset < 0) ||
(length < 0) || ((offset + length) > chars.length)public final TextBuilder append(boolean b)
boolean
argument.b - the boolean to format.thisTypeFormatpublic final TextBuilder append(int i)
int
argument.i - the int to format.thispublic final TextBuilder append(int i, int radix)
int
argument.i - the int to format.radix - the radix (e.g. 16 for hexadecimal).thispublic final TextBuilder append(long l)
long
argument.l - the long to format.thispublic final TextBuilder append(long l, int radix)
long
argument.l - the long to format.radix - the radix (e.g. 16 for hexadecimal).thispublic final TextBuilder append(float f)
float.f - the float to format.append(f, 10, (abs(f) >= 1E7) || (abs(f) < 0.001), false)public final TextBuilder append(double d)
double;
the number of digits is 17 or 16 when the 16 digits representation
can be parsed back to the same double (mimic the standard
library formatting).d - the double to format.append(d, -1, (MathLib.abs(d) >= 1E7) ||
(MathLib.abs(d) < 0.001), false)public final TextBuilder append(double d, int digits, boolean scientific, boolean showZero)
double
according to the specified formatting arguments.d - the double value.digits - the number of significative digits (excludes exponent) or
-1 to mimic the standard library (16 or 17 digits).scientific - true to forces the use of the scientific
notation (e.g. 1.23E3); false
otherwise.showZero - true if trailing fractional zeros are
represented; false otherwise.TypeFormat.format(d, digits, scientific, showZero, this)IllegalArgumentException - if (digits > 19))public final TextBuilder insert(int index, CharSequence csq)
index - the insertion position.csq - the character sequence being inserted.thisIndexOutOfBoundsException - if (index < 0) ||
(index > this.length())public final TextBuilder clear()
this.delete(start, this.length())).this.delete(0, this.length())public final TextBuilder delete(int start, int end)
start - the beginning index, inclusive.end - the ending index, exclusive.thisIndexOutOfBoundsException - if (start < 0) || (end < 0)
|| (start > end) || (end > this.length())public final TextBuilder reverse()
thispublic final Text toText()
Text corresponding to this TextBuilder.Text instance.public final String toString()
String representation of this
TextBuilder.toString in interface CharSequencetoString in class Objectjava.lang.String for this text builder.public final CharArray toCharArray()
CharArray representation of this
TextBuilder.CharArray instance.public final int hashCode()
public final boolean equals(Object obj)
true if the specified object is a text builder
having the same character content.public final boolean contentEquals(CharSequence csq)
csq - the character sequence to compare with.true if the specified character sequence has the
same character content as this text; false otherwise.Copyright © 2005-2013 Javolution. All Rights Reserved.