public class TextBuilder extends java.lang.Object implements java.lang.Appendable, java.lang.CharSequence, Reusable, Realtime, java.io.Serializable
This class represents 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).
This implementation is not synchronized.
| Constructor and Description |
|---|
TextBuilder()
Creates a text builder of small initial capacity.
|
TextBuilder(int capacity)
Creates a text builder of specified initial capacity.
|
TextBuilder(java.lang.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(java.lang.CharSequence csq)
Appends the specified character sequence.
|
TextBuilder |
append(java.lang.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(java.lang.Object obj)
Appends the textual representation of the specified object.
|
TextBuilder |
append(java.lang.String str)
Appends the specified string to this text builder.
|
TextBuilder |
append(java.lang.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(java.lang.CharSequence csq)
Indicates if this text builder has the same character content as the
specified character sequence.
|
boolean |
contentEquals(java.lang.String csq)
Equivalent to
contentEquals(CharSequence)
(for J2ME compability). |
TextBuilder |
delete(int start,
int end)
Removes the characters between the specified indices.
|
boolean |
equals(java.lang.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,
java.lang.CharSequence csq)
Inserts the specified character sequence at the specified location.
|
int |
length()
Returns the length (character count) of this text builder.
|
static TextBuilder |
newInstance()
Returns a new, preallocated or
recycled text builder
(on the stack when executing in a StackContext). |
void |
print()
Prints out this text builder to
System.out (UTF-8 encoding). |
void |
print(java.io.Writer writer)
Prints out this text builder to the specified writer.
|
void |
println()
Prints out this text builder to
System.out and then
terminates the line. |
void |
println(java.io.Writer writer)
Prints out this text builder to the specified writer and then terminates
the line.
|
static void |
recycle(TextBuilder instance)
Recycles a text builder
instance immediately
(on the stack when executing in a StackContext). |
void |
reset()
Resets this text builder for reuse (equivalent to
clear()). |
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.
|
java.lang.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. |
java.lang.String |
toString()
Returns the
String representation of this
TextBuilder. |
Text |
toText()
Returns the
Text corresponding to this TextBuilder
(allocated on the "stack" when executing in a
StackContext). |
public TextBuilder()
public TextBuilder(java.lang.String str)
String
(convenience method).str - the initial string content of this text builder.public TextBuilder(int capacity)
capacity - the initial capacity.public static TextBuilder newInstance()
recycled text builder
(on the stack when executing in a StackContext).public static void recycle(TextBuilder instance)
instance immediately
(on the stack when executing in a StackContext).public final int length()
length in interface java.lang.CharSequencepublic final char charAt(int index)
charAt in interface java.lang.CharSequenceindex - the index of the character.java.lang.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.java.lang.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.java.lang.IndexOutOfBoundsException - if (index < 0) ||
(index >= this.length())public final void setLength(int newLength)
setLength(newLength, ' ').newLength - the new length of this builder.java.lang.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.java.lang.IndexOutOfBoundsException - if (newLength < 0)public final java.lang.CharSequence subSequence(int start,
int end)
CharSequence corresponding
to the character sequence between the specified indexes.subSequence in interface java.lang.CharSequencestart - the index of the first character inclusive.end - the index of the last character exclusive.java.lang.IndexOutOfBoundsException - if (start < 0) || (end < 0) ||
(start > end) || (end > this.length())public final TextBuilder append(char c)
append in interface java.lang.Appendablec - the character to append.thispublic final TextBuilder append(java.lang.Object obj)
append(Text.valueOf(obj))obj - the object to represent or null.thisText.valueOf(Object)public final TextBuilder append(java.lang.CharSequence csq)
null this method is equivalent to
append("null").append in interface java.lang.Appendablecsq - the character sequence to append or null.thispublic final TextBuilder append(java.lang.CharSequence csq, int start, int end)
null this method
is equivalent to append("null").append in interface java.lang.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.thisjava.lang.IndexOutOfBoundsException - if (start < 0) || (end < 0)
|| (start > end) || (end > csq.length())public final TextBuilder append(java.lang.String str)
null this method
is equivalent to append("null").str - the string to append or null.thispublic final TextBuilder append(java.lang.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.thisjava.lang.IndexOutOfBoundsException - 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.thisjava.lang.IndexOutOfBoundsException - 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.thisjava.lang.IndexOutOfBoundsException - 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)java.lang.IllegalArgumentException - if (digits > 19))public final TextBuilder insert(int index, java.lang.CharSequence csq)
index - the insertion position.csq - the character sequence being inserted.thisjava.lang.IndexOutOfBoundsException - 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.thisjava.lang.IndexOutOfBoundsException - if (start < 0) || (end < 0)
|| (start > end) || (end > this.length())public final TextBuilder reverse()
thispublic final Text toText()
Text corresponding to this TextBuilder
(allocated on the "stack" when executing in a
StackContext).public final java.lang.String toString()
String representation of this
TextBuilder.toString in interface java.lang.CharSequencetoString in class java.lang.Objectjava.lang.String for this text builder.public final CharArray toCharArray()
CharArray representation of this
TextBuilder.CharArray instance.public final void reset()
clear()).public final int hashCode()
hashCode in class java.lang.Objectpublic final boolean equals(java.lang.Object obj)
true if the specified object is a text builder
having the same character content.equals in class java.lang.Objectobj - the object to compare with or null.true if that is a text builder with the same
character content as this text; false otherwise.public void print()
System.out (UTF-8 encoding).
This method is equivalent to:
synchronized(OUT) {
print(OUT);
OUT.flush();
}
...
static final OUT = new UTF8StreamWriter().setOutput(System.out);
public void println()
System.out and then
terminates the line. This method is equivalent to:
synchronized(OUT) {
println(OUT);
OUT.flush();
}
...
static final OUT = new UTF8StreamWriter().setOutput(System.out);
public void print(java.io.Writer writer)
throws java.io.IOException
writer - the destination writer.java.io.IOExceptionpublic void println(java.io.Writer writer)
throws java.io.IOException
writer - the destination writer.java.io.IOExceptionpublic final boolean contentEquals(java.lang.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.public final boolean contentEquals(java.lang.String csq)
contentEquals(CharSequence)
(for J2ME compability).csq - the string character sequence to compare with.true if the specified string has the
same character content as this text; false otherwise.Copyright © 2005 - 2007 Javolution.