|
JADE v6.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.dautelle.realtime.RealtimeObject
com.dautelle.util.FastString
This class represents a Real-Time
String.
This class is very much like java.lang.String; but a lot
faster (e.g. string concatenation is as fast as with
java.lang.StringBuffer) and more flexible as it allows for
search, concatenation and comparison with any CharSequence
such as itself, java.lang.String or
java.lang.StringBuffer.
Instances of this class are immutable (but like any real-time object,
instances allocated in a pool context must be exported
if referenced after exiting the pool context).
In case of successive concatenations, it may be advantageous to start
with a FastString whose character buffer is capable of holding
the final concatenated string (ref. newInstance(int capacity)),
this to avoid unnecessary character buffer allocation. Then
FastString can advantageously be used in place of
java.lang.StringBuffer(capacity) (as fast, but immutable).
For example:
// Constructs an immutable fullName.
FastString fullName = FastString.newInstance(64).
concat(firstName).concat(" ").concat(lastName);
Finally, as for any CharSequence, parsing to primitive types
can be achieved using the TypeFormat utility
class.
| Nested Class Summary | |
static class |
FastString.Value
This inner class represents a mutable image of an immutable FastString. |
| Nested classes inherited from class com.dautelle.realtime.RealtimeObject |
RealtimeObject.Factory |
| Field Summary | |
static FastString |
EMPTY
Holds the empty string. |
| Constructor Summary | |
FastString(java.lang.CharSequence chars)
Creates a constant FastString always allocated on the heap,
corresponding to the specified character sequence. |
|
| Method Summary | |
char |
charAt(int index)
Returns the character at the specified index. |
int |
compareTo(java.lang.CharSequence chars)
Compares this FastString with the specified character sequence
lexicographically. |
int |
compareTo(java.lang.Object that)
Compares this FastString to another object. |
FastString |
concat(java.lang.CharSequence chars)
Concatenates the specified character sequence to the end of this FastString. |
boolean |
endsWith(java.lang.CharSequence suffix)
Indicates if this FastString ends with the specified suffix. |
boolean |
equals(java.lang.Object that)
Compares this FastString against the specified object. |
boolean |
equalsIgnoreCase(java.lang.CharSequence chars)
Compares this FastString to the specified character sequence
ignoring case considerations. |
java.lang.Object |
export()
Exports this object out of the current pool context. |
void |
getChars(int start,
int end,
char[] dest,
int destPos)
Copies the characters from this FastString into the destination
character array. |
int |
hashCode()
Returns the hash code for this real-time string. |
int |
indexOf(java.lang.CharSequence chars)
Returns the index within this FastString of the first occurrence
of the specified character sequence searching forward. |
int |
indexOf(java.lang.CharSequence chars,
int fromIndex)
Returns the index within this FastString of the first occurrence
of the specified character sequence searching forward from the specified
index. |
int |
lastIndexOf(java.lang.CharSequence chars)
Returns the index within this FastString of the last occurrence of
the specified character sequence searching backward. |
int |
lastIndexOf(java.lang.CharSequence chars,
int fromIndex)
Returns the index within this FastString of the last occurrence of
the specified character sequence searching backward from the specified
index. |
int |
length()
Returns the length of this FastString. |
static FastString |
newInstance(int capacity)
Returns an empty FastString having an internal data array of
specified capacity. |
FastString |
replace(char oldChar,
char newChar)
Returns a FastString where all occurrences of
oldChar have been replaced with newChar. |
boolean |
startsWith(java.lang.CharSequence prefix)
Indicates if this FastString starts with the specified prefix. |
boolean |
startsWith(java.lang.CharSequence prefix,
int index)
Indicates if this FastString starts with the specified prefix
at the specified index. |
java.lang.CharSequence |
subSequence(int start,
int end)
Returns a new character sequence that is a subsequence of this sequence. |
FastString |
substring(int start)
Returns a sub-string of this FastString. |
FastString |
substring(int start,
int end)
Returns a sub-string of this FastString. |
java.lang.Object |
toHeap()
Moves this object to the heap. |
java.lang.String |
toString()
Returns the text representation of this FastString. |
FastString |
trim()
Returns a copy of this FastString, with leading and trailing
whitespace omitted. |
static FastString |
valueOf(boolean b)
Returns the FastString representing the boolean
argument. |
static FastString |
valueOf(char c)
Returns the FastString representing the char
argument. |
static FastString |
valueOf(char[] data,
int first,
int length)
Returns the FastString that contains the characters from
the specified subarray of characters. |
static FastString |
valueOf(java.lang.CharSequence chars)
Returns the FastString representing the specified character
sequence. |
static FastString |
valueOf(double d)
Returns the FastString representing the specified
double argument. |
static FastString |
valueOf(int i)
Returns the FastString representing the specified int
argument (decimal representation). |
static FastString |
valueOf(long l)
Returns the FastString representing the specified long
argument (decimal representation). |
| Methods inherited from class com.dautelle.realtime.RealtimeObject |
clone, isLocalObject, isPoolObject, recycle |
| Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final FastString EMPTY
| Constructor Detail |
public FastString(java.lang.CharSequence chars)
FastString always allocated on the heap,
corresponding to the specified character sequence. This method is
typically used to define static FastString constants.
chars - the CharSequence source.| Method Detail |
public static FastString newInstance(int capacity)
FastString having an internal data array of
specified capacity.
Note: Despite of their immutability, strings may share the same data
array (e.g. substring(int)). In case of successive
concatenations, it may be advantageous to start with a
FastString capable of holding the final concatenated
string. Then all intermediate strings share the same
data array (they are substrings) and no additional data array
need to be allocated. Doing so, FastString behave very
much like StringBuffer (as fast) but still
maintain their immutability requirement.
capacity - the maximum number of characters during concatenation;
beyond which new allocations of internal data arrays may occur.
public static FastString valueOf(char[] data, int first, int length)
FastString that contains the characters from
the specified subarray of characters.
data - the source of the characters.first - the index of the first character.length - the length of the subarray.
public static FastString valueOf(java.lang.CharSequence chars)
FastString representing the specified character
sequence.
chars - the CharSequence source.
public static FastString valueOf(boolean b)
FastString representing the boolean
argument.
b - a boolean.
true, a string equal to
"true" is returned; otherwise, a string equal to
"false" is returned.TypeFormat.parseBoolean(java.lang.CharSequence)public static FastString valueOf(char c)
FastString representing the char
argument.
c - a char.
1 containing
as its single character the argument c.public static FastString valueOf(int i)
FastString representing the specified int
argument (decimal representation).
i - the int number.
int argument.TypeFormat.parseInt(java.lang.CharSequence)public static FastString valueOf(long l)
FastString representing the specified long
argument (decimal representation).
l - the long number.
long argument.TypeFormat.parseLong(java.lang.CharSequence)public static FastString valueOf(double d)
FastString representing the specified
double argument. The error is assumed to be
the intrinsic double error (64 bits IEEE 754 format).
d - the double number.
valueOf(d, 0)TypeFormat.parseDouble(java.lang.CharSequence)public int length()
FastString.
length in interface java.lang.CharSequencepublic char charAt(int index)
charAt in interface java.lang.CharSequenceindex - the index of the character starting at 0.
java.lang.IndexOutOfBoundsException - if the index is not
in the [0, length() - 1] range.public FastString substring(int start)
FastString.
Note: For performance reason, the sub-string being returned
references this FastString character array.
If this FastString is short-lived and the sub-string
is long-lived, it is recommended to perform a copy of
the sub-string to avoid that small sub-strings takes up a lot
of memory space which cannot be garbage collected.
start - the index of the first character inclusive.
java.lang.IndexOutOfBoundsException - if the start index
is not in the [0, length()] range.public FastString substring(int start, int end)
FastString.
Note: For performance reason, the sub-string being returned
references this FastString character array.
If this FastString is short-lived and the sub-string
is long-lived, it is recommended to perform a copy of
the sub-string to avoid that small sub-strings takes up a lot
of memory space which cannot be garbage collected.
start - the index of the first character inclusive.end - the index of the last character exclusive.
start
position and ending just before the specified end
position.
java.lang.IndexOutOfBoundsException - if the start index
is not in the [0, length()] range.
java.lang.IndexOutOfBoundsException - if the end index
is not in the [start, length()] range.
public java.lang.CharSequence subSequence(int start,
int end)
substring(int, int)
subSequence in interface java.lang.CharSequencestart - the index of the first character inclusive.end - the index of the last character exclusive.
start position and ending just before the specified
end position.
java.lang.IndexOutOfBoundsException - if the start index
is not in the [0, length()] range.
java.lang.IndexOutOfBoundsException - if the end index
is not in the [start, length()] range.
public void getChars(int start,
int end,
char[] dest,
int destPos)
FastString into the destination
character array.
start - the index of the first character in the string to copy.end - the index after the last character in the string to copy.dest - the destination array.destPos - the start offset in the destination array.
java.lang.StringIndexOutOfBoundsException - if the start index
is not in the [0, length()] range.
java.lang.StringIndexOutOfBoundsException - if the end index
is not in the [start, length()] range.public int indexOf(java.lang.CharSequence chars)
FastString of the first occurrence
of the specified character sequence searching forward.
chars - a character sequence.
-1 if the character sequence is not found.
public int indexOf(java.lang.CharSequence chars,
int fromIndex)
FastString of the first occurrence
of the specified character sequence searching forward from the specified
index.
chars - a character sequence.fromIndex - the index to start the search from.
[fromIndex, length()-chars.length()]
or -1 if the character sequence is not
found.public int lastIndexOf(java.lang.CharSequence chars)
FastString of the last occurrence of
the specified character sequence searching backward.
chars - a character sequence.
-1 if the character sequence is not found.
public int lastIndexOf(java.lang.CharSequence chars,
int fromIndex)
FastString of the last occurrence of
the specified character sequence searching backward from the specified
index.
chars - a character sequence.fromIndex - the index to start the backward search from.
[0, fromIndex] or
-1 if the character sequence is not found.public boolean startsWith(java.lang.CharSequence prefix)
FastString starts with the specified prefix.
prefix - the prefix.
true if the character sequence represented by the
argument is a prefix of the character sequence represented by
this string; false otherwise.public boolean endsWith(java.lang.CharSequence suffix)
FastString ends with the specified suffix.
suffix - the suffix.
true if the character sequence represented by the
argument is a suffix of the character sequence represented by
this string; false otherwise.
public boolean startsWith(java.lang.CharSequence prefix,
int index)
FastString starts with the specified prefix
at the specified index.
prefix - the prefix.index - the index of the prefix location in this string.
this.substring(index).startsWith(prefix)public FastString concat(java.lang.CharSequence chars)
FastString.
chars - the character sequence that is concatenated.
public FastString replace(char oldChar, char newChar)
FastString where all occurrences of
oldChar have been replaced with newChar.
oldChar - the old character.newChar - the new character.
FastString if it does not contain any occurence of
the specifed oldChar or a string derived from this
string by replacing every occurrence of oldChar
with newChar.public FastString trim()
FastString, with leading and trailing
whitespace omitted.
public java.lang.String toString()
FastString.
The String returned is always allocated on the heap
and can safely be referenced elsewhere.
toString in interface java.lang.CharSequencejava.lang.String for this FastString.public boolean equals(java.lang.Object that)
FastString against the specified object.
Note: Unfortunately, due to the current (JDK 1.4.1) implementation
of java.lang.String and
java.lang.StringBuffer, this method is not symmetric.
that - the object to compare with.
true if both objects are CharSequence
and they represent the same sequence;
false otherwise.public boolean equalsIgnoreCase(java.lang.CharSequence chars)
FastString to the specified character sequence
ignoring case considerations. The two character sequence are considered
equal ignoring case if they are of the same length, and corresponding
characters in the two strings are equal ignoring case.
chars - the CharSequence to compare this
FastString against.
true if the argument is not null
and the character sequences are equal, ignoring case;
false otherwise.equals(Object)public int hashCode()
Note: Returns the same hashCode as java.lang.String
(consistent with equals(java.lang.Object))
public int compareTo(java.lang.Object that)
FastString to another object.
If the object is a CharSequence this function behaves like
compareTo(CharSequence). Otherwise, it throws a
ClassCastException.
compareTo in interface java.lang.Comparablethat - the object to be compared.
compareTo((CharSequence) that)
java.lang.ClassCastException - if the specifed object is not a
CharSequence.public int compareTo(java.lang.CharSequence chars)
FastString with the specified character sequence
lexicographically.
chars - the character sequence to be compared with.
0 if the argument character sequence is
equal to this string; a value less than 0 if this
string is lexicographically less than the character sequence
argument; and a value greater than 0 if this string
is lexicographically greater than the character sequence
argument.
java.lang.ClassCastException - if the specifed object is not a
CharSequence.public java.lang.Object export()
RealtimeRealtime members are exported as well (recursion).
This method affects only objects belonging to the current pool context.
To avoid pool depletion, a "free" object from the outer pool
is moved to replace the object being exported.
export in interface Realtimeexport in class RealtimeObjectpublic java.lang.Object toHeap()
RealtimeRealtime members are moved to the heap as well (recursion).
This method affects only objects belonging to a pool context
(current or not).
toHeap in interface RealtimetoHeap in class RealtimeObject
|
JADE v6.1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||