javolution37.javolution.lang
Class TextBuilder
- java.lang.Object
-
- javolution37.javolution.realtime.RealtimeObject
-
- javolution37.javolution.lang.TextBuilder
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Appendable, java.lang.CharSequence, Reusable, Realtime
public class TextBuilder extends RealtimeObject implements java.lang.Appendable, java.lang.CharSequence, Reusable, java.io.Serializable
This class represents an
Appendabletext 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
Textclass directly (O(Log(n))insertionanddeletioncapabilities).This implementation is not synchronized.
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javolution37.javolution.realtime.RealtimeObject
RealtimeObject.Factory<T extends RealtimeObject>
-
Nested classes/interfaces inherited from interface javolution37.javolution.realtime.Realtime
Realtime.ObjectSpace
-
-
Constructor Summary
Constructors Constructor and Description TextBuilder()Creates a text builder of small initial capacity.TextBuilder(java.lang.CharSequence csq)Creates a text builder holding the specified character sequence.TextBuilder(int capacity)Creates a text builder of specified initial capacity.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description TextBuilderappend(boolean b)Appends the textual representation of the specifiedboolean(equivalent toTypeFormat.format(b, this)).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(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(double d)Appends the textual representation of the specifieddouble(equivalent toTypeFormat.format(d, this)).TextBuilderappend(double value, int digits, boolean scientific, boolean showZero)Appends the specifieddoublevalue according to the specified formatting arguments.TextBuilderappend(float f)Appends the textual representation of the specifiedfloat(equivalent toTypeFormat.format(f, this)).TextBuilderappend(int i)Appends the decimal representation of the specifiedint(equivalent toTypeFormat.format(i, this)).TextBuilderappend(int i, int radix)Appends the radix representation of the specifiedintargument.TextBuilderappend(long l)Appends the decimal representation of the specifiedlong(equivalent toTypeFormat.format(l, this)).TextBuilderappend(long l, int radix)Appends the radix representation of the specifiedlongargument.TextBuilderappend(java.lang.Object obj)Appends the textual representation of the specified object.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.TextBuilderappend(Text text)Appends the specified text to this text builder.charcharAt(int index)Returns the character at the specified index.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.voidgetChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)Copies the character from this text builder into the destination character array.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.static TextBuildernewInstance()Returns a text builder allocated from the "stack" when executing in aPoolContext).voidreset()Resets this text builder for reuse (sets its length to0).TextBuilderreverse()Reverses this character sequence.voidsetCharAt(int index, char c)Sets the character at the specified position.voidsetLength(int newLength)Sets the length of this character builder.java.lang.CharSequencesubSequence(int start, int end)Returns an instance ofText(immutable) corresponding to the character sequence between the specified indexes.TexttoText()Returns theTextcorresponding to thisTextBuilder(allocated on the "stack" when executing in aPoolContext).-
Methods inherited from class javolution37.javolution.realtime.RealtimeObject
export, move, moveHeap, preserve, toString, unpreserve
-
-
-
-
Constructor Detail
-
TextBuilder
public TextBuilder()
Creates a text builder of small initial capacity.
-
TextBuilder
public TextBuilder(java.lang.CharSequence csq)
Creates a text builder holding the specified character sequence.- Parameters:
csq- the initial character sequence 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
-
newInstance
public static TextBuilder newInstance()
Returns a text builder allocated from the "stack" when executing in aPoolContext).- Returns:
- a new, preallocated or recycled text builder instance.
-
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()).
-
getChars
public final void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)Copies the character from this text builder into the destination character array.- Parameters:
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.- Throws:
java.lang.IndexOutOfBoundsException- if(srcBegin < 0) || (dstBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this.length()) || ((dstBegin + srcEnd - srcBegin) > dst.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)
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:
java.lang.IndexOutOfBoundsException- if(newLength < 0)
-
subSequence
public final java.lang.CharSequence subSequence(int start, int end)Returns an instance ofText(immutable) corresponding 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:
- an immutable 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.Object obj)
Appends the textual representation of the specified object. If the specified object isnullthis method is equivalent toappend("null").- Parameters:
obj- the object to represent ornull.- Returns:
this
-
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 > csq.length())
-
append
public TextBuilder append(Text text)
Appends the specified text to this text builder. If the specified text isnullthis method is equivalent toappend("null").- Parameters:
text- the text to append ornull.- Returns:
this
-
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 specifiedboolean(equivalent toTypeFormat.format(b, this)).- Parameters:
b- thebooleanto format.- Returns:
this- See Also:
TypeFormat
-
append
public final TextBuilder append(int i)
Appends the decimal representation of the specifiedint(equivalent toTypeFormat.format(i, this)).- Parameters:
i- theintto format.- Returns:
this- See Also:
TypeFormat
-
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- See Also:
TypeFormat
-
append
public final TextBuilder append(long l)
Appends the decimal representation of the specifiedlong(equivalent toTypeFormat.format(l, this)).- Parameters:
l- thelongto format.- Returns:
this- See Also:
TypeFormat
-
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- See Also:
TypeFormat
-
append
public final TextBuilder append(float f)
Appends the textual representation of the specifiedfloat(equivalent toTypeFormat.format(f, this)).- Parameters:
f- thefloatto format.- Returns:
this- See Also:
/
-
append
public final TextBuilder append(double d)
Appends the textual representation of the specifieddouble(equivalent toTypeFormat.format(d, this)).- Parameters:
d- thedoubleto format.- Returns:
this- See Also:
/
-
append
public final TextBuilder append(double value, int digits, boolean scientific, boolean showZero)
Appends the specifieddoublevalue according to the specified formatting arguments.- Parameters:
value- thedoublevalue.digits- the number of significative digits (excludes exponent).scientific-trueto forces the use of the scientific notation (e.g.1.23E3);falseotherwise.showZero-trueif trailing fractional zeros are represented;falseotherwise.- Returns:
this- Throws:
java.lang.IllegalArgumentException- if((digits > 19) || (digits <= 0))) /
-
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())
-
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
-
toText
public final Text toText()
Returns theTextcorresponding to thisTextBuilder(allocated on the "stack" when executing in aPoolContext).- Specified by:
toTextin interfaceRealtime- Overrides:
toTextin classRealtimeObject- Returns:
- the corresponding
Textinstance.
-
reset
public final void reset()
Resets this text builder for reuse (sets its length to0).
-
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.
-
-
DMelt 3.0 © DataMelt by jWork.ORG