|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.utexas.its.eis.tools.qwicap.util.Characters
public final class Characters
The Characters
class transparently represents either a String
, or a subsection of a
character array. Conversions from String
to character array, and vice versa, are avoided wherever
possible, and if a conversion must be performed to satisfy a caller, the conversion is performed only once, and the
result is cached. This means that modifications to a character array passed to the constructor, or returned by the
getArray()
method, have the potential to invalidate the cache. So do NOT modify those arrays.
Convenience methods such as write, println and append are provided so that those common operations can be
performed without the caller having to be aware of the presence/absence of char[]
or String
forms in any instance of this class, and in order to avoid conversions between those forms unless absolutely
necessary.
Constructor Summary | |
---|---|
Characters(char[] C)
Creates a Characters object that represents an entire char array. |
|
Characters(char[] C,
int COffset,
int CLength)
Creates a Characters object that represents a subsection of a char array. |
|
Characters(String S)
Creates a Characters object that represents a String . |
|
Characters(StringBuffer SB)
Creates a Characters object that represents the String supplied by the specified
StringBuffer object. |
|
Characters(StringBuilder SB)
Creates a Characters object that represents the String supplied by the specified
StringBuffer object. |
Method Summary | |
---|---|
Characters |
append(Characters Other)
Creates a new Characters object representing the concatenation of first this object, and then the
specified Characters object. |
void |
append(StringBuffer Buff)
Appends the characters represented by this object to the specified StringBuffer . |
void |
append(StringBuilder Buff)
Appends the characters represented by this object to the specified StringBuilder . |
char |
charAt(int Index)
Returns the char value at the specified index. |
boolean |
equals(char[] OtherChars,
int OtherOffset,
int OtherLength)
Compares the characters in this object to the specified subsection of a char array. |
boolean |
equals(Object OtherObj)
Compares this object to another object. |
char[] |
getArray()
Returns the charactes of this object represented as an array of characters. |
int |
getArrayOffset()
Returms the offset of the first character represented by this object in the char array returned by the getArray method. |
boolean |
hasArray()
Returns true if this object already contains a char array representation of its characters,
or false if such a representation has not yet been created. |
int |
hashCode()
Return the hash code for these characters. |
boolean |
hasString()
Returns true if this object already contains a String representation of its characters, or
false if such a representation has not yet been created. |
int |
indexOf(int Char)
Returns the index of the first occurrence of the specified character, or -1 if the character was not found. |
int |
indexOf(int Char,
int Offset)
Returns the index of the first occurrence of the specified character, or -1 if the character was not found. |
int |
length()
Returns the length of this character sequence. |
void |
print(PrintStream Out)
Prints the characters of this object to the specified PrintStream . |
void |
print(PrintWriter Out)
Prints the characters of this object to the specified PrintWriter . |
void |
println(PrintStream Out)
Uses the specified PrintStream object's println method to print the characters of this
object. |
void |
println(PrintWriter Out)
Uses the specified PrintWriter object's println method to print the characters of this
object. |
boolean |
startsWith(Characters Other)
Compares the initial characters of this object with all the characters of another Characters object. |
CharSequence |
subSequence(int FirstCharOffset,
int LastCharOffset)
Returns a Characters instance representing a subsequence of this object's characters. |
String |
substring(int FirstCharOffset)
Retrieves a substring of this object's characters, beginning with the character at the specified offset, and including all of the characters that follow it. |
String |
substring(int FirstCharOffset,
int LastCharOffset)
Retrieves a substring of this object's characters. |
String |
toString()
Returns the String representation of the characters represented by this Characters object. |
void |
write(Writer Out)
Writes the characters of this object to the specified Writer . |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Characters(String S)
Characters
object that represents a String
.
S
- The String
to be represented by this Characters
object.public Characters(StringBuffer SB)
Characters
object that represents the String
supplied by the specified
StringBuffer
object.
SB
- The StringBuffer
object containing the String to be represented by this
Characters
object.public Characters(StringBuilder SB)
Characters
object that represents the String
supplied by the specified
StringBuffer
object.
SB
- The StringBuilder
object containing the String to be represented by this
Characters
object.public Characters(char[] C)
Characters
object that represents an entire char array.
C
- The char array to be represented by this Characters
object.public Characters(char[] C, int COffset, int CLength)
Characters
object that represents a subsection of a char array.
C
- The char array to be represented by this Characters
object.COffset
- Index of the first character in the C array to be represented by this object.CLength
- Number of characters, beginning at COffset, to be represented by this object.Method Detail |
---|
public int length()
length
in interface CharSequence
public char[] getArray()
String
representation of the characters exists, a char array is created and cached for future use.
For efficiency, the array returned is not a clone or
copy of the character array used within this object, it is that actual array. Consequently, alterations to the
contents of the array are possible, but strongly discouraged. Among other things, alterations to
the array will leave the array out of synch with the String
representation of these same characters
that may also exist. If so, callers treating this Characters
object as a source for an array of chars
will get different results from those treating this Characters
object as a source for a
String
. All kinds of bad things might come from this. If this class is needed in a context where
programmers can't be depended upon to respect this limitation, a subclass should be created which overrides this
method to return a copy of the array (and overrides getArrayOffset
to always return 0).
public int getArrayOffset()
getArray
method.
getArray
.public boolean equals(Object OtherObj)
String
or another Characters
object. In all other cases, this method returns false.
equals
in class Object
OtherObj
- Another object to compare with this one.
true
if this object represents a sequence of characters equivalent to the
supplied object, false
otherwise.public boolean equals(char[] OtherChars, int OtherOffset, int OtherLength)
OtherChars
- The array of characters to be compared to the characters in this object.OtherOffset
- The index into OtherChars
at which comparison is to begin.OtherLength
- The number of characters in OtherChars
, starting at OtherOffset
, to
be compared.
true
if the characters match, false
otherwise.public int hashCode()
String
object, or as an array of characters.
hashCode
in class Object
public boolean startsWith(Characters Other)
Characters
object.
The comparison is case-sensitive.
Other
- The Characters
object to be compared with the start of this one.
true
if this object begins with the characters of the Other object, false
otherwise.public String substring(int FirstCharOffset)
FirstCharOffset
- Offset of the first character, inclusive.
public String substring(int FirstCharOffset, int LastCharOffset)
FirstCharOffset
- Offset of the first character, inclusive.LastCharOffset
- Offset of the final character, exclusive.
public CharSequence subSequence(int FirstCharOffset, int LastCharOffset)
Characters
instance representing a subsequence of this object's characters.
subSequence
in interface CharSequence
FirstCharOffset
- Offset of the first character, inclusive.LastCharOffset
- Offset of the final character, exclusive.
Characters
.public char charAt(int Index) throws IndexOutOfBoundsException
char
value at the specified index. An index ranges from zero to length() - 1
.
The first char
value of the sequence is at index zero, the next at index one, and so on, as for array
indexing.
If the char value specified by the index is a surrogate, the surrogate value is returned.
charAt
in interface CharSequence
Index
- The index of the character to be returned.
char
at the specified index.
IndexOutOfBoundsException
- If the index is invalid.public int indexOf(int Char)
Char
- Character to be searched for.
public int indexOf(int Char, int Offset)
Char
- Character to be searched for.Offset
- The offset at which to begin the search.
Char
, or -1 if it was not found.public String toString()
String
representation of the characters represented by this Characters
object.
This method always returns the same String
object for efficiency. If only a character array
representation of the characters exists, a new String
object is created and cached for future use.
toString
in interface CharSequence
toString
in class Object
String
.public boolean hasString()
true
if this object already contains a String
representation of its characters, or
false if such a representation has not yet been created.
true
if a String
representation of this object has already exists,
false
otherwise.public boolean hasArray()
true
if this object already contains a char array representation of its characters,
or false
if such a representation has not yet been created.
true
if a char array representation of this object has already exists, false
otherwise.public Characters append(Characters Other)
Characters
object representing the concatenation of first this object, and then the
specified Characters
object.
Other
- The characters to be appended to this object.
Characters
object representing this + Other
.public void append(StringBuffer Buff)
StringBuffer
.
Buff
- The StringBuffer
to which this object's characters should be appended.public void append(StringBuilder Buff)
StringBuilder
.
Buff
- The StringBuilder
to which this object's characters should be appended.public void print(PrintStream Out)
PrintStream
.
Out
- PrintStream
to which this object's characters should be printed.public void println(PrintStream Out)
PrintStream
object's println
method to print the characters of this
object.
Out
- PrintStream
to which this object's characters should be printed.public void print(PrintWriter Out) throws IOException
PrintWriter
.
Out
- PrintWriter
to which this object's characters should be printed.
IOException
- If thers's a problem printing to the PrintWriter
.public void println(PrintWriter Out) throws IOException
PrintWriter
object's println
method to print the characters of this
object.
Out
- PrintWriter
to which this object's characters should be printed.
IOException
- If thers's a problem printing to the PrintWriter
.public void write(Writer Out) throws IOException
Writer
.
Out
- Writer
to which this object's characters should be written.
IOException
- If thers's a problem writing to the Writer
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |