com.sosnoski.util
Class CharBuffer

java.lang.Object
  |
  +--com.sosnoski.util.GrowableBase
        |
        +--com.sosnoski.util.array.ArrayBase
              |
              +--com.sosnoski.util.array.CharArray
                    |
                    +--com.sosnoski.util.CharBuffer

public class CharBuffer
extends CharArray

Growable char array with added StringBuffer-like functionality. This implementation differs from StringBuffer in that it is unsynchronized so as to provide the best possible performance for typical usage scenarios. Explicit synchronization must be implemented by a wrapper class or directly by the application in cases where instances are modified in a multithreaded environment. See the base classes for other details of the implementation.

This class defines a number of convenience methods for working with character data (including simple arrays and Strings). Besides allowing character data to be appended/inserted/replaced in the growable array, other methods support comparisons between the several forms of character sequences and calculations of hash codes independent of the form of the sequence.

Version:
1.0
Author:
Dennis M. Sosnoski

Field Summary
protected static int KEY_MULTIPLIER
          Hash value multiplier to scramble bits in accumulation.
 
Fields inherited from class com.sosnoski.util.array.CharArray
m_baseArray
 
Fields inherited from class com.sosnoski.util.array.ArrayBase
m_countPresent
 
Fields inherited from class com.sosnoski.util.GrowableBase
DEFAULT_SIZE, m_countLimit, m_maximumGrowth
 
Constructor Summary
CharBuffer()
          Default constructor.
CharBuffer(char[] base)
          Constructor from char[].
CharBuffer(CharArray base)
          Copy (clone) constructor.
CharBuffer(int size)
          Constructor with initial size specified.
CharBuffer(int size, int growth)
          Constructor with full specification.
CharBuffer(java.lang.String base)
          Constructor from String.
 
Method Summary
protected  void adjust(int from, int to, int length)
          Adjust the characters in the array to make room for an insertion or replacement.
 int append(char[] text)
          Appends all the characters from an array to the current contents of the array.
 int append(char[] text, int offset, int length)
          Appends the characters from an array range to the current contents of the array.
 int append(CharArray text)
          Appends all the characters from another growable array to the current contents of the array.
 int append(java.lang.String text)
          Appends the characters from a String to the current contents of the array.
 java.lang.Object clone()
          Duplicates the object with the generic call.
 boolean equals(char[] comp)
          Compare the character sequence in the array with that in a simple array.
static boolean equals(char[] a, char[] b)
          Compare the character sequences in a pair of arrays.
 boolean equals(char[] comp, int offset, int length)
          Compare the character sequence in the array with the characters in a simple array range.
static boolean equals(char[] a, java.lang.String b)
          Compare the character sequences in a simple array and a String.
 boolean equals(CharArray comp)
          Compare the character sequence in the array with the sequence in another growable array.
 boolean equals(java.lang.String comp)
          Compare the character sequence in the array with a String.
 boolean equalsNoCase(char[] comp)
          Compare the character sequence in the array with that in a simple array without regard to case.
static boolean equalsNoCase(char[] a, char[] b)
          Compare the character sequences in a pair of arrays without regard to case.
 boolean equalsNoCase(char[] comp, int offset, int length)
          Compare the character sequence in the array with the characters in a simple array range without regard to case.
static boolean equalsNoCase(char[] a, java.lang.String b)
          Compare the character sequences in a simple array and a String without regard to case.
 boolean equalsNoCase(CharArray comp)
          Compare the character sequence in the array with the sequence in another growable array without regard to case.
 boolean equalsNoCase(java.lang.String comp)
          Compare the character sequence in the array with a String without regard to case.
 int hashCode()
          Compute a compatible hash code value for this character sequence.
static int hashCode(char[] text)
          Compute the compatible hash code value for character sequence in a simple array.
static int hashCode(java.lang.String text)
          Compute the compatible hash code value for character sequence in a String.
 void insert(int offset, char[] text)
          Insert the characters from a char[] into the array.
 void insert(int offset, java.lang.String text)
          Insert the characters from a String into the array.
 void replace(int from, int to, char[] text)
          Replace a character range in the array with the characters from a char[].
 void replace(int from, int to, java.lang.String text)
          Replace a character range in the array with the characters from a String.
 java.lang.String toString()
          Construct a String from the character sequence present.
 java.lang.String toString(int offset, int length)
          Construct a String from a portion of the character sequence present.
 
Methods inherited from class com.sosnoski.util.array.CharArray
add, add, get, getArray, set, setArray, toArray, toArray
 
Methods inherited from class com.sosnoski.util.array.ArrayBase
buildArray, clear, getAddIndex, getArray, makeInsertSpace, remove, remove, setSize, size
 
Methods inherited from class com.sosnoski.util.GrowableBase
discardValues, ensureCapacity, growArray, resizeCopy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

KEY_MULTIPLIER

protected static final int KEY_MULTIPLIER
Hash value multiplier to scramble bits in accumulation.
Constructor Detail

CharBuffer

public CharBuffer(int size,
                  int growth)
Constructor with full specification.
Parameters:
size - number of char values initially allowed in array
growth - maximum size increment for growing array

CharBuffer

public CharBuffer(int size)
Constructor with initial size specified.
Parameters:
size - number of char values initially allowed in array

CharBuffer

public CharBuffer()
Default constructor.

CharBuffer

public CharBuffer(java.lang.String base)
Constructor from String.

CharBuffer

public CharBuffer(char[] base)
Constructor from char[].

CharBuffer

public CharBuffer(CharArray base)
Copy (clone) constructor.
Parameters:
base - instance being copied
Method Detail

append

public int append(java.lang.String text)
Appends the characters from a String to the current contents of the array.
Parameters:
text - String of characters to be appended
Returns:
index number of first character appended

append

public int append(char[] text,
                  int offset,
                  int length)
Appends the characters from an array range to the current contents of the array.
Parameters:
text - array containing characters to be appended
offset - starting offset in array
length - length of character range in array
Returns:
index number of first character appended

append

public int append(char[] text)
Appends all the characters from an array to the current contents of the array.
Parameters:
text - array containing characters to be appended
Returns:
index number of first character appended

append

public int append(CharArray text)
Appends all the characters from another growable array to the current contents of the array.
Parameters:
text - growable array containing characters to be appended
Returns:
index number of first character appended

adjust

protected void adjust(int from,
                      int to,
                      int length)
Adjust the characters in the array to make room for an insertion or replacement. Depending on the relative sizes of the range being replaced and the range being inserted, this may move characters past the start of the replacement range up or down in the array.
Parameters:
from - index number of first character to be replaced
to - index number past last character to be replaced
length - length of character range being inserted

replace

public void replace(int from,
                    int to,
                    java.lang.String text)
Replace a character range in the array with the characters from a String.
Parameters:
from - index number of first character to be replaced
to - index number past last character to be replaced
text - replacement text

replace

public void replace(int from,
                    int to,
                    char[] text)
Replace a character range in the array with the characters from a char[].
Parameters:
from - index number of first character to be replaced
to - index number past last character to be replaced
text - replacement text

insert

public void insert(int offset,
                   java.lang.String text)
Insert the characters from a String into the array.
Parameters:
offset - insert position offset in array
text - insertion text

insert

public void insert(int offset,
                   char[] text)
Insert the characters from a char[] into the array.
Parameters:
offset - insert position offset in array
text - insertion text

equals

public boolean equals(java.lang.String comp)
Compare the character sequence in the array with a String.
Parameters:
comp - String value to be compared
Returns:
true if the character sequences are identical, false if they're different

equals

public boolean equals(char[] comp,
                      int offset,
                      int length)
Compare the character sequence in the array with the characters in a simple array range.
Parameters:
comp - array of characters to be compared
offset - starting offset in array
length - length of character range in array
Returns:
true if the character sequences are identical, false if they're different

equals

public boolean equals(char[] comp)
Compare the character sequence in the array with that in a simple array.
Parameters:
comp - array of characters to be compared
Returns:
true if the character sequences are identical, false if they're different

equals

public boolean equals(CharArray comp)
Compare the character sequence in the array with the sequence in another growable array.
Parameters:
comp - array of characters to be compared
Returns:
true if the character sequences are identical, false if they're different

equals

public static boolean equals(char[] a,
                             char[] b)
Compare the character sequences in a pair of arrays.
Parameters:
a - first character sequence array (non-null)
b - second character sequence array (may be null)
Returns:
true if the character sequences are identical, false if they're different

equals

public static boolean equals(char[] a,
                             java.lang.String b)
Compare the character sequences in a simple array and a String.
Parameters:
a - simple array character sequence (non-null)
b - String character sequence (may be null)
Returns:
true if the character sequences are identical, false if they're different

equalsNoCase

public boolean equalsNoCase(java.lang.String comp)
Compare the character sequence in the array with a String without regard to case.
Parameters:
comp - String value to be compared
Returns:
true if the character sequences are identical except perhaps for case, false if they're different

equalsNoCase

public boolean equalsNoCase(char[] comp,
                            int offset,
                            int length)
Compare the character sequence in the array with the characters in a simple array range without regard to case.
Parameters:
comp - array of characters to be compared
offset - starting offset in array
length - length of character range in array
Returns:
true if the character sequences are identical except perhaps for case, false if they're different

equalsNoCase

public boolean equalsNoCase(char[] comp)
Compare the character sequence in the array with that in a simple array without regard to case.
Parameters:
comp - array of characters to be compared
Returns:
true if the character sequences are identical except perhaps for case, false if they're different

equalsNoCase

public boolean equalsNoCase(CharArray comp)
Compare the character sequence in the array with the sequence in another growable array without regard to case.
Parameters:
comp - array of characters to be compared
Returns:
true if the character sequences are identical except perhaps for case, false if they're different

equalsNoCase

public static boolean equalsNoCase(char[] a,
                                   char[] b)
Compare the character sequences in a pair of arrays without regard to case.
Parameters:
a - first character sequence array (non-null)
b - second character sequence array (may be null)
Returns:
true if the character sequences are identical except perhaps for case, false if they're different

equalsNoCase

public static boolean equalsNoCase(char[] a,
                                   java.lang.String b)
Compare the character sequences in a simple array and a String without regard to case.
Parameters:
a - simple array character sequence (non-null)
b - String character sequence (may be null)
Returns:
true if the character sequences are identical except perhaps for case, false if they're different

hashCode

public static int hashCode(char[] text)
Compute the compatible hash code value for character sequence in a simple array.
Parameters:
text - text to be hashed
Returns:
compatible hash code value

hashCode

public static int hashCode(java.lang.String text)
Compute the compatible hash code value for character sequence in a String.
Parameters:
text - text to be hashed
Returns:
compatible hash code value

hashCode

public int hashCode()
Compute a compatible hash code value for this character sequence.
Overrides:
hashCode in class java.lang.Object
Returns:
compatible hash code value

clone

public java.lang.Object clone()
Duplicates the object with the generic call.
Overrides:
clone in class CharArray
Returns:
a copy of the object

toString

public java.lang.String toString()
Construct a String from the character sequence present.
Overrides:
toString in class java.lang.Object
Returns:
copy of data as String

toString

public java.lang.String toString(int offset,
                                 int length)
Construct a String from a portion of the character sequence present.
Parameters:
offset - start offset in array
length - number of characters to use
Returns:
copy of data as String


Company Web Site

XML Benchmark Home