|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavolution.realtime.RealtimeObject
javolution.lang.Text
public abstract class Text
This class represents an immutable character sequence with extremely
fast concatenation, insertion and
deletion capabilities (O[Log(n)]) instead of
O[n] for StringBuffer/StringBuilder).
Instances of this class have the following advantages over
String:
StringBuffer in order to
manipulate textual documents. Text methods are much
faster (especially for large documents).String.substring(int)
memory leak bug (when small substrings prevent memory from
larger string from being garbage collected).java.lang.String or CharSequence.formatting using the TextBuilder
class (no need to specify the buffer capacity as
it gently increases without incurring expensive resize/copy
operations).PoolContext). As for any CharSequence, parsing of primitive types can
be achieved using the TypeFormat utility class.
Text literals should be explicitely interned.
Unlike strings literals and strings-value constant expressions,
interning is not implicit. For example:
Interned texts are always allocated in ImmortalMemory (RTSJ VMs).
final static Text TRUE = Text.intern("true");
final static Text FALSE = Text.intern("false");
Implementation Note: To avoid expensive copy operations ,
Text instances are broken down into smaller immutable
sequences (they form a minimal-depth binary tree).
Internal copies are then performed in O[Log(n)]
instead of O[n]).
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javolution.realtime.RealtimeObject |
|---|
RealtimeObject.Factory<T extends RealtimeObject> |
| Nested classes/interfaces inherited from interface javolution.realtime.Realtime |
|---|
Realtime.ObjectSpace |
| Field Summary | |
|---|---|
static Text |
EMPTY
Holds an empty character sequence. |
static Text |
NULL
Holds the "null" character sequence. |
| Method Summary | |
|---|---|
abstract char |
charAt(int index)
Returns the character at the specified index. |
int |
compareTo(java.lang.Object csq)
Compares this text to another character sequence or string lexicographically. |
Text |
concat(Text that)
Concatenates the specified text to the end of this text. |
boolean |
contentEquals(java.lang.CharSequence csq)
Indicates if this text has the same character content as the specified character sequence. |
boolean |
contentEqualsIgnoreCase(java.lang.CharSequence csq)
Indicates if this text has the same character contend as the specified character sequence ignoring case considerations. |
Text |
copy()
Returns a compact copy of this text allocated on the stack when executing in a PoolContext. |
Text |
delete(int start,
int end)
Returns the text without the characters between the specified indexes. |
abstract int |
depth()
Returns the depth of the internal tree used to represent this text. |
boolean |
endsWith(java.lang.CharSequence suffix)
Indicates if this text ends with the specified suffix. |
boolean |
equals(java.lang.Object obj)
Compares this text against the specified object for equality. |
abstract void |
getChars(int start,
int end,
char[] dest,
int destPos)
Copies the characters from this text into the destination character array. |
int |
hashCode()
Returns the hash code for this text. |
abstract int |
indexOf(char c,
int fromIndex)
Returns the index within this text of the first occurrence of the specified character, starting the search at the specified index. |
int |
indexOf(java.lang.CharSequence csq)
Returns the index within this text of the first occurrence of the specified character sequence searching forward. |
int |
indexOf(java.lang.CharSequence csq,
int fromIndex)
Returns the index within this text of the first occurrence of the specified characters sequence searching forward from the specified index. |
int |
indexOfAny(CharSet charSet)
Returns the index within this text of the first occurrence of any character in the specified character set. |
int |
indexOfAny(CharSet charSet,
int start)
Returns the index within a region of this text of the first occurrence of any character in the specified character set. |
int |
indexOfAny(CharSet charSet,
int start,
int length)
Returns the index within a region of this text of the first occurrence of any character in the specified character set. |
Text |
insert(int index,
Text txt)
Returns the text having the specified text inserted at the specified location. |
static Text |
intern(java.lang.CharSequence csq)
Returns a text equals to the specified character sequence from a pool of unique text instances in ImmortalMemory. |
static Text |
intern(java.lang.String str)
Returns a text equals to the specified string from a pool of unique text instances in ImmortalMemory. |
boolean |
isBlank()
Indicates if all characters of this text are whitespaces (no characters greater than the space character). |
boolean |
isBlank(int start,
int length)
Indicates if the specified sub-range of characters of this text are whitespaces (no characters greater than the space character). |
abstract int |
lastIndexOf(char c,
int fromIndex)
Returns the index within this text of the first occurrence of the specified character, searching backward and starting at the specified index. |
int |
lastIndexOf(java.lang.CharSequence csq)
Returns the index within this text of the last occurrence of the specified characters sequence searching backward. |
int |
lastIndexOf(java.lang.CharSequence csq,
int fromIndex)
Returns the index within this text of the last occurrence of the specified character sequence searching backward from the specified index. |
int |
lastIndexOfAny(CharSet charSet)
Returns the index within this text of the last occurrence of any character in the specified character set. |
int |
lastIndexOfAny(CharSet charSet,
int start)
Returns the index within a region of this text of the last occurrence of any character in the specified character set. |
int |
lastIndexOfAny(CharSet charSet,
int start,
int length)
Returns the index within a region of this text of the last occurrence of any character in the specified character set. |
int |
length()
Returns the length of this text. |
Text |
padLeft(int len)
Pads this text on the left with spaces to make the minimum total length as specified. |
Text |
padLeft(int len,
char c)
Pads this text on the left to make the minimum total length as specified. |
Text |
padRight(int len)
Pads this text on the right with spaces to make the minimum total length as specified. |
Text |
padRight(int len,
char c)
Pads this text on the right to make the minimum total length as specified. |
Text |
plus(java.lang.Object obj)
Returns the concatenation of this text and the textual representation of the specified object. |
Text |
replace(Text target,
Text replacement)
Replaces each character sequence of this text that matches the specified target sequence with the specified replacement sequence. |
boolean |
startsWith(java.lang.CharSequence prefix)
Indicates if this text starts with the specified prefix. |
boolean |
startsWith(java.lang.CharSequence prefix,
int index)
Indicates if this text starts with the specified prefix at the specified index. |
abstract java.lang.String |
stringValue()
Returns the String value corresponding to this text. |
java.lang.CharSequence |
subSequence(int start,
int end)
Returns subtext(start, end). |
Text |
subtext(int start)
Returns a portion of this text. |
abstract Text |
subtext(int start,
int end)
Returns a portion of this text. |
abstract Text |
toLowerCase()
Converts the characters of this text to lower case. |
Text |
toText()
Returns this (implements
Realtime interface). |
abstract Text |
toUpperCase()
Converts the characters of this text to upper case. |
Text |
trim()
Returns a copy of this text, with leading and trailing whitespace omitted. |
Text |
trimEnd()
Returns a copy of this text, with trailing whitespace omitted. |
Text |
trimStart()
Returns a copy of this text, with leading whitespace omitted. |
static Text |
valueOf(boolean b)
Returns the text representation of the boolean argument. |
static Text |
valueOf(char c)
Returns the unique text instance corresponding to the
specified character. |
static Text |
valueOf(char[] chars)
Returns the text that contains the characters from the specified array. |
static Text |
valueOf(char[] chars,
int offset,
int length)
Returns the text that contains the characters from the specified subarray of characters. |
static Text |
valueOf(char c,
int length)
Returns the text that contains a specific length sequence of the character specified. |
static Text |
valueOf(java.lang.CharSequence csq,
int start,
int end)
Returns the text that contains the specified subsequence of characters. |
static Text |
valueOf(double d)
Returns the textual representation of the specified double
argument. |
static Text |
valueOf(double value,
int digits,
boolean scientific,
boolean showZero)
Returns the textual representation of the specified double
value according to the specified formatting arguments. |
static Text |
valueOf(float f)
Returns the textual representation of the specified float
instance. |
static Text |
valueOf(int i)
Returns the decimal representation of the specified int
argument. |
static Text |
valueOf(int i,
int radix)
Returns the radix representation of the specified int
argument. |
static Text |
valueOf(long l)
Returns the decimal representation of the specified long
argument. |
static Text |
valueOf(long l,
int radix)
Returns the radix representation of the specified long
argument. |
static Text |
valueOf(java.lang.Object obj)
Returns the text representing the specified object. |
| Methods inherited from class javolution.realtime.RealtimeObject |
|---|
export, move, moveHeap, preserve, recycle, toString, unpreserve |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.lang.CharSequence |
|---|
toString |
| Field Detail |
|---|
public static final Text EMPTY
public static final Text NULL
"null" character sequence.
| Method Detail |
|---|
public static Text valueOf(java.lang.Object obj)
null this method
returns NULL.
obj - the object to represent as text.
Realtime.toText()
public static Text valueOf(java.lang.CharSequence csq,
int start,
int end)
csq - the character sequence source.start - the index of the first character.end - the index after the last character.
java.lang.IndexOutOfBoundsException - if (start < 0) || (end < 0)
|| (start > end) || (end > csq.length())public static Text valueOf(char[] chars)
chars - the array source of the characters.
public static Text valueOf(char[] chars,
int offset,
int length)
chars - the source of the characters.offset - the index of the first character in the data soure.length - the length of the text returned.
java.lang.IndexOutOfBoundsException - if (offset < 0) ||
(length < 0) || ((offset + length) > chars.length)public static Text valueOf(boolean b)
boolean argument.
b - a boolean.
true, the text
"true" is returned; otherwise, the text
"false" is returned.public static Text valueOf(char c)
unique text instance corresponding to the
specified character.
c - a character.
1 containing 'c'.public static Text valueOf(int i)
int
argument.
i - the int to format.
public static Text valueOf(int i,
int radix)
int
argument.
i - the int to format.radix - the radix (e.g. 16 for hexadecimal).
public static Text valueOf(long l)
long
argument.
l - the long to format.
public static Text valueOf(long l,
int radix)
long
argument.
l - the long to format.radix - the radix (e.g. 16 for hexadecimal).
public static Text valueOf(float f)
float
instance.
f - the float to format.
public static Text valueOf(double d)
double
argument.
d - the double to format.
public static Text valueOf(double value,
int digits,
boolean scientific,
boolean showZero)
double
value according to the specified formatting arguments.
value - the double value.digits - the number of significative digits (excludes exponent).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.
java.lang.IllegalArgumentException - if ((digits > 19) ||
(digits <= 0)))
/public final int length()
length in interface java.lang.CharSequencepublic final Text plus(java.lang.Object obj)
obj - the object whose textual representation is appended.
this.concat(Text.valueOf(obj))public final Text concat(Text that)
StringBuffer.append(String)) and still returns
a text instance with an internal binary tree of minimal depth!
that - the text that is concatenated.
this + thatpublic final Text subtext(int start)
start - the index of the first character inclusive.
java.lang.IndexOutOfBoundsException - if (start < 0) ||
(start > this.length())
public final Text insert(int index,
Text txt)
index - the insertion position.txt - the text being inserted.
subtext(0, index).concat(txt).concat(subtext(index))
java.lang.IndexOutOfBoundsException - if (index < 0) ||
(index > this.length())
public final Text delete(int start,
int end)
start - the beginning index, inclusive.end - the ending index, exclusive.
subtext(0, start).concat(subtext(end))
java.lang.IndexOutOfBoundsException - if (start < 0) || (end < 0) ||
(start > end) || (end > this.length()
public final Text replace(Text target,
Text replacement)
target - the text to be replaced.replacement - the replacement text.
public final java.lang.CharSequence subSequence(int start,
int end)
subtext(start, end).
subSequence in interface java.lang.CharSequencestart - the index of the first character inclusive.end - the index of the last character exclusive.
this.subtext(start, end)
java.lang.IndexOutOfBoundsException - if (start < 0) || (end < 0) ||
(start > end) || (end > this.length())public final int indexOf(java.lang.CharSequence csq)
csq - a character sequence.
-1 if the character sequence is not found.
public final int indexOf(java.lang.CharSequence csq,
int fromIndex)
csq - a character sequence.fromIndex - the index to start the search from.
[fromIndex, length() - csq.length()]
or -1 if the character sequence is not found.public final int lastIndexOf(java.lang.CharSequence csq)
csq - a character sequence.
-1 if the character sequence is not found.
public final int lastIndexOf(java.lang.CharSequence csq,
int fromIndex)
csq - a character sequence.fromIndex - the index to start the backward search from.
[0, fromIndex] or
-1 if the character sequence is not found.public final boolean startsWith(java.lang.CharSequence prefix)
prefix - the prefix.
true if the character sequence represented by the
argument is a prefix of the character sequence represented by
this text; false otherwise.public final boolean endsWith(java.lang.CharSequence suffix)
suffix - the suffix.
true if the character sequence represented by the
argument is a suffix of the character sequence represented by
this text; false otherwise.
public final boolean startsWith(java.lang.CharSequence prefix,
int index)
prefix - the prefix.index - the index of the prefix location in this string.
this.substring(index).startsWith(prefix)public final Text trim()
public static Text intern(java.lang.CharSequence csq)
ImmortalMemory.
ImmortalMemory.public static Text intern(java.lang.String str)
ImmortalMemory.
ImmortalMemory.public 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 contentEqualsIgnoreCase(java.lang.CharSequence csq)
csq - the CharSequence to compare this text against.
true if the argument and this text are equal,
ignoring case; false otherwise.public final boolean equals(java.lang.Object obj)
true if the specified object is a text having
the same character sequence as this text.
For generic comparaison with any character sequence the
contentEquals(CharSequence) should be used.
equals in class java.lang.Objectobj - the object to compare with or null.
true if that is a text with the same character
sequence as this text; false otherwise.public final int hashCode()
hashCode in class java.lang.Objectpublic final int compareTo(java.lang.Object csq)
compareTo in interface java.lang.Comparablecsq - the character sequence to be compared.
TypeFormat.LEXICAL_COMPARATOR.compare(this, csq)
java.lang.ClassCastException - if the specifed object is not a
CharSequence or a String.public final Text toText()
this (implements
Realtime interface).
toText in interface RealtimetoText in class RealtimeObjectthispublic final Text copy()
PoolContext.
public abstract int depth()
public abstract 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 abstract int indexOf(char c,
int fromIndex)
c - the character to search for.fromIndex - the index to start the search from.
fromIndex,
or -1 if the character does not occur.
public abstract int lastIndexOf(char c,
int fromIndex)
c - the character to search for.fromIndex - the index to start the search backward from.
fromIndex,
or -1 if the character does not occur.
public abstract Text subtext(int start,
int end)
start - 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 abstract void getChars(int start,
int end,
char[] dest,
int destPos)
start - the index of the first character to copy.end - the index after the last character to copy.dest - the destination array.destPos - the start offset in the destination array.
java.lang.IndexOutOfBoundsException - if (start < 0) || (end < 0) ||
(start > end) || (end > this.length())public abstract Text toLowerCase()
Character.toLowerCase(char)public abstract Text toUpperCase()
Character.toUpperCase(char)public abstract java.lang.String stringValue()
String value corresponding to this text.
java.lang.String for this text.
public static Text valueOf(char c,
int length)
c - the character to fill this text with.length - the length of the text returned.
java.lang.IndexOutOfBoundsException - if (length < 0)public final boolean isBlank()
true if this text contains only whitespace.
public final boolean isBlank(int start,
int length)
start - the start index.length - the number of characters to inspect.public final Text trimStart()
public final Text trimEnd()
public final Text padLeft(int len)
(length()-len) spaces.
len - the total number of characters to make this text equal to.
an - IllegalArgumentException if the (len<0).
public final Text padLeft(int len,
char c)
(length()-len) pad characters.
len - the total number of characters to make this text equal to.c - the character to pad using.
an - IllegalArgumentException if the (len<0).public final Text padRight(int len)
(length()-len) spaces.
len - the total number of characters to make this text equal to.
an - IllegalArgumentException if the (len<0).
public final Text padRight(int len,
char c)
(length()-len) pad characters.
len - the total number of characters to make this text equal to.c - the character to pad using.
an - IllegalArgumentException if the (len<0).public final int indexOfAny(CharSet charSet)
charSet - the character set.
-1 if none.
public final int indexOfAny(CharSet charSet,
int start)
charSet - the character set.start - the index of the start of the search region in this text.
-1 if none.
public final int indexOfAny(CharSet charSet,
int start,
int length)
charSet - the character set.start - the index of the start of the search region in this text.length - the length of the region to search.
-1 if none.public final int lastIndexOfAny(CharSet charSet)
charSet - the character set.
-1 if none.
public final int lastIndexOfAny(CharSet charSet,
int start)
charSet - the character set.start - the index of the start of the search region in this text.
-1 if none.
public final int lastIndexOfAny(CharSet charSet,
int start,
int length)
charSet - the character set.start - the index of the start of the search region in this text.length - the length of the region to search.
-1 if none.
|
J avolution v3.7 (J2SE 1.5+) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||