Class CharArray
java.lang.Object
com.opensymphony.module.sitemesh.html.util.CharArray
A leaner, meaner version of StringBuilder.
It provides basic functionality to handle dynamically-growing char arrays as quickly as possible. This class is not threadsafe.
- Author:
- Chris Miller
-
Constructor Summary
ConstructorsConstructorDescriptionCharArray(int size) Constructs a CharArray that is initialized to the specified size. -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) Appends a single character to the end of the character array.append(char[] chars) Appends the supplied characters to the end of the array.append(char[] chars, int position, int length) Append.Appends an existing CharArray on to this one.Appends the supplied string to the end of this character array.charcharAt(int pos) Returns the character that is at the specified position in the array.final voidclear()Clear the contents.booleancompareLower(String lowerStr, int offset) Compares the supplied uppercase string with the contents of the character array, starting at the offset specified.booleancompareLowerSubstr(String lowerStr) This compares a substring of this character array (as specified by thesetSubstr(int, int)method call) with the supplied string.Returns the substring that was specified by thesetSubstr(int, int)call.intlength()Returns the current length of the character array.voidsetLength(int newSize) Changes the size of the character array to the value specified.voidsetSubstr(int begin, int end) Allows an arbitrary substring of this character array to be specified.intReturns the hashcode for a lowercase version of the array's substring (as set by thesetSubstr(int, int)method).substring(int begin, int end) Returns a substring from within this character array.toString()Returns a String represenation of the character array.voidwriteTo(PrintWriter writer) Write to.
-
Constructor Details
-
CharArray
public CharArray(int size) Constructs a CharArray that is initialized to the specified size. Do not pass in a negative value because there is no bounds checking!- Parameters:
size- the size
-
-
Method Details
-
toString
Returns a String represenation of the character array. -
charAt
public char charAt(int pos) Returns the character that is at the specified position in the array. There is no bounds checking on this method so be sure to pass in a sensible value.- Parameters:
pos- the pos- Returns:
- the char
-
setLength
public void setLength(int newSize) Changes the size of the character array to the value specified. If the new size is less than the current size, the data in the internal array will be truncated. If the new size is <= 0, the array will be reset to empty (but, unlike StringBuilder, the internal array will NOT be shrunk). If the new size is > the current size, the array will be padded out with null characters ('\u0000').- Parameters:
newSize- the new size of the character array
-
length
public int length()Returns the current length of the character array.- Returns:
- the int
-
append
Appends an existing CharArray on to this one. Passing in anullCharArray will result in aNullPointerException.- Parameters:
chars- the chars- Returns:
- the char array
-
append
Appends the supplied characters to the end of the array.- Parameters:
chars- the chars- Returns:
- the char array
-
append
Append.- Parameters:
chars- the charsposition- the positionlength- the length- Returns:
- the char array
-
append
Appends a single character to the end of the character array.- Parameters:
c- the c- Returns:
- the char array
-
append
Appends the supplied string to the end of this character array. Passing in anullstring will result in aNullPointerException.- Parameters:
str- the str- Returns:
- the char array
-
substring
Returns a substring from within this character array. Note that NO range checking is performed!- Parameters:
begin- the beginend- the end- Returns:
- the string
-
setSubstr
public void setSubstr(int begin, int end) Allows an arbitrary substring of this character array to be specified. This method should be called prior to callingcompareLowerSubstr(String)to set the range of the substring comparison.- Parameters:
begin- the starting offset into the character array.end- the ending offset into the character array.
-
getLowerSubstr
Returns the substring that was specified by thesetSubstr(int, int)call.- Returns:
- the lower substr
-
compareLowerSubstr
This compares a substring of this character array (as specified by thesetSubstr(int, int)method call) with the supplied string. The supplied string must be lowercase, otherwise the comparison will fail.- Parameters:
lowerStr- the lower str- Returns:
- true, if successful
-
substrHashCode
public int substrHashCode()Returns the hashcode for a lowercase version of the array's substring (as set by thesetSubstr(int, int)method). This uses the same calculation as theString.hashCode()method so that it remains compatible with the hashcodes of normal strings.- Returns:
- the int
-
compareLower
Compares the supplied uppercase string with the contents of the character array, starting at the offset specified. This is a specialized method to help speed up the FastPageParser slightly.The supplied string is assumed to contain only uppercase ASCII characters. The offset indicates the offset into the character array that the comparison should start from.
If (and only if) the supplied string and the relevant portion of the character array are considered equal, this method will return
true.- Parameters:
lowerStr- the lower stroffset- the offset- Returns:
- true, if successful
-
clear
public final void clear()Clear the contents. -
writeTo
Write to.- Parameters:
writer- the writer
-