Package org.apache.uima.internal.util
Class CharArrayString
- java.lang.Object
-
- org.apache.uima.internal.util.CharArrayString
-
public class CharArrayString extends java.lang.ObjectAn unsafe String class based on a publicly accessible character array. This class aims to provide similar functionality as java.lang.String, but without the overhead of copying at creation time. Consequently, you should only use this class if you have complete control over the underlying memory (i.e., char array).- Version:
- $Id: CharArrayString.java,v 1.1 2002/09/30 19:09:09 goetz Exp $
-
-
Constructor Summary
Constructors Constructor Description CharArrayString(char[] charArray)Create a new CharArrayString from an array of characters.CharArrayString(char[] charArray, int startPos, int length)Create a new CharArrayString from an array of characters.CharArrayString(java.lang.String string)Create a new CharArrayString from a String.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description charcharAt(int pos)Return the character at a given position.CharArrayStringcopy()Copy this string.booleanendsWith(char c)Check if we end in a given character.booleanendsWith(CharArrayString string)Check of we end in a give string suffix.booleanequals(java.lang.Object o)Check for equality with another CharArrayString.char[]getChars()Get the internal character array.intgetEnd()Get the end position of the string in the internal array.intgetStart()Get the start position of the string in the internal array.inthashCode()Get the hash code for this object.static inthashCode(char[] charArray, int startPos, int endPos)A static method to compute the hash code for a character range in an array.static inthashCode(java.lang.String s)Compute a hash-code for a string.intindexOf(char c)Find the first occurence of a given char.intindexOf(char c, int offset)Find an occurence of a given character after some position.intlastIndexOf(char c)Find the last occurence of a character.intlength()Get the length of the string.voidsetChar(int pos, char c)Set the char at a certain position.CharArrayStringsubstring(int startPos)Return a substring starting at a given position.CharArrayStringsubstring(int startPos, int endPos)Returns a substring.java.lang.StringtoString()Return a string representation.CharArrayStringtrim()Trim this.
-
-
-
Constructor Detail
-
CharArrayString
public CharArrayString(java.lang.String string)
Create a new CharArrayString from a String.- Parameters:
string- The input string. The content of this string is copied.
-
CharArrayString
public CharArrayString(char[] charArray)
Create a new CharArrayString from an array of characters.- Parameters:
charArray- The input char array.
-
CharArrayString
public CharArrayString(char[] charArray, int startPos, int length)Create a new CharArrayString from an array of characters.- Parameters:
charArray- The input char array.startPos- The start of the string.length- The length of the string.
-
-
Method Detail
-
length
public int length()
Get the length of the string.- Returns:
- The length.
-
getStart
public int getStart()
Get the start position of the string in the internal array.- Returns:
- The start position.
-
getEnd
public int getEnd()
Get the end position of the string in the internal array.- Returns:
- The end position.
-
getChars
public char[] getChars()
Get the internal character array.- Returns:
- The char array.
-
trim
public CharArrayString trim()
Trim this.- Returns:
- A trimmed version.
-
substring
public CharArrayString substring(int startPos, int endPos) throws java.lang.IndexOutOfBoundsException
Returns a substring. The position parameters are interpreted relative to the string represented in this object, not the underlying char array. Note that the substring is NOT a copy, but uses the same underlying char array.- Parameters:
startPos- The start of the substring.endPos- The end of the substring.- Returns:
- The corresponding substring.
- Throws:
java.lang.IndexOutOfBoundsException- If the position parameters are not valid string positions.
-
substring
public CharArrayString substring(int startPos)
Return a substring starting at a given position.- Parameters:
startPos- The start position of the substring.- Returns:
- A new substring, starting at
startPos.
-
lastIndexOf
public int lastIndexOf(char c)
Find the last occurence of a character.- Parameters:
c- The char we're looking for.- Returns:
- The last position of the character, or
-1if the character is not contained in the string.
-
toString
public java.lang.String toString()
Return a string representation.- Overrides:
toStringin classjava.lang.Object- Returns:
- The string version of this CharArrayString.
-
endsWith
public boolean endsWith(CharArrayString string)
Check of we end in a give string suffix.- Parameters:
string- The string suffix we're looking for.- Returns:
trueiffstringis a suffix of this.
-
endsWith
public boolean endsWith(char c)
Check if we end in a given character.- Parameters:
c- The character.- Returns:
trueiff we end inc.
-
charAt
public char charAt(int pos)
Return the character at a given position.- Parameters:
pos- The position we're looking for.- Returns:
- The character at the position.
-
indexOf
public int indexOf(char c, int offset) throws java.lang.IndexOutOfBoundsExceptionFind an occurence of a given character after some position.- Parameters:
c- The char we're looking for.offset- An offset after which we start looking.- Returns:
- The position, or
-1if the char wasn't found. - Throws:
java.lang.IndexOutOfBoundsException- Ifoffsetis less than 0.
-
indexOf
public int indexOf(char c)
Find the first occurence of a given char.- Parameters:
c- The char we're looking for.- Returns:
- The position of the char, or
-1if the char couldn't be found.
-
setChar
public void setChar(int pos, char c) throws java.lang.IndexOutOfBoundsExceptionSet the char at a certain position.- Parameters:
pos- The position where to set the char.c- The char to set.- Throws:
java.lang.IndexOutOfBoundsException- Ifposis out of bounds.
-
copy
public CharArrayString copy()
Copy this string.- Returns:
- A copy.
-
hashCode
public int hashCode()
Get the hash code for this object.- Overrides:
hashCodein classjava.lang.Object- Returns:
- The hash code.
-
hashCode
public static final int hashCode(char[] charArray, int startPos, int endPos)A static method to compute the hash code for a character range in an array.- Parameters:
charArray- -startPos- -endPos- -- Returns:
- The hash code.
-
hashCode
public static final int hashCode(java.lang.String s)
Compute a hash-code for a string.- Parameters:
s- The string to get the hash code for.- Returns:
- A hash code.
-
equals
public boolean equals(java.lang.Object o)
Check for equality with another CharArrayString.- Overrides:
equalsin classjava.lang.Object- Parameters:
o- The other string.- Returns:
trueiff the two strings are equal.
-
-