net.sf.ivmaidns.util
Class CharVector

java.lang.Object
  extended by net.sf.ivmaidns.util.CharVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Indexable, ReallyCloneable, Sortable, Verifiable

public final class CharVector
extends java.lang.Object
implements ReallyCloneable, java.io.Serializable, Indexable, Sortable, Verifiable

Class for 'char' array wrappers. This class wraps a primitive char-type array, and has the possibility to resize (when required) the wrapped array. This class supports cloning, serialization and comparison of its instances. In addition, the class contains static methods for char arrays resizing, filling in, reversing, non-zero elements counting, sorting, linear/binary searching in for a value or sequence, case-sensitive or case-insensitive 'less-equal-greater' comparison, mismatches counting and hashing.

Version:
2.0
Author:
Ivan Maidanski
See Also:
ByteVector, DoubleVector, FloatVector, IntVector, LongVector, ShortVector, BooleanVector, ObjectVector, StrComparator, Serialized Form

Field Summary
protected  char[] array
          The wrapped (encapsulated) custom char array.
protected static char[] EMPTY
          A constant initialized with an instance of empty char array.
 
Constructor Summary
CharVector()
          Constructs an empty char vector.
CharVector(char[] array)
          Constructs a new char array wrapper.
CharVector(int size)
          Constructs a new char vector of the specified length.
 
Method Summary
 char[] array()
          Returns array wrapped by this vector.
static int binarySearch(char[] array, int offset, int len, char value)
          Searches (fast) for value in a given sorted array.
 java.lang.Object clone()
          Creates and returns a copy of this object.
static int compare(char[] arrayA, int offsetA, int lenA, char[] arrayB, int offsetB, int lenB, boolean ignoreCase)
          Compares two given array regions.
 void copyAt(int srcOffset, int destOffset, int len)
          Copies a region of values at one offset to another offset in this vector.
static void counterSort(char[] array, int offset, int len)
          Sorts the elements in the region of a given array by counting the amount of each possible value in it.
static int countNonZero(char[] array)
          Count non-zero elements in a given array.
static char[] ensureSize(char[] array, int size)
          Ensures the length (capacity) of a given array.
 void ensureSize(int size)
          Ensures the size (capacity) of this vector.
static boolean equals(char[] arrayA, char[] arrayB)
          Tests whether or not the specified two arrays are equal.
 boolean equals(java.lang.Object obj)
          Indicates whether this object is equal to the specified one.
static void fill(char[] array, int offset, int len, char value)
          Fills in the region of a given array with the specified value.
 java.lang.Object getAt(int index)
          Returns the wrapped value of the element at the specified index.
 char getCharAt(int index)
          Returns value of the element at the specified index.
 boolean greaterThan(java.lang.Object obj)
          Tests for being semantically greater than the argument.
 int hashCode()
          Computes and returns a hash code value for the object.
static int hashCode(char[] array, boolean ignoreCase)
          Produces a hash code value for a given array.
static int indexOf(char[] subArray, int offset, int len, int index, char[] array, boolean ignoreCase)
          Searches forward for the specified sequence in a given array.
static int indexOf(char value, int index, char[] array, boolean ignoreCase)
          Searches forward for value in a given array.
 void integrityCheck()
          Verifies this object for its integrity.
static int lastIndexOf(char[] subArray, int offset, int len, int index, char[] array, boolean ignoreCase)
          Searches backward for the specified sequence in a given array.
static int lastIndexOf(char value, int index, char[] array, boolean ignoreCase)
          Searches backward for value in a given array.
 int length()
          Returns the number of elements in this vector.
static int mismatches(char[] arrayA, int offsetA, char[] arrayB, int offsetB, int len, boolean ignoreCase)
          Count the mismatches of two given array regions.
static void quickSort(char[] array, int offset, int len)
          Sorts the elements in the region of a given array using 'Quick' algorithm.
static char[] resize(char[] array, int size)
          Resizes a given array.
 void resize(int size)
          Resizes this vector.
static void reverse(char[] array)
          Reverses the elements order in a given array.
 void setArray(char[] array)
          Sets another array to be wrapped by this vector.
 void setAt(int index, char value)
          Assigns a new value to the element at the specified index.
 java.lang.String toString()
          Converts this character vector to a string.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

protected static final char[] EMPTY
A constant initialized with an instance of empty char array.

See Also:
array

array

protected char[] array
The wrapped (encapsulated) custom char array. array must be non-null.

See Also:
EMPTY, CharVector(), CharVector(int), CharVector(char[]), setArray(char[]), array(), length(), resize(int), ensureSize(int), setAt(int, char), getCharAt(int), copyAt(int, int, int), clone(), integrityCheck()
Constructor Detail

CharVector

public CharVector()
Constructs an empty char vector. This constructor is used for the creation of a resizable vector. The length of such a vector is changed only by resize(int) and ensureSize(int) methods.

See Also:
CharVector(int), CharVector(char[]), array(), length(), resize(int), ensureSize(int), setAt(int, char), getCharAt(int), copyAt(int, int, int), clone(), toString()

CharVector

public CharVector(int size)
Constructs a new char vector of the specified length. This constructor is typically used for the creation of a vector with a fixed size. All elements of the created vector are set to zero.

Parameters:
size - the initial length (unsigned) of the vector to be created.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
CharVector(), CharVector(char[]), array(), length(), setAt(int, char), getCharAt(int), copyAt(int, int, int), fill(char[], int, int, char), clone(), toString()

CharVector

public CharVector(char[] array)
           throws java.lang.NullPointerException
Constructs a new char array wrapper. This constructor is used for the creation of a vector which wraps the specified array (without copying it). The wrapped array may be further replaced with another one only by setArray(char[]) and by resize(int), ensureSize(int) methods.

Parameters:
array - the char array (must be non-null) to be wrapped.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
CharVector(), CharVector(int), setArray(char[]), array(), resize(int), ensureSize(int), setAt(int, char), getCharAt(int), copyAt(int, int, int), clone(), toString()
Method Detail

setArray

public void setArray(char[] array)
              throws java.lang.NullPointerException
Sets another array to be wrapped by this vector. Important notes: resize(int) and ensureSize(int) methods may change the array to be wrapped too (but only with its copy of a different length); this method does not copy array. If an exception is thrown then this vector remains unchanged.

Parameters:
array - the char array (must be non-null) to be wrapped.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
CharVector(), CharVector(char[]), array(), resize(int), ensureSize(int), setAt(int, char), getCharAt(int), copyAt(int, int, int), clone()

array

public final char[] array()
Returns array wrapped by this vector. Important notes: this method does not copy array.

Returns:
the char array (not null), which is wrapped.
Since:
1.8
See Also:
CharVector(char[]), setArray(char[]), length(), resize(int), ensureSize(int), copyAt(int, int, int), clone()

length

public int length()
Returns the number of elements in this vector. The result is the same as length of array().

Specified by:
length in interface Indexable
Returns:
the length (non-negative value) of this vector.
Since:
1.8
See Also:
setArray(char[]), array(), setAt(int, char), resize(int), ensureSize(int), getCharAt(int), getAt(int)

getAt

public java.lang.Object getAt(int index)
                       throws java.lang.ArrayIndexOutOfBoundsException
Returns the wrapped value of the element at the specified index. The result is the same as of new Character(array()[index]).

Specified by:
getAt in interface Indexable
Parameters:
index - the index (must be in the range) at which to return an element.
Returns:
an element (instance of Character) at index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is negative or is not less than length().
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
getCharAt(int), array(), length()

getCharAt

public final char getCharAt(int index)
                     throws java.lang.ArrayIndexOutOfBoundsException
Returns value of the element at the specified index. The result is the same as of array()[index].

Parameters:
index - the index (must be in the range) at which to return an element.
Returns:
a char element at index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is negative or is not less than length().
See Also:
array(), length(), setAt(int, char), resize(int), ensureSize(int)

setAt

public void setAt(int index,
                  char value)
           throws java.lang.ArrayIndexOutOfBoundsException
Assigns a new value to the element at the specified index. If an exception is thrown then this vector remains unchanged.

Parameters:
index - the index (must be in the range) at which to assign a new value.
value - the value to be assigned.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is negative or is not less than length().
See Also:
setArray(char[]), array(), length(), getCharAt(int), resize(int), ensureSize(int), copyAt(int, int, int), fill(char[], int, int, char)

copyAt

public void copyAt(int srcOffset,
                   int destOffset,
                   int len)
            throws java.lang.ArrayIndexOutOfBoundsException
Copies a region of values at one offset to another offset in this vector. Copying is performed here through arraycopy(Object, int, Object, int, int) method of System class. Negative len is treated as zero. If an exception is thrown then this vector remains unchanged.

Parameters:
srcOffset - the source first index (must be in the range) of the region to be copied.
destOffset - the first index (must be in the range) of the region copy destination.
len - the length of the region to be copied.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (srcOffset is negative or is greater than length() minus len, or destOffset is negative or is greater than length() minus len).
See Also:
array(), length(), setAt(int, char), getCharAt(int), resize(int), ensureSize(int)

resize

public void resize(int size)
Resizes this vector. The result is the same as of setArray(resize(array(), size)). This method changes the length of this vector to the specified one. Important notes: if size (length) of the vector grows then its new elements are set to zero. If an exception is thrown then this vector remains unchanged.

Parameters:
size - the (unsigned) length of this vector to set.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
CharVector(int), setArray(char[]), array(), length(), ensureSize(int), resize(char[], int)

ensureSize

public void ensureSize(int size)
Ensures the size (capacity) of this vector. The result is the same as of setArray(ensureSize(array(), size)). This method changes (only if size is greater than length()) the length of this vector to a value not less than size. Important notes: if size (length) of the vector grows then its new elements are set to zero. If an exception is thrown then this vector remains unchanged.

Parameters:
size - the (unsigned) length of this vector to be ensured.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
array(), length(), setAt(int, char), resize(int), ensureSize(char[], int)

resize

public static final char[] resize(char[] array,
                                  int size)
                           throws java.lang.NullPointerException
Resizes a given array. This method 'changes' (creates a new array and copies the content to it) the length of the specified array to the specified one. Important notes: array elements are not changed; if length of array is the same as size then array is returned else array content is copied into the result (all new elements are set to zero).

Parameters:
array - the array (must be non-null) to be resized.
size - the (unsigned) length of the array to set.
Returns:
the resized array (not null, with length equal to size).
Throws:
java.lang.NullPointerException - if array is null.
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
resize(int), ensureSize(char[], int), fill(char[], int, int, char)

ensureSize

public static final char[] ensureSize(char[] array,
                                      int size)
                               throws java.lang.NullPointerException
Ensures the length (capacity) of a given array. This method 'grows' (only if size is greater than length of array) the length of array. Important notes: array elements are not changed; if length of array is greater or the same as size then array is returned else array content is copied into the result (all new elements are set to zero).

Parameters:
array - the array (must be non-null) to be length-ensured.
size - the (unsigned) length of the array to ensure.
Returns:
the length-ensured array (not null, with length not less than size).
Throws:
java.lang.NullPointerException - if array is null.
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
ensureSize(int), resize(char[], int), fill(char[], int, int, char)

fill

public static final void fill(char[] array,
                              int offset,
                              int len,
                              char value)
                       throws java.lang.NullPointerException,
                              java.lang.ArrayIndexOutOfBoundsException
Fills in the region of a given array with the specified value. All the elements in the specified region of array are set to value. Negative len is treated as zero. If an exception is thrown then array remains unchanged. Else array content is altered. Important notes: region filling is performed using arraycopy(Object, int, Object, int, int) method of System class.

Parameters:
array - the array (must be non-null) to be filled in.
offset - the first index (must be in the range) of the region to fill in.
len - the length of the region to be filled.
value - the value to fill with.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
Since:
2.0
See Also:
array(), copyAt(int, int, int), indexOf(char[], int, int, int, char[], boolean), lastIndexOf(char[], int, int, int, char[], boolean), quickSort(char[], int, int), binarySearch(char[], int, int, char)

reverse

public static final void reverse(char[] array)
                          throws java.lang.NullPointerException
Reverses the elements order in a given array. The first element is exchanged with the least one, the second one is exchanged with the element just before the last one, etc. array content is altered.

Parameters:
array - the array (must be non-null) to be reversed.
Throws:
java.lang.NullPointerException - if array is null.
See Also:
array(), countNonZero(char[]), indexOf(char, int, char[], boolean), lastIndexOf(char, int, char[], boolean), hashCode(char[], boolean), equals(char[], char[]), compare(char[], int, int, char[], int, int, boolean), mismatches(char[], int, char[], int, int, boolean)

countNonZero

public static final int countNonZero(char[] array)
                              throws java.lang.NullPointerException
Count non-zero elements in a given array. This method returns the count of elements of array which are not equal to zero.

Parameters:
array - the array (must be non-null) to count non-zero elements in.
Returns:
the count (non-negative and not greater than length of array) of non-zero elements.
Throws:
java.lang.NullPointerException - if array is null.
Since:
2.0
See Also:
array(), fill(char[], int, int, char), equals(char[], char[]), compare(char[], int, int, char[], int, int, boolean), mismatches(char[], int, char[], int, int, boolean)

indexOf

public static final int indexOf(char value,
                                int index,
                                char[] array,
                                boolean ignoreCase)
                         throws java.lang.NullPointerException
Searches forward for value in a given array. Negative index is treated as zero, too big index is treated as length of array. Characters case is ignored only if ignoreCase. If value is not found then the result is -1.

Parameters:
value - the character to sequentially search for.
index - the first index, from which to begin forward searching.
array - the array (must be non-null) to be searched in.
ignoreCase - true if and only if characters case is ignored.
Returns:
the index (non-negative) of the found value or -1 (if not found).
Throws:
java.lang.NullPointerException - if array is null.
See Also:
array(), lastIndexOf(char, int, char[], boolean), indexOf(char[], int, int, int, char[], boolean), binarySearch(char[], int, int, char), equals(char[], char[]), compare(char[], int, int, char[], int, int, boolean)

lastIndexOf

public static final int lastIndexOf(char value,
                                    int index,
                                    char[] array,
                                    boolean ignoreCase)
                             throws java.lang.NullPointerException
Searches backward for value in a given array. Negative index is treated as -1, too big index is treated as length of array minus one. Characters case is ignored only if ignoreCase. If value is not found then the result is -1.

Parameters:
value - the character to sequentially search for.
index - the first index, from which to begin backward searching.
array - the array (must be non-null) to be searched in.
ignoreCase - true if and only if characters case is ignored.
Returns:
the index (non-negative) of the found value or -1 (if not found).
Throws:
java.lang.NullPointerException - if array is null.
See Also:
array(), indexOf(char, int, char[], boolean), lastIndexOf(char[], int, int, int, char[], boolean), binarySearch(char[], int, int, char), reverse(char[]), equals(char[], char[]), compare(char[], int, int, char[], int, int, boolean)

indexOf

public static final int indexOf(char[] subArray,
                                int offset,
                                int len,
                                int index,
                                char[] array,
                                boolean ignoreCase)
                         throws java.lang.NullPointerException,
                                java.lang.ArrayIndexOutOfBoundsException
Searches forward for the specified sequence in a given array. The searched sequence of values is specified by subArray, offset and len. Negative len is treated as zero. Negative index is treated as zero, too big index is treated as length of array. Characters case is ignored only if ignoreCase. If the sequence is not found then the result is -1.

Parameters:
subArray - the array (must be non-null) specifying the sequence of characters to search for.
offset - the offset (must be in the range) of the sequence in subArray.
len - the length of the sequence.
index - the first index, from which to begin forward searching.
array - the array (must be non-null) to be searched in.
ignoreCase - true if and only if characters case is ignored.
Returns:
the index (non-negative) of the found sequence or -1 (if not found).
Throws:
java.lang.NullPointerException - if subArray is null or array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of subArray minus len).
See Also:
array(), indexOf(char, int, char[], boolean), lastIndexOf(char[], int, int, int, char[], boolean), equals(char[], char[]), compare(char[], int, int, char[], int, int, boolean)

lastIndexOf

public static final int lastIndexOf(char[] subArray,
                                    int offset,
                                    int len,
                                    int index,
                                    char[] array,
                                    boolean ignoreCase)
                             throws java.lang.NullPointerException,
                                    java.lang.ArrayIndexOutOfBoundsException
Searches backward for the specified sequence in a given array. The searched sequence of values is specified by subArray, offset and len. Negative len is treated as zero. Negative index is treated as -1, too big index is treated as length of array minus one. Characters case is ignored only if ignoreCase. If the sequence is not found then the result is -1.

Parameters:
subArray - the array (must be non-null) specifying the sequence of characters to search for.
offset - the offset (must be in the range) of the sequence in subArray.
len - the length of the sequence.
index - the first index, from which to begin backward searching.
array - the array (must be non-null) to be searched in.
ignoreCase - true if and only if characters case is ignored.
Returns:
the index (non-negative) of the found sequence or -1 (if not found).
Throws:
java.lang.NullPointerException - if subArray is null or array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of subArray minus len).
See Also:
array(), lastIndexOf(char, int, char[], boolean), indexOf(char[], int, int, int, char[], boolean), equals(char[], char[]), compare(char[], int, int, char[], int, int, boolean)

hashCode

public static final int hashCode(char[] array,
                                 boolean ignoreCase)
                          throws java.lang.NullPointerException
Produces a hash code value for a given array. This method mixes all the characters (or their lower-case equivalents if ignoreCase) of array to produce a single hash code value.

Parameters:
array - the array (must be non-null) to evaluate hash of.
ignoreCase - true if and only if characters case is ignored.
Returns:
the hash code value for array.
Throws:
java.lang.NullPointerException - if array is null.
See Also:
array(), hashCode(), fill(char[], int, int, char), reverse(char[]), countNonZero(char[]), indexOf(char, int, char[], boolean), lastIndexOf(char, int, char[], boolean), equals(char[], char[]), compare(char[], int, int, char[], int, int, boolean), mismatches(char[], int, char[], int, int, boolean)

equals

public static final boolean equals(char[] arrayA,
                                   char[] arrayB)
                            throws java.lang.NullPointerException
Tests whether or not the specified two arrays are equal. This method returns true if and only if both of the arrays are of the same length and all the characters of the first array are equal to the corresponding characters of the second array (matching their case).

Parameters:
arrayA - the first array (must be non-null) to be compared.
arrayB - the second array (must be non-null) to compare with.
Returns:
true if and only if arrayA content is the same as arrayB content.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), equals(java.lang.Object), fill(char[], int, int, char), reverse(char[]), countNonZero(char[]), indexOf(char, int, char[], boolean), lastIndexOf(char, int, char[], boolean), indexOf(char[], int, int, int, char[], boolean), lastIndexOf(char[], int, int, int, char[], boolean), hashCode(char[], boolean), compare(char[], int, int, char[], int, int, boolean), mismatches(char[], int, char[], int, int, boolean)

mismatches

public static final int mismatches(char[] arrayA,
                                   int offsetA,
                                   char[] arrayB,
                                   int offsetB,
                                   int len,
                                   boolean ignoreCase)
                            throws java.lang.NullPointerException,
                                   java.lang.ArrayIndexOutOfBoundsException
Count the mismatches of two given array regions. This method returns the count of characters of the first array region which are not equal to the corresponding characters of the second array region (matching case or not). Negative len is treated as zero.

Parameters:
arrayA - the first array (must be non-null) to be compared.
offsetA - the first index (must be in the range) of the first region.
arrayB - the second array (must be non-null) to compare with.
offsetB - the first index (must be in the range) of the second region.
len - the length of the regions.
ignoreCase - true if and only if characters case is ignored.
Returns:
the count (non-negative) of found mismatches of the regions.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offsetA is negative or is greater than length of arrayA minus len, or offsetB is negative or is greater than length of arrayB minus len).
Since:
2.0
See Also:
array(), fill(char[], int, int, char), reverse(char[]), countNonZero(char[]), hashCode(char[], boolean), equals(char[], char[]), compare(char[], int, int, char[], int, int, boolean)

compare

public static final int compare(char[] arrayA,
                                int offsetA,
                                int lenA,
                                char[] arrayB,
                                int offsetB,
                                int lenB,
                                boolean ignoreCase)
                         throws java.lang.NullPointerException,
                                java.lang.ArrayIndexOutOfBoundsException
Compares two given array regions. This method returns a signed integer indicating case-sensitive or case-insensitive 'less-equal-greater' relation between the specified array regions of characters (the absolute value of the result, in fact, is the distance between the first found mismatch and the end of the bigger-length region). Negative lenA is treated as zero. Negative lenB is treated as zero. Important notes: the content of array regions is compared before comparing their length.

Parameters:
arrayA - the first array (must be non-null) to be compared.
offsetA - the first index (must be in the range) of the first region.
lenA - the length of the first region.
arrayB - the second array (must be non-null) to compare with.
offsetB - the first index (must be in the range) of the second region.
lenB - the length of the second region.
ignoreCase - true if and only if characters case is ignored.
Returns:
a negative integer, zero, or a positive integer as arrayA region is less than, equal to, or greater than arrayB one.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
java.lang.ArrayIndexOutOfBoundsException - if lenA is positive and (offsetA is negative or is greater than length of arrayA minus lenA), or if lenB is positive and (offsetB is negative or is greater than length of arrayB minus lenB).
See Also:
array(), greaterThan(java.lang.Object), fill(char[], int, int, char), reverse(char[]), indexOf(char, int, char[], boolean), lastIndexOf(char, int, char[], boolean), hashCode(char[], boolean), equals(char[], char[]), mismatches(char[], int, char[], int, int, boolean)

quickSort

public static final void quickSort(char[] array,
                                   int offset,
                                   int len)
                            throws java.lang.NullPointerException,
                                   java.lang.ArrayIndexOutOfBoundsException
Sorts the elements in the region of a given array using 'Quick' algorithm. Elements in the region are sorted into ascending natural (unsigned) order. But equal elements may be reordered (since the algorithm is not 'stable'). A small working stack is allocated (since the algorithm is 'in-place' and recursive). The algorithm cost is O(log(len) * len) typically, but may be of O(len * len) in the worst case (which is rare, in fact). Negative len is treated as zero. If an exception is thrown then array remains unchanged. Else the region content is altered.

Parameters:
array - the array (must be non-null) to be sorted.
offset - the first index (must be in the range) of the region to sort.
len - the length of the region to sort.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
array(), counterSort(char[], int, int), binarySearch(char[], int, int, char), fill(char[], int, int, char)

counterSort

public static final void counterSort(char[] array,
                                     int offset,
                                     int len)
                              throws java.lang.NullPointerException,
                                     java.lang.ArrayIndexOutOfBoundsException
Sorts the elements in the region of a given array by counting the amount of each possible value in it. Elements in the region are sorted into ascending natural (unsigned) order. A working (counter) buffer of (CHAR_MASK + 1) (or (BYTE_MASK + 1) if all characters in the region are bytes) integer values is allocated. The algorithm cost is linear but only for large regions. Negative len is treated as zero. If an exception is thrown then array remains unchanged. Else the region content is altered.

Parameters:
array - the array (must be non-null) to be sorted.
offset - the first index (must be in the range) of the region to sort.
len - the length of the region to sort.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
java.lang.OutOfMemoryError - if there is not enough memory.
Since:
2.0
See Also:
array(), quickSort(char[], int, int), binarySearch(char[], int, int, char), fill(char[], int, int, char)

binarySearch

public static final int binarySearch(char[] array,
                                     int offset,
                                     int len,
                                     char value)
                              throws java.lang.NullPointerException,
                                     java.lang.ArrayIndexOutOfBoundsException
Searches (fast) for value in a given sorted array. array (or its specified range) must be sorted ascending, or the result is undefined. The algorithm cost is of O(log(len)). Negative len is treated as zero. If value is not found then (-result - 1) is the offset of the insertion point for value.

Parameters:
array - the sorted array (must be non-null) to be searched in.
offset - the first index (must be in the range) of the region to search in.
len - the length of the region to search in.
value - the case-sensitive value to search for.
Returns:
the index (non-negative) of the found value or (-insertionOffset - 1) (a negative integer) if not found.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.ArrayIndexOutOfBoundsException - if len is positive and (offset is negative or is greater than length of array minus len).
See Also:
array(), indexOf(char, int, char[], boolean), lastIndexOf(char, int, char[], boolean), quickSort(char[], int, int), counterSort(char[], int, int), fill(char[], int, int, char)

clone

public java.lang.Object clone()
Creates and returns a copy of this object. This method creates a new instance of the class of this object and initializes its array with a copy of array of this vector.

Specified by:
clone in interface ReallyCloneable
Overrides:
clone in class java.lang.Object
Returns:
a copy (not null and != this) of this instance.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
CharVector(), array(), getCharAt(int), equals(java.lang.Object)

hashCode

public int hashCode()
Computes and returns a hash code value for the object. This method mixes lower-case equivalents of all the characters of this vector to produce a single hash code value.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.
See Also:
hashCode(char[], boolean), array(), length(), getCharAt(int), equals(java.lang.Object)

equals

public boolean equals(java.lang.Object obj)
Indicates whether this object is equal to the specified one. This method returns true if and only if obj is instance of this vector class and all elements of this vector are equal to the corresponding elements of obj vector.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object (may be null) with which to compare.
Returns:
true if and only if this value is the same as obj value.
See Also:
CharVector(), equals(char[], char[]), array(), length(), getCharAt(int), hashCode(), greaterThan(java.lang.Object)

greaterThan

public boolean greaterThan(java.lang.Object obj)
Tests for being semantically greater than the argument. The result is true if and only if obj is instance of this class and this object is greater than the specified object. Vectors are compared in the element-by-element case-sensitive manner, starting at index 0.

Specified by:
greaterThan in interface Sortable
Parameters:
obj - the second compared object (may be null).
Returns:
true if obj is comparable with this and this object is greater than obj, else false.
Since:
2.0
See Also:
compare(char[], int, int, char[], int, int, boolean), array(), length(), getCharAt(int), equals(java.lang.Object)

toString

public java.lang.String toString()
Converts this character vector to a string. All the characters of the wrapped array are concatenated together (without spaces) to produce a single string (using String(char[]) constructor).

Overrides:
toString in class java.lang.Object
Returns:
the string representation (not null) of this object.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
array(), length()

integrityCheck

public void integrityCheck()
Verifies this object for its integrity. For debug purpose only.

Specified by:
integrityCheck in interface Verifiable
Throws:
java.lang.InternalError - if integrity violation is detected.
Since:
2.0
See Also:
CharVector(char[]), setArray(char[]), array()