Package org.apache.uima.internal.util
Class CharArrayString
java.lang.Object
org.apache.uima.internal.util.CharArrayString
An 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
ConstructorDescriptionCharArrayString
(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
(String string) Create a new CharArrayString from a String. -
Method Summary
Modifier and TypeMethodDescriptionchar
charAt
(int pos) Return the character at a given position.copy()
Copy this string.boolean
endsWith
(char c) Check if we end in a given character.boolean
endsWith
(CharArrayString string) Check of we end in a give string suffix.boolean
Check for equality with another CharArrayString.char[]
getChars()
Get the internal character array.int
getEnd()
Get the end position of the string in the internal array.int
getStart()
Get the start position of the string in the internal array.int
hashCode()
Get the hash code for this object.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.static final int
Compute a hash-code for a string.int
indexOf
(char c) Find the first occurence of a given char.int
indexOf
(char c, int offset) Find an occurence of a given character after some position.int
lastIndexOf
(char c) Find the last occurence of a character.int
length()
Get the length of the string.void
setChar
(int pos, char c) Set the char at a certain position.substring
(int startPos) Return a substring starting at a given position.substring
(int startPos, int endPos) Returns a substring.toString()
Return a string representation.trim()
Trim this.
-
Constructor Details
-
CharArrayString
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 Details
-
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
Trim this.- Returns:
- A trimmed version.
-
substring
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:
IndexOutOfBoundsException
- If the position parameters are not valid string positions.
-
substring
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
-1
if the character is not contained in the string.
-
toString
Return a string representation. -
endsWith
Check of we end in a give string suffix.- Parameters:
string
- The string suffix we're looking for.- Returns:
true
iffstring
is a suffix of this.
-
endsWith
public boolean endsWith(char c) Check if we end in a given character.- Parameters:
c
- The character.- Returns:
true
iff 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
Find 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
-1
if the char wasn't found. - Throws:
IndexOutOfBoundsException
- Ifoffset
is 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
-1
if the char couldn't be found.
-
setChar
Set the char at a certain position.- Parameters:
pos
- The position where to set the char.c
- The char to set.- Throws:
IndexOutOfBoundsException
- Ifpos
is out of bounds.
-
copy
Copy this string.- Returns:
- A copy.
-
hashCode
public int hashCode()Get the hash code for this object. -
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
Compute a hash-code for a string.- Parameters:
s
- The string to get the hash code for.- Returns:
- A hash code.
-
equals
Check for equality with another CharArrayString.
-