| java.lang.Object javolution.text.TextBuilder
Constructor Summary | |
public | TextBuilder() Creates a text builder of small initial capacity. | public | TextBuilder(CharSequence csq) Creates a text builder holding the specified character sequence. | public | TextBuilder(String str) Creates a text builder holding the specified String . | public | TextBuilder(int capacity) Creates a text builder of specified initial capacity. |
Method Summary | |
final public Appendable | append(char c) Appends the specified character.
Parameters: c - the character to append. | final public TextBuilder | append(Object obj) Appends the textual representation of the specified object. | final public Appendable | append(CharSequence csq) Appends the specified character sequence. | final public Appendable | append(CharSequence csq, int start, int end) Appends a subsequence of the specified character sequence.
If the specified character sequence is null this method
is equivalent to append("null") . | final public TextBuilder | append(String str) Appends the specified string to this text builder. | final public TextBuilder | append(String str, int start, int end) Appends a subsequence of the specified string.
If the specified character sequence is null this method
is equivalent to append("null") . | final public TextBuilder | append(Text txt) Appends the specified text to this text builder. | final public TextBuilder | append(Text txt, int start, int end) Appends a subsequence of the specified text.
If the specified character sequence is null this method
is equivalent to append("null") . | final public TextBuilder | append(char chars) Appends the characters from the char array argument.
Parameters: chars - the character array source. | final public TextBuilder | append(char chars, int offset, int length) Appends the characters from a subarray of the char array argument.
Parameters: chars - the character array source. Parameters: offset - the index of the first character to append. Parameters: length - the number of character to append. | final public TextBuilder | append(boolean b) Appends the textual representation of the specified boolean
argument.
Parameters: b - the boolean to format. | final public TextBuilder | append(int i) Appends the decimal representation of the specified int
argument.
Parameters: i - the int to format. | final public TextBuilder | append(int i, int radix) Appends the radix representation of the specified int
argument.
Parameters: i - the int to format. Parameters: radix - the radix (e.g. | final public TextBuilder | append(long l) Appends the decimal representation of the specified long
argument.
Parameters: l - the long to format. | final public TextBuilder | append(long l, int radix) Appends the radix representation of the specified long
argument.
Parameters: l - the long to format. Parameters: radix - the radix (e.g. | final void | appendFraction(long l, int digits, boolean showZero) Appends the textual representation of the specified double
according to the specified formatting arguments.
Parameters: d - the double value. Parameters: digits - the number of significative digits (excludes exponent) or-1 to mimic the standard library (16 or 17 digits). Parameters: scientific - true to forces the use of the scientific notation (e.g. | final void | appendTo(StringBuffer sb) Appends the content of this text builder to the specified
string buffer (only for text builder with length less than 32). | final public char | charAt(int i) Returns the character at the specified index.
Parameters: i - the index of the character. | final char[] | charsAt(int i) | final public TextBuilder | clear() Removes all the characters of this text builder
(equivalent to this.delete(start, this.length()) ). | final public boolean | contentEquals(CharSequence csq) Indicates if this text builder has the same character content as the
specified character sequence.
Parameters: csq - the character sequence to compare with. | final public boolean | contentEquals(String csq) Equivalent to
TextBuilder.contentEquals(CharSequence)
(for J2ME compability).
Parameters: csq - the string character sequence to compare with. | final public TextBuilder | delete(int start, int end) Removes the characters between the specified indices.
Parameters: start - the beginning index, inclusive. Parameters: end - the ending index, exclusive. | final public boolean | equals(Object obj) Compares this text builder against the specified object for equality.
Returns true if the specified object is a text builder
having the same character content.
Parameters: obj - the object to compare with or null . | final public void | getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) Copies the character from this text builder into the destination
character array. | final public int | hashCode() Returns the hash code for this text builder. | final public TextBuilder | insert(int index, CharSequence csq) Inserts the specified character sequence at the specified location.
Parameters: index - the insertion position. Parameters: csq - the character sequence being inserted. | final public int | length() Returns the length (character count) of this text builder. | public static TextBuilder | newInstance() Returns a new, preallocated or
TextBuilder.recycle recycled text builder
(on the stack when executing in a
javolution.context.StackContextStackContext ). | public void | print() Prints out this text builder to System.out (UTF-8 encoding). | public void | print(Writer writer) Prints out this text builder to the specified writer. | public void | println() Prints out this text builder to System.out and then
terminates the line. | public void | println(Writer writer) Prints out this text builder to the specified writer and then terminates
the line. | public static void | recycle(TextBuilder instance) Recycles a text builder
TextBuilder.newInstance() instance immediately
(on the stack when executing in a
javolution.context.StackContextStackContext ). | final public void | reset() Resets this text builder for reuse (equivalent to
TextBuilder.clear ). | final public TextBuilder | reverse() Reverses this character sequence. | final public void | setCharAt(int index, char c) Sets the character at the specified position.
Parameters: index - the index of the character to modify. Parameters: c - the new character. | final public void | setLength(int newLength) Sets the length of this character builder.
If the length is greater than the current length; the
null character '\u0000' is inserted. | final public CharSequence | subSequence(int start, int end) Returns an instance of
Text (immutable) corresponding
to the character sequence between the specified indexes.
Parameters: start - the index of the first character inclusive. Parameters: end - the index of the last character exclusive. | final public String | toString() Returns the String representation of this
TextBuilder . | final public Text | toText() Returns the
Text corresponding to this
TextBuilder (allocated on the "stack" when executing in a
javolution.context.StackContext StackContext ). |
TextBuilder | public TextBuilder()(Code) | | Creates a text builder of small initial capacity.
|
TextBuilder | public TextBuilder(CharSequence csq)(Code) | | Creates a text builder holding the specified character sequence.
Parameters: csq - the initial character sequence of this text builder. |
TextBuilder | public TextBuilder(String str)(Code) | | Creates a text builder holding the specified String .
Parameters: str - the initial string content of this text builder. |
TextBuilder | public TextBuilder(int capacity)(Code) | | Creates a text builder of specified initial capacity.
Unless the text length exceeds the specified capacity, operations
on this text builder will not allocate memory.
Parameters: capacity - the initial capacity. |
append | final public Appendable append(char c)(Code) | | Appends the specified character.
Parameters: c - the character to append. this |
append | final public TextBuilder append(Object obj)(Code) | | Appends the textual representation of the specified object.
If the specified object is null this method
is equivalent to append("null") .
Parameters: obj - the object to represent or null . this |
append | final public Appendable append(CharSequence csq)(Code) | | Appends the specified character sequence. If the specified character
sequence is null this method is equivalent to
append("null") .
Parameters: csq - the character sequence to append or null . this |
append | final public Appendable append(CharSequence csq, int start, int end)(Code) | | Appends a subsequence of the specified character sequence.
If the specified character sequence is null this method
is equivalent to append("null") .
Parameters: csq - the character sequence to append or null . Parameters: start - the index of the first character to append. Parameters: end - the index after the last character to append. this throws: IndexOutOfBoundsException - if (start < 0) || (end < 0) || (start > end) || (end > csq.length()) |
append | final public TextBuilder append(String str)(Code) | | Appends the specified string to this text builder.
If the specified string is null this method
is equivalent to append("null") .
Parameters: str - the string to append or null . this |
append | final public TextBuilder append(String str, int start, int end)(Code) | | Appends a subsequence of the specified string.
If the specified character sequence is null this method
is equivalent to append("null") .
Parameters: str - the string to append or null . Parameters: start - the index of the first character to append. Parameters: end - the index after the last character to append. this throws: IndexOutOfBoundsException - if (start < 0) || (end < 0) || (start > end) || (end > str.length()) |
append | final public TextBuilder append(Text txt)(Code) | | Appends the specified text to this text builder.
If the specified text is null this method
is equivalent to append("null") .
Parameters: txt - the text to append or null . this |
append | final public TextBuilder append(Text txt, int start, int end)(Code) | | Appends a subsequence of the specified text.
If the specified character sequence is null this method
is equivalent to append("null") .
Parameters: txt - the text to append or null . Parameters: start - the index of the first character to append. Parameters: end - the index after the last character to append. this throws: IndexOutOfBoundsException - if (start < 0) || (end < 0) || (start > end) || (end > txt.length()) |
append | final public TextBuilder append(char chars)(Code) | | Appends the characters from the char array argument.
Parameters: chars - the character array source. this |
append | final public TextBuilder append(char chars, int offset, int length)(Code) | | Appends the characters from a subarray of the char array argument.
Parameters: chars - the character array source. Parameters: offset - the index of the first character to append. Parameters: length - the number of character to append. this throws: IndexOutOfBoundsException - if (offset < 0) || (length < 0) || ((offset + length) > chars.length) |
append | final public TextBuilder append(boolean b)(Code) | | Appends the textual representation of the specified boolean
argument.
Parameters: b - the boolean to format. this See Also: TypeFormat |
append | final public TextBuilder append(int i)(Code) | | Appends the decimal representation of the specified int
argument.
Parameters: i - the int to format. this |
append | final public TextBuilder append(int i, int radix)(Code) | | Appends the radix representation of the specified int
argument.
Parameters: i - the int to format. Parameters: radix - the radix (e.g. 16 for hexadecimal). this |
append | final public TextBuilder append(long l)(Code) | | Appends the decimal representation of the specified long
argument.
Parameters: l - the long to format. this |
append | final public TextBuilder append(long l, int radix)(Code) | | Appends the radix representation of the specified long
argument.
Parameters: l - the long to format. Parameters: radix - the radix (e.g. 16 for hexadecimal). this |
appendFraction | final void appendFraction(long l, int digits, boolean showZero)(Code) | | Appends the textual representation of the specified double
according to the specified formatting arguments.
Parameters: d - the double value. Parameters: digits - the number of significative digits (excludes exponent) or-1 to mimic the standard library (16 or 17 digits). Parameters: scientific - true to forces the use of the scientific notation (e.g. 1.23E3 ); false otherwise. Parameters: showZero - true if trailing fractional zeros are represented; false otherwise. this throws: IllegalArgumentException - if (digits > 19) )public final TextBuilder append(double d, int digits,boolean scientific, boolean showZero) {if (digits > 19)throw new IllegalArgumentException("digits: " + digits);if (d != d) // NaNreturn append("NaN");if (d < 0) { // Work with positive number.d = -d;append('-');}if (d == Double.POSITIVE_INFINITY) // Infinity.return append("Infinity");if (d == 0.0) { // Zero.if (digits == 1)return append("0.");if (!showZero)return append("0.0");append("0.0");for (int i = 2; i < digits; i++) {append('0');}return this;}// Find the exponent e such as: value == x.xxx * 10^eint e = MathLib.floorLog10(d);long m;if (digits < 0) { // Use 16 or 17 digits.// Try 17 digits.long m17 = MathLib.toLongPow10(d, (17 - 1) - e);// Check if we can use 16 digits.long m16 = m17 / 10;double dd = MathLib.toDoublePow10(m16, e - 16 + 1);if (dd == d) { // 16 digits is enough.digits = 16;m = m16;} else { // We cannot remove the last digit.digits = 17;m = m17;}} else { // Use the specified number of digits.m = MathLib.toLongPow10(d, (digits - 1) - e);}// Formats.if (scientific || (e >= digits)) {// Scientific notation has to be used ("x.xxxEyy").long pow10 = POW10_LONG[digits - 1];int i = (int) (m / pow10); // Single digit.append(DIGIT_TO_CHAR[i]);m = m - pow10 * i;appendFraction(m, digits - 1, showZero);append('E');append(e);} else { // Dot within the string ("xxxx.xxxxx").if (e < 0) {append('0');} else {long pow10 = POW10_LONG[digits - e - 1];long l = m / pow10;append(l);m = m - pow10 * l;}appendFraction(m, digits - e - 1, showZero);}return this;}private static final long[] POW10_LONG = new long[] { 1L, 10L, 100L, 1000L,10000L, 100000L, 1000000L, 10000000L, 100000000L, 1000000000L,10000000000L, 100000000000L, 1000000000000L, 10000000000000L,100000000000000L, 1000000000000000L, 10000000000000000L,100000000000000000L, 1000000000000000000L };/* |
appendTo | final void appendTo(StringBuffer sb)(Code) | | Appends the content of this text builder to the specified
string buffer (only for text builder with length less than 32).
Parameters: sb - the string buffer. |
charAt | final public char charAt(int i)(Code) | | Returns the character at the specified index.
Parameters: i - the index of the character. the character at the specified index. throws: IndexOutOfBoundsException - if (i < 0) || (i >= this.length()) . |
charsAt | final char[] charsAt(int i)(Code) | | |
clear | final public TextBuilder clear()(Code) | | Removes all the characters of this text builder
(equivalent to this.delete(start, this.length()) ).
this.delete(0, this.length()) |
contentEquals | final public boolean contentEquals(CharSequence csq)(Code) | | Indicates if this text builder has the same character content as the
specified character sequence.
Parameters: csq - the character sequence to compare with. true if the specified character sequence has the same character content as this text; false otherwise. |
contentEquals | final public boolean contentEquals(String csq)(Code) | | Equivalent to
TextBuilder.contentEquals(CharSequence)
(for J2ME compability).
Parameters: csq - the string character sequence to compare with. true if the specified string has the same character content as this text; false otherwise. |
delete | final public TextBuilder delete(int start, int end)(Code) | | Removes the characters between the specified indices.
Parameters: start - the beginning index, inclusive. Parameters: end - the ending index, exclusive. this throws: IndexOutOfBoundsException - if (start < 0) || (end < 0) || (start > end) || (end > this.length()) |
equals | final public boolean equals(Object obj)(Code) | | Compares this text builder against the specified object for equality.
Returns true if the specified object is a text builder
having the same character content.
Parameters: obj - the object to compare with or null . true if that is a text builder with the same character content as this text; false otherwise. |
getChars | final public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)(Code) | | Copies the character from this text builder into the destination
character array.
Parameters: srcBegin - this text start index. Parameters: srcEnd - this text end index (not included). Parameters: dst - the destination array to copy the data into. Parameters: dstBegin - the offset into the destination array. throws: IndexOutOfBoundsException - if (srcBegin < 0) ||(dstBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this.length())|| ((dstBegin + srcEnd - srcBegin) > dst.length) |
hashCode | final public int hashCode()(Code) | | Returns the hash code for this text builder.
the hash code value. |
insert | final public TextBuilder insert(int index, CharSequence csq)(Code) | | Inserts the specified character sequence at the specified location.
Parameters: index - the insertion position. Parameters: csq - the character sequence being inserted. this throws: IndexOutOfBoundsException - if (index < 0) || (index > this.length()) |
length | final public int length()(Code) | | Returns the length (character count) of this text builder.
the number of characters (16-bits Unicode). |
print | public void print()(Code) | | Prints out this text builder to System.out (UTF-8 encoding).
This method is equivalent to:[code]
synchronized(OUT) {
print(OUT);
OUT.flush();
}
...
static final OUT = new UTF8StreamWriter().setOutput(System.out);
[/code]
|
print | public void print(Writer writer) throws IOException(Code) | | Prints out this text builder to the specified writer.
Parameters: writer - the destination writer. |
println | public void println()(Code) | | Prints out this text builder to System.out and then
terminates the line. This method is equivalent to:[code]
synchronized(OUT) {
println(OUT);
OUT.flush();
}
...
static final OUT = new UTF8StreamWriter().setOutput(System.out);
[/code]
|
println | public void println(Writer writer) throws IOException(Code) | | Prints out this text builder to the specified writer and then terminates
the line.
Parameters: writer - the destination writer. |
reverse | final public TextBuilder reverse()(Code) | | Reverses this character sequence.
this |
setCharAt | final public void setCharAt(int index, char c)(Code) | | Sets the character at the specified position.
Parameters: index - the index of the character to modify. Parameters: c - the new character. throws: IndexOutOfBoundsException - if (index < 0) || (index >= this.length()) |
setLength | final public void setLength(int newLength)(Code) | | Sets the length of this character builder.
If the length is greater than the current length; the
null character '\u0000' is inserted.
Parameters: newLength - the new length of this builder. throws: IndexOutOfBoundsException - if (newLength < 0) |
subSequence | final public CharSequence subSequence(int start, int end)(Code) | | Returns an instance of
Text (immutable) corresponding
to the character sequence between the specified indexes.
Parameters: start - the index of the first character inclusive. Parameters: end - the index of the last character exclusive. an immutable character sequence. throws: IndexOutOfBoundsException - if (start < 0) || (end < 0) ||(start > end) || (end > this.length()) |
toString | final public String toString()(Code) | | Returns the String representation of this
TextBuilder .
the java.lang.String for this text builder. |
|
|