Class TextBuilder
- java.lang.Object
-
- pl.tkowalcz.tjahzi.javolution.text.TextBuilder
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Appendable,java.lang.CharSequence
public class TextBuilder extends java.lang.Object implements java.lang.Appendable, java.lang.CharSequence, java.io.SerializableAn
Appendabletext whose capacity expands gently without incurring expensive resize/copy operations ever.This class is not intended for large documents manipulations.
- Version:
- 5.3, January 20, 2008
- Author:
- Jean-Marie Dautelle
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor 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 specifiedString(convenience method).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TextBuilderappend(boolean b)Appends the textual representation of the specifiedbooleanargument.TextBuilderappend(char c)Appends the specified character.TextBuilderappend(char[] chars)Appends the characters from the char array argument.TextBuilderappend(char[] chars, int offset, int length)Appends the characters from a subarray of the char array argument.TextBuilderappend(int i)Appends the decimal representation of the specifiedintargument.TextBuilderappend(int i, int radix)Appends the radix representation of the specifiedintargument.TextBuilderappend(long l)Appends the decimal representation of the specifiedlongargument.TextBuilderappend(long l, int radix)Appends the radix representation of the specifiedlongargument.TextBuilderappend(java.lang.CharSequence csq)Appends the specified character sequence.TextBuilderappend(java.lang.CharSequence csq, int start, int end)Appends a subsequence of the specified character sequence.TextBuilderappend(java.lang.String str)Appends the specified string to this text builder.TextBuilderappend(java.lang.String str, int start, int end)Appends a subsequence of the specified string.charcharAt(int index)Returns the character at the specified index.TextBuilderclear()Removes all the characters of this text builder (equivalent tothis.delete(start, this.length())).booleancontentEquals(java.lang.CharSequence csq)Indicates if this text builder has the same character content as the specified character sequence.TextBuilderdelete(int start, int end)Removes the characters between the specified indices.booleanequals(java.lang.Object obj)Compares this text builder against the specified object for equality.inthashCode()Returns the hash code for this text builder.TextBuilderinsert(int index, java.lang.CharSequence csq)Inserts the specified character sequence at the specified location.intlength()Returns the length (character count) of this text builder.TextBuilderreverse()Reverses this character sequence.voidsetCharAt(int index, char c)Sets the character at the specified position.voidsetLength(int newLength)Convenience method equivalent tosetLength(newLength, ' ').voidsetLength(int newLength, char fillChar)Sets the length of this character builder.java.lang.CharSequencesubSequence(int start, int end)Returns aCharSequencecorresponding to the character sequence between the specified indexes.
-
-
-
Constructor Detail
-
TextBuilder
public TextBuilder()
Creates a text builder of small initial capacity.
-
TextBuilder
public TextBuilder(java.lang.String str)
Creates a text builder holding the specifiedString(convenience method).- Parameters:
str- the initial string content of this text builder.
-
TextBuilder
public TextBuilder(int capacity)
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.
-
-
Method Detail
-
length
public final int length()
Returns the length (character count) of this text builder.- Specified by:
lengthin interfacejava.lang.CharSequence- Returns:
- the number of characters (16-bits Unicode).
-
charAt
public final char charAt(int index)
Returns the character at the specified index.- Specified by:
charAtin interfacejava.lang.CharSequence- Parameters:
index- the index of the character.- Returns:
- the character at the specified index.
- Throws:
java.lang.IndexOutOfBoundsException- if(index < 0) || (index >= this.length()).
-
setCharAt
public final void setCharAt(int index, char c)Sets the character at the specified position.- Parameters:
index- the index of the character to modify.c- the new character.- Throws:
java.lang.IndexOutOfBoundsException- if(index < 0) || (index >= this.length())
-
setLength
public final void setLength(int newLength)
Convenience method equivalent tosetLength(newLength, ' ').- Parameters:
newLength- the new length of this builder.- Throws:
java.lang.IndexOutOfBoundsException- if(newLength < 0)
-
setLength
public final void setLength(int newLength, char fillChar)Sets the length of this character builder. If the length is greater than the current length; the specified character is inserted.- Parameters:
newLength- the new length of this builder.fillChar- the character to be appended if required.- Throws:
java.lang.IndexOutOfBoundsException- if(newLength < 0)
-
subSequence
public final java.lang.CharSequence subSequence(int start, int end)Returns aCharSequencecorresponding to the character sequence between the specified indexes.- Specified by:
subSequencein interfacejava.lang.CharSequence- Parameters:
start- the index of the first character inclusive.end- the index of the last character exclusive.- Returns:
- a character sequence.
- Throws:
java.lang.IndexOutOfBoundsException- if(start < 0) || (end < 0) || (start > end) || (end > this.length())
-
append
public final TextBuilder append(char c)
Appends the specified character.- Specified by:
appendin interfacejava.lang.Appendable- Parameters:
c- the character to append.- Returns:
this
-
append
public final TextBuilder append(java.lang.CharSequence csq)
Appends the specified character sequence. If the specified character sequence isnullthis method is equivalent toappend("null").- Specified by:
appendin interfacejava.lang.Appendable- Parameters:
csq- the character sequence to append ornull.- Returns:
this
-
append
public final TextBuilder append(java.lang.CharSequence csq, int start, int end)
Appends a subsequence of the specified character sequence. If the specified character sequence isnullthis method is equivalent toappend("null").- Specified by:
appendin interfacejava.lang.Appendable- Parameters:
csq- the character sequence to append ornull.start- the index of the first character to append.end- the index after the last character to append.- Returns:
this- Throws:
java.lang.IndexOutOfBoundsException- if(start < 0) || (end < 0) || (start > end) || (end > csq.length())
-
append
public final TextBuilder append(java.lang.String str)
Appends the specified string to this text builder. If the specified string isnullthis method is equivalent toappend("null").- Parameters:
str- the string to append ornull.- Returns:
this
-
append
public final TextBuilder append(java.lang.String str, int start, int end)
Appends a subsequence of the specified string. If the specified character sequence isnullthis method is equivalent toappend("null").- Parameters:
str- the string to append ornull.start- the index of the first character to append.end- the index after the last character to append.- Returns:
this- Throws:
java.lang.IndexOutOfBoundsException- if(start < 0) || (end < 0) || (start > end) || (end > str.length())
-
append
public final TextBuilder append(char[] chars)
Appends the characters from the char array argument.- Parameters:
chars- the character array source.- Returns:
this
-
append
public final 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.offset- the index of the first character to append.length- the number of character to append.- Returns:
this- Throws:
java.lang.IndexOutOfBoundsException- if(offset < 0) || (length < 0) || ((offset + length) > chars.length)
-
append
public final TextBuilder append(boolean b)
Appends the textual representation of the specifiedbooleanargument.- Parameters:
b- thebooleanto format.- Returns:
this
-
append
public final TextBuilder append(int i)
Appends the decimal representation of the specifiedintargument.- Parameters:
i- theintto format.- Returns:
this
-
append
public final TextBuilder append(int i, int radix)
Appends the radix representation of the specifiedintargument.- Parameters:
i- theintto format.radix- the radix (e.g.16for hexadecimal).- Returns:
this
-
append
public final TextBuilder append(long l)
Appends the decimal representation of the specifiedlongargument.- Parameters:
l- thelongto format.- Returns:
this
-
append
public final TextBuilder append(long l, int radix)
Appends the radix representation of the specifiedlongargument.- Parameters:
l- thelongto format.radix- the radix (e.g.16for hexadecimal).- Returns:
this
-
insert
public final TextBuilder insert(int index, java.lang.CharSequence csq)
Inserts the specified character sequence at the specified location.- Parameters:
index- the insertion position.csq- the character sequence being inserted.- Returns:
this- Throws:
java.lang.IndexOutOfBoundsException- if(index < 0) || (index > this.length())
-
clear
public final TextBuilder clear()
Removes all the characters of this text builder (equivalent tothis.delete(start, this.length())).- Returns:
this.delete(0, this.length())
-
delete
public final TextBuilder delete(int start, int end)
Removes the characters between the specified indices.- Parameters:
start- the beginning index, inclusive.end- the ending index, exclusive.- Returns:
this- Throws:
java.lang.IndexOutOfBoundsException- if(start < 0) || (end < 0) || (start > end) || (end > this.length())
-
reverse
public final TextBuilder reverse()
Reverses this character sequence.- Returns:
this
-
hashCode
public final int hashCode()
Returns the hash code for this text builder.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code value.
-
equals
public final boolean equals(java.lang.Object obj)
Compares this text builder against the specified object for equality. Returnstrueif the specified object is a text builder having the same character content.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the object to compare with ornull.- Returns:
trueif that is a text builder with the same character content as this text;falseotherwise.
-
contentEquals
public final boolean contentEquals(java.lang.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.- Returns:
trueif the specified character sequence has the same character content as this text;falseotherwise.
-
-