ariba.util.core
Class FastStringBuffer

java.lang.Object
  extended by ariba.util.core.FastStringBuffer
Direct Known Subclasses:
FormatBuffer

public class FastStringBuffer
extends java.lang.Object

Object subclass resembling the java.lang.StringBuffer class (an object that manages a mutable string). Unlike java.lang.StringBuffer, none of FastStringBuffer's methods are synchronized, which results in a significant performance increase. FastStringBuffer also has additional API that allows it to be more easily modified than the standard StringBuffer.


Constructor Summary
FastStringBuffer()
          Creates a FastStringBuffer containing the empty string.
FastStringBuffer(char aChar)
          Creates a FastStringBuffer containing the character aChar.
FastStringBuffer(int length)
          Constructs an empty String buffer with the specified initial length.
FastStringBuffer(java.lang.String aString)
          Creates a FastStringBuffer containing the characters in aString.
FastStringBuffer(java.lang.String aString, int start, int end)
          Creates a FastStringBuffer containing the characters in aString from the index start to end.
 
Method Summary
 void append(char aChar)
          Appends aChar to the FastStringBuffer.
 void append(char[] value)
          Appends the char array to the FastStringBuffer.
 void append(FastStringBuffer aBuffer)
          Appends a FastStringBuffer to this FastStringBuffer.
 void append(java.lang.Object aObject)
          Appends a string representation of aObject to the FastStringBuffer.
 void append(java.lang.String aString)
          Appends aString to the FastStringBuffer.
 void appendCharRange(char[] aChar, int startOffset, int endOffset)
          Copies characters from the character array into the FastStringBuffer.
 void appendStringRange(java.lang.String aString, int startOffset, int endOffset)
          Copies characters from the string into the FastStringBuffer.
 char[] charArray()
          Returns the FastStringBuffer's char array, for situation where it is needed.
 char charAt(int index)
          Returns the character at index.
 char[] getBuffer()
          Return the buffer holding the state of this FormatBuffer.
 boolean getDoublesCapacityWhenGrowing()
          Returns whether FastStringBuffer doubles its size when some data is inserted and the internal buffer is too small.
 int indexOf(char aChar)
          Returns the index of the first occurrence of aChar in the FastStringBuffer.
 int indexOf(char aChar, int offset)
          Returns the index of the first occurrence of aChar in the FastStringBuffer, starting at character offset.
 int indexOf(java.lang.String value)
          Returns the index of the first occurrence of value in the FastStringBuffer.
 int indexOf(java.lang.String value, int offset)
          Returns the index of the first occurrence of value in the FastStringBuffer, starting at character offset.
 void insert(char aChar, int index)
          Inserts aChar at index.
 void insert(java.lang.String aString, int index)
          Inserts aString at index.
 int length()
          Returns the number of characters in the FastStringBuffer.
 void moveChars(int fromIndex, int toIndex)
          This removes the characters between fromIndex and toIndex (non inclusive.) if fromIndex <= toIndex the method does nothing.
 void removeCharAt(int index)
          Removes the character at index.
 void replace(int index, char[] value)
          Replaces value at index.
 void replace(int index, char value, int span)
          Replaces value at index for span chars.
 void replace(java.lang.String oldString, java.lang.String newString)
          For each instance of oldString found in the buffer, we'll replace it with newString.
 void setCharAt(int index, char ch)
          Sets the character at the location index to the character ch.
 void setDoublesCapacityWhenGrowing(boolean aFlag)
          Set whether the FastStringBuffer should double its size when some data is inserted and the internal buffer is too small.
 void setStringValue(java.lang.String aString)
          Sets the FastStringBuffer's contents to the characters in aString.
 boolean startsWith(java.lang.String value)
          Check if the FastStringBuffer's characters start with the contents of a specified String.
 boolean startsWith(java.lang.String value, int offset)
          Check if the FastStringBuffer's characters start with the contents of a specified String.
 java.lang.String substring(int startIndex, int endIndex)
          Returns the String for the FastStringBuffer's contents.
 boolean tabOrSpaceAt(int index)
          Check if a tab or a space occurs at the specified position in the FastStringBuffer.
 java.lang.String toString()
          Returns the String for the FastStringBuffer's contents.
 void truncateToLength(int aLength)
          Truncates the FastStringBuffer to aLength characters.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FastStringBuffer

public FastStringBuffer(int length)
Constructs an empty String buffer with the specified initial length.

Parameters:
length - the initial length, must be greater than or equal to zero

FastStringBuffer

public FastStringBuffer()
Creates a FastStringBuffer containing the empty string.


FastStringBuffer

public FastStringBuffer(java.lang.String aString)
Creates a FastStringBuffer containing the characters in aString.

Parameters:
aString - the initial string to hold

FastStringBuffer

public FastStringBuffer(java.lang.String aString,
                        int start,
                        int end)
Creates a FastStringBuffer containing the characters in aString from the index start to end.

Parameters:
aString - the string to copy a range of characters from
start - the index of the string to start copying from
end - the index of the string to end copying by, the character at position end is excluded.

FastStringBuffer

public FastStringBuffer(char aChar)
Creates a FastStringBuffer containing the character aChar.

Parameters:
aChar - the initial character to contain
Method Detail

getBuffer

public char[] getBuffer()
Return the buffer holding the state of this FormatBuffer. The effect on the returned array of operations performed on this FormatBuffer is not defined.

Returns:
returns the character array that is used for internal storage. There may be garbage characters after the length.

setDoublesCapacityWhenGrowing

public void setDoublesCapacityWhenGrowing(boolean aFlag)
Set whether the FastStringBuffer should double its size when some data is inserted and the internal buffer is too small.

Parameters:
aFlag - if true (the default value if the method is not called) the array will double capacity when growing. If false it will only pad by up to 20 characters.

getDoublesCapacityWhenGrowing

public boolean getDoublesCapacityWhenGrowing()
Returns whether FastStringBuffer doubles its size when some data is inserted and the internal buffer is too small.

Returns:
true if the buffer will double when growing, false otherwise.

setStringValue

public void setStringValue(java.lang.String aString)
Sets the FastStringBuffer's contents to the characters in aString.

Parameters:
aString - the string to set the contents of the fastStringBuffer to. Any previous contents will be cleared.

substring

public java.lang.String substring(int startIndex,
                                  int endIndex)
Returns the String for the FastStringBuffer's contents.

Parameters:
startIndex - the index of the FastStringBuffer to start copying from.
endIndex - the index of the FastStringBuffer to end copying with. The character at endIndex is excluded.
Returns:
a new String containing the characters between the specified start and end index into the FastStringBuffer
Throws:
java.lang.StringIndexOutOfBoundsException - if the startIndex or endIndex arguments index characters outside the bounds of the FastStringBuffer.

toString

public java.lang.String toString()
Returns the String for the FastStringBuffer's contents.

Overrides:
toString in class java.lang.Object
Returns:
a string representing the contents of this buffer.

charAt

public char charAt(int index)
Returns the character at index.

Parameters:
index - the index of the character to return.
Returns:
the character at the location specified.
Throws:
java.lang.StringIndexOutOfBoundsException - If the index is invalid

startsWith

public boolean startsWith(java.lang.String value)
Check if the FastStringBuffer's characters start with the contents of a specified String.

Parameters:
value - the String to match against
Returns:
true if the specified value matches the first characters in the FastStringBuffer, false otherwise. Returns true if value is empty. If value is not empty, but the FastStringBuffer is empty, it will return false.

startsWith

public boolean startsWith(java.lang.String value,
                          int offset)
Check if the FastStringBuffer's characters start with the contents of a specified String.

Parameters:
value - the String to match against.
offset - the offset of FastStringBuffer's contents to start the comparison at.
Returns:
true if the specified value matches the offset characters in the FastStringBuffer, false otherwise. Returns true if value is empty as long as the offset is valid.

indexOf

public int indexOf(java.lang.String value)
Returns the index of the first occurrence of value in the FastStringBuffer. If the value is not found, -1 is returned.

Parameters:
value - the String to search for in the FastStringBuffer
Returns:
the index of the first occurrence of the String in the character sequence represented by this object, or -1 if the String does not occur.

indexOf

public int indexOf(java.lang.String value,
                   int offset)
Returns the index of the first occurrence of value in the FastStringBuffer, starting at character offset. If the value is not found, -1 is returned.

Parameters:
value - the String to search for in the FastStringBuffer
offset - the offset into the FastStringBuffer's contents to start searching at.
Returns:
the index of the first occurrence of the String in the character sequence represented by this object starting at the specified offset, or -1 if the String does not occur or if the index is out of bounds.

indexOf

public int indexOf(char aChar,
                   int offset)
Returns the index of the first occurrence of aChar in the FastStringBuffer, starting at character offset.

Parameters:
aChar - the character to locate in the FastStringBuffer
offset - the offset in the FastStringBuffer for the first character to search
Returns:
the index of the first occurrence of the char in the character sequence represented by this object starting at the specified offset, or -1 if the char does not occur.

indexOf

public int indexOf(char aChar)
Returns the index of the first occurrence of aChar in the FastStringBuffer. Equivalent to the code:
        indexOf(aChar, 0);
        

Parameters:
aChar - the character to locate in the FastStringBuffer
Returns:
the index of the first occurrence of the char in the character sequence represented by this object, or -1 if the char does not occur.
See Also:
indexOf(java.lang.String)

tabOrSpaceAt

public boolean tabOrSpaceAt(int index)
Check if a tab or a space occurs at the specified position in the FastStringBuffer.

Parameters:
index - the index of the FastStringBuffer's contents to check.
Returns:
true if the FastStringBuffer contains a space or tab character at position index, false otherwise
Throws:
java.lang.StringIndexOutOfBoundsException - If the index is invalid.

setCharAt

public void setCharAt(int index,
                      char ch)
Sets the character at the location index to the character ch.

Parameters:
index - the index of the character in the FastStringBuffer to replace. It must be >= 0 and <= the length.
ch - the character to replace the value with.
Throws:
java.lang.StringIndexOutOfBoundsException - If the index is invalid.

append

public void append(char aChar)
Appends aChar to the FastStringBuffer.

Parameters:
aChar - the character to append to the FastStringBuffer

append

public void append(java.lang.String aString)
Appends aString to the FastStringBuffer. The behavior of append(null) is not defined.

Parameters:
aString - the String to append to the FastStringBuffer

append

public void append(java.lang.Object aObject)
Appends a string representation of aObject to the FastStringBuffer. Equivalent to the code:
        append(String.valueOf(aObject));
        

Parameters:
aObject - the Object to append the String value of.

append

public void append(char[] value)
Appends the char array to the FastStringBuffer.

Parameters:
value - the character array to append to the string

append

public void append(FastStringBuffer aBuffer)
Appends a FastStringBuffer to this FastStringBuffer.

Parameters:
aBuffer - the FastStringBuffer to append to this FastStringBuffer.

appendStringRange

public void appendStringRange(java.lang.String aString,
                              int startOffset,
                              int endOffset)
Copies characters from the string into the FastStringBuffer.

The first character to be copied is at index startOffset; the last character to be copied is at index endOffset-1 (thus the total number of characters to be copied is endOffset-startOffset).

Parameters:
aString - the source String
startOffset - index of the first character in the string to copy.
endOffset - index after the last character in the string to copy.
Throws:
java.lang.StringIndexOutOfBoundsException - If srcBegin or srcEnd is out of range, or if srcBegin is greater than the srcEnd.

appendCharRange

public void appendCharRange(char[] aChar,
                            int startOffset,
                            int endOffset)
Copies characters from the character array into the FastStringBuffer.

The first character to be copied is at index startOffset; the last character to be copied is at index endOffset-1 (thus the total number of characters to be copied is endOffset-startOffset).

Parameters:
aChar - the source character array
startOffset - index of the first character in the array to copy.
endOffset - index after the last character in the array to copy.
Throws:
java.lang.StringIndexOutOfBoundsException - If startOffset or endOffset is out of range, or if startOffset is greater than the endOffset.

replace

public void replace(int index,
                    char[] value)
Replaces value at index. If index + value.length() is greater than or equal to the number of characters within the buffer, it is expanded to accommodate.

Parameters:
index - the index in the FastStringBuffer to start replacing characters at.
value - a character array used for the replacement contents.
Throws:
java.lang.StringIndexOutOfBoundsException - if the index is invalid.

replace

public void replace(int index,
                    char value,
                    int span)
Replaces value at index for span chars. If index + value.length() is greater than or equal to the number of characters within the buffer is expanded to accommodate.

Parameters:
index - index to start replacing at
value - character to replace with
span - number of characters to replace
Throws:
java.lang.StringIndexOutOfBoundsException - if the index is invalid

replace

public void replace(java.lang.String oldString,
                    java.lang.String newString)
For each instance of oldString found in the buffer, we'll replace it with newString.

Parameters:
oldString - string to replace
newString - replacement string

insert

public void insert(char aChar,
                   int index)
Inserts aChar at index. If index is greater than or equal to the number of characters within the buffer, appends aChar.

Parameters:
aChar - character to insert
index - location to insert character at
Throws:
java.lang.StringIndexOutOfBoundsException - if the index is invalid.

insert

public void insert(java.lang.String aString,
                   int index)
Inserts aString at index. If index is greater than or equal to the number of characters within the buffer, appends aString.

Parameters:
aString - string to insert into the FastStringBuffer
index - location to insert string.
Throws:
java.lang.StringIndexOutOfBoundsException - If the index is invalid.

removeCharAt

public void removeCharAt(int index)
Removes the character at index.

Parameters:
index - location to remove the character from
Throws:
java.lang.StringIndexOutOfBoundsException - if the index is invalid.

truncateToLength

public void truncateToLength(int aLength)
Truncates the FastStringBuffer to aLength characters. If aLength is invalid, does nothing.

Parameters:
aLength - the length to truncate the FastStringBuffer to

length

public int length()
Returns the number of characters in the FastStringBuffer.

Returns:
the current number of characters stored.

moveChars

public void moveChars(int fromIndex,
                      int toIndex)
This removes the characters between fromIndex and toIndex (non inclusive.) if fromIndex <= toIndex the method does nothing.

Parameters:
fromIndex - index to start removing characters from
toIndex - index to end removing characters
Throws:
java.lang.StringIndexOutOfBoundsException - if the fromIndex and toIndex are outside the range of the string.

charArray

public char[] charArray()
Returns the FastStringBuffer's char array, for situation where it is needed. For example, you can draw the FastStringBuffer's contents by passing the array to the Graphic's drawString() method that takes a char array, rather than first convert the StringBuffer to a String. You should never modify this array yourself.

Returns:
returns the character array that is used for internal storage. There may be garbage characters after the length.


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.