net.sf.ivmaidns.util
Class ObjectVector

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

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

Class for object array wrappers. This class contains an Object-type array, and has the possibility to resize (when required) the contained array. This class supports serialization (only if all its custom-type elements are serializable), shallow cloning and comparison of its instances. In addition, the class contains static methods for Object arrays resizing, filling in, reversing, non-null elements counting, linear/binary searching in for a value or sequence, equality testing and mismatches counting, hashing and 'to-string' conversion, 'greater-than' comparison and sorting according to the specified comparator, 'less-equal-greater' comparison for String arrays. As a container, this class is similar to ConstVector, except that any vector of this class is mutable and the contained array is the exact instance of Object[].

Version:
2.0
Author:
Ivan Maidanski
See Also:
ConstVector, ByteVector, CharVector, DoubleVector, FloatVector, IntVector, LongVector, ShortVector, BooleanVector, GComparator, Serialized Form

Field Summary
protected  java.lang.Object[] array
          The encapsulated Object-type array.
protected static java.lang.Object[] EMPTY
          A constant initialized with an exact instance of empty Object array.
 
Constructor Summary
ObjectVector()
          Constructs an empty Object vector.
ObjectVector(int size)
          Constructs a new Object vector of the specified length.
ObjectVector(java.lang.Object[] array)
          Constructs a new initialized Object-type container.
 
Method Summary
 java.lang.Object[] array()
          Returns array encapsulated by this vector.
static int binarySearch(java.lang.Object[] array, int offset, int len, java.lang.Object value, GComparator comparator)
          Searches (fast) for value in a given sorted array.
 java.lang.Object clone()
          Creates and returns a copy of this object.
static int compare(java.lang.String[] arrayA, int offsetA, int lenA, java.lang.String[] arrayB, int offsetB, int lenB)
          Compares two given String 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 int countNonNull(java.lang.Object[] array)
          Count non-null elements in a given array.
 void ensureSize(int size)
          Ensures the size (capacity) of this vector.
static java.lang.Object[] ensureSize(java.lang.Object[] array, int size)
          Ensures the length (capacity) of a given array.
 boolean equals(java.lang.Object obj)
          Indicates whether this object is equal to the specified one.
static boolean equals(java.lang.Object[] arrayA, java.lang.Object[] arrayB)
          Tests whether or not the specified two arrays are equal.
static void fill(java.lang.Object[] array, int offset, int len, java.lang.Object value)
          Fills in the region of a given array with the specified value.
 java.lang.Object getAt(int index)
          Returns value of the element at the specified index.
static boolean greater(java.lang.Object[] arrayA, java.lang.Object[] arrayB, GComparator comparator)
          Tests whether or not the first array is greater than the second one according to the supplied comparator.
static boolean greater(Sortable[] arrayA, Sortable[] arrayB)
          Tests whether or not the first Sortable array is greater than the second one.
 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(java.lang.Object[] array)
          Produces a hash code value for a given array.
static int indexOf(java.lang.Object[] subArray, int offset, int len, int index, java.lang.Object[] array)
          Searches forward for the specified sequence in a given array.
static int indexOf(java.lang.Object value, int index, java.lang.Object[] array)
          Searches forward for value in a given array.
 void integrityCheck()
          Verifies this object for its integrity.
static int lastIndexOf(java.lang.Object[] subArray, int offset, int len, int index, java.lang.Object[] array)
          Searches backward for the specified sequence in a given array.
static int lastIndexOf(java.lang.Object value, int index, java.lang.Object[] array)
          Searches backward for value in a given array.
 int length()
          Returns the number of elements in this vector.
static int mismatches(java.lang.Object[] arrayA, int offsetA, java.lang.Object[] arrayB, int offsetB, int len)
          Count the mismatches of two given array regions.
static int mismatchRemain(java.lang.Object[] arrayA, int offsetA, java.lang.Object[] arrayB, int offsetB, int len)
          Tests two given array regions for non-equality and returns the distance between the end of the regions and the first found regions mismatch.
static void quickSort(java.lang.Object[] array, int offset, int len, GComparator comparator)
          Sorts the elements in the region of a given array using 'Quick' algorithm according to the supplied comparator.
 void resize(int size)
          Resizes this vector.
static java.lang.Object[] resize(java.lang.Object[] array, int size)
          Resizes a given array.
static void reverse(java.lang.Object[] array)
          Reverses the elements order in a given array.
 void setArrayCloned(java.lang.Object[] array)
          Sets another array to be encapsulated by this vector.
 void setAt(int index, java.lang.Object value)
          Assigns a new value to the element at the specified index.
static void sort(java.lang.Object[] array, int offset, int len, GComparator comparator)
          Sorts the objects in the region of a given array according to the supplied comparator.
 java.lang.Object[] toArray()
          Returns a newly created array filled with the elements of this vector.
 java.lang.String toString()
          Converts this vector to its string representation.
static java.lang.String toString(java.lang.Object[] array, int offset, int len, char separator)
          Converts the region of a given array to its string representation.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY

protected static final java.lang.Object[] EMPTY
A constant initialized with an exact instance of empty Object array.

See Also:
array

array

protected java.lang.Object[] array
The encapsulated Object-type array. array must be the exact instance of Object[].

See Also:
EMPTY, ObjectVector(), ObjectVector(int), ObjectVector(java.lang.Object[]), setArrayCloned(java.lang.Object[]), array(), length(), toArray(), resize(int), ensureSize(int), setAt(int, java.lang.Object), getAt(int), copyAt(int, int, int), clone(), integrityCheck()
Constructor Detail

ObjectVector

public ObjectVector()
Constructs an empty Object 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:
ObjectVector(int), ObjectVector(java.lang.Object[]), array(), length(), resize(int), ensureSize(int), setAt(int, java.lang.Object), getAt(int), copyAt(int, int, int), clone(), toString()

ObjectVector

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

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

ObjectVector

public ObjectVector(java.lang.Object[] array)
             throws java.lang.NullPointerException
Constructs a new initialized Object-type container. This constructor is used for the creation of a vector which contains the copy of the specified array (the component type of the copy is always set to Object type). The encapsulated array may be further replaced with another one only by setArrayCloned(Object[]) and by resize(int), ensureSize(int) methods.

Parameters:
array - the Object array (must be non-null) to be copied and encapsulated.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
ObjectVector(), ObjectVector(int), setArrayCloned(java.lang.Object[]), array(), toArray(), resize(int), ensureSize(int), setAt(int, java.lang.Object), getAt(int), copyAt(int, int, int), clone(), toString()
Method Detail

setArrayCloned

public void setArrayCloned(java.lang.Object[] array)
                    throws java.lang.NullPointerException
Sets another array to be encapsulated by this vector. If an exception is thrown then this vector remains unchanged. Else this method creates a new Object array and copies the content of the supplied array into it.

Parameters:
array - the Object array (must be non-null) to be copied and encapsulated.
Throws:
java.lang.NullPointerException - if array is null.
java.lang.OutOfMemoryError - if there is not enough memory.
Since:
2.0
See Also:
ObjectVector(), ObjectVector(java.lang.Object[]), array(), toArray(), resize(int), ensureSize(int), setAt(int, java.lang.Object), getAt(int), copyAt(int, int, int), clone()

array

public final java.lang.Object[] array()
Returns array encapsulated by this vector. Important notes: this method does not copy array.

Returns:
the encapsulated array (not null).
Since:
1.8
See Also:
ObjectVector(java.lang.Object[]), setArrayCloned(java.lang.Object[]), toArray(), length(), resize(int), ensureSize(int), copyAt(int, int, int), clone()

toArray

public java.lang.Object[] toArray()
Returns a newly created array filled with the elements of this vector. The result is the exact instance of Object[] (with the same length as of this vector).

Returns:
the copy (not null) of the encapsulated array.
Throws:
java.lang.OutOfMemoryError - if there is not enough memory.
See Also:
ObjectVector(java.lang.Object[]), setArrayCloned(java.lang.Object[]), array(), 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:
setArrayCloned(java.lang.Object[]), array(), setAt(int, java.lang.Object), resize(int), ensureSize(int), getAt(int)

getAt

public java.lang.Object getAt(int index)
                       throws java.lang.ArrayIndexOutOfBoundsException
Returns value of the element at the specified index. The result is the same as of 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 (may be null) at index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is negative or is not less than length().
See Also:
array(), length(), setAt(int, java.lang.Object), resize(int), ensureSize(int)

setAt

public void setAt(int index,
                  java.lang.Object 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 (may be null) to be assigned.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is negative or is not less than length().
See Also:
setArrayCloned(java.lang.Object[]), array(), length(), getAt(int), resize(int), ensureSize(int), copyAt(int, int, int), fill(java.lang.Object[], int, int, java.lang.Object)

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, java.lang.Object), getAt(int), resize(int), ensureSize(int)

resize

public void resize(int size)
Resizes this vector. 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 null. 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:
ObjectVector(int), setArrayCloned(java.lang.Object[]), array(), length(), ensureSize(int), resize(java.lang.Object[], int)

ensureSize

public void ensureSize(int size)
Ensures the size (capacity) of this vector. 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 null. 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, java.lang.Object), resize(int), ensureSize(java.lang.Object[], int)

resize

public static final java.lang.Object[] resize(java.lang.Object[] array,
                                              int size)
                                       throws java.lang.NullPointerException
Resizes a given array. This method 'changes' (creates a new Object-type array and copies the content into 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 null in it, the component type of the new array is always set to Object).

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(java.lang.Object[], int), fill(java.lang.Object[], int, int, java.lang.Object)

ensureSize

public static final java.lang.Object[] ensureSize(java.lang.Object[] array,
                                                  int size)
                                           throws java.lang.NullPointerException
Ensures the length (capacity) of a given array. This method 'grows' (creates a new appropriate Object-type array and copies the content into it, but 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 null in it, the component type of the new array is always set to Object).

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(java.lang.Object[], int), fill(java.lang.Object[], int, int, java.lang.Object)

fill

public static final void fill(java.lang.Object[] array,
                              int offset,
                              int len,
                              java.lang.Object value)
                       throws java.lang.NullPointerException,
                              java.lang.ArrayIndexOutOfBoundsException,
                              java.lang.ArrayStoreException
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 (may be null) 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).
java.lang.ArrayStoreException - if value could not be stored into array.
Since:
2.0
See Also:
array(), copyAt(int, int, int), toString(java.lang.Object[], int, int, char), sort(java.lang.Object[], int, int, net.sf.ivmaidns.util.GComparator), binarySearch(java.lang.Object[], int, int, java.lang.Object, net.sf.ivmaidns.util.GComparator)

reverse

public static final void reverse(java.lang.Object[] 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(), countNonNull(java.lang.Object[]), indexOf(java.lang.Object, int, java.lang.Object[]), lastIndexOf(java.lang.Object, int, java.lang.Object[]), hashCode(java.lang.Object[]), equals(java.lang.Object[], java.lang.Object[]), mismatches(java.lang.Object[], int, java.lang.Object[], int, int)

countNonNull

public static final int countNonNull(java.lang.Object[] array)
                              throws java.lang.NullPointerException
Count non-null elements in a given array. This method returns the count of elements of array which are not null.

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

indexOf

public static final int indexOf(java.lang.Object value,
                                int index,
                                java.lang.Object[] array)
                         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. If value is not found then the result is -1. Important notes: value is tested for equality against the elements.

Parameters:
value - the value (may be null) 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.
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(), equals(java.lang.Object[], java.lang.Object[]), lastIndexOf(java.lang.Object, int, java.lang.Object[]), indexOf(java.lang.Object[], int, int, int, java.lang.Object[])

lastIndexOf

public static final int lastIndexOf(java.lang.Object value,
                                    int index,
                                    java.lang.Object[] array)
                             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. If value is not found then the result is -1. Important notes: value is tested for equality against the elements.

Parameters:
value - the value (may be null) 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.
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(), reverse(java.lang.Object[]), equals(java.lang.Object[], java.lang.Object[]), indexOf(java.lang.Object, int, java.lang.Object[]), lastIndexOf(java.lang.Object[], int, int, int, java.lang.Object[])

indexOf

public static final int indexOf(java.lang.Object[] subArray,
                                int offset,
                                int len,
                                int index,
                                java.lang.Object[] array)
                         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. If the sequence is not found then the result is -1. Important notes: the elements of subArray are tested for equality against the elements of array.

Parameters:
subArray - the array (must be non-null) specifying the sequence of values 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.
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(), equals(java.lang.Object[], java.lang.Object[]), indexOf(java.lang.Object, int, java.lang.Object[]), lastIndexOf(java.lang.Object[], int, int, int, java.lang.Object[])

lastIndexOf

public static final int lastIndexOf(java.lang.Object[] subArray,
                                    int offset,
                                    int len,
                                    int index,
                                    java.lang.Object[] array)
                             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. If the sequence is not found then the result is -1. Important notes: the elements of subArray are tested for equality against the elements of array.

Parameters:
subArray - the array (must be non-null) specifying the sequence of values 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.
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(), equals(java.lang.Object[], java.lang.Object[]), lastIndexOf(java.lang.Object, int, java.lang.Object[]), indexOf(java.lang.Object[], int, int, int, java.lang.Object[])

toString

public static final java.lang.String toString(java.lang.Object[] array,
                                              int offset,
                                              int len,
                                              char separator)
                                       throws java.lang.NullPointerException,
                                              java.lang.ArrayIndexOutOfBoundsException
Converts the region of a given array to its string representation. The string representations of values (if a value is null then "null") of the specified region of array are placed into the resulting string in the direct index order, delimited by a single separator character. Negative len is treated as zero.

Parameters:
array - the array (must be non-null) to be converted.
offset - the first index (must be in the range) of the region to be converted.
len - the length of the region to be converted.
separator - the delimiter character.
Returns:
the string representation (not null) of the specified region.
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(), toString(), fill(java.lang.Object[], int, int, java.lang.Object)

hashCode

public static final int hashCode(java.lang.Object[] array)
                          throws java.lang.NullPointerException
Produces a hash code value for a given array. This method mixes the hash codes of all the elements of array to produce a single hash code value. Important notes: if an element is null then its hash code is assumed to be 0.

Parameters:
array - the array (must be non-null) to evaluate hash of.
Returns:
the hash code value for array.
Throws:
java.lang.NullPointerException - if array is null.
See Also:
array(), hashCode(), fill(java.lang.Object[], int, int, java.lang.Object), countNonNull(java.lang.Object[]), indexOf(java.lang.Object, int, java.lang.Object[]), lastIndexOf(java.lang.Object, int, java.lang.Object[]), equals(java.lang.Object[], java.lang.Object[]), mismatches(java.lang.Object[], int, java.lang.Object[], int, int)

equals

public static final boolean equals(java.lang.Object[] arrayA,
                                   java.lang.Object[] 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 elements of the first array are equal to the corresponding elements of the second array. Important notes: the component type of arrays is not compared.

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.
See Also:
array(), equals(java.lang.Object), fill(java.lang.Object[], int, int, java.lang.Object), indexOf(java.lang.Object, int, java.lang.Object[]), lastIndexOf(java.lang.Object, int, java.lang.Object[]), hashCode(java.lang.Object[]), mismatchRemain(java.lang.Object[], int, java.lang.Object[], int, int)

mismatchRemain

public static final int mismatchRemain(java.lang.Object[] arrayA,
                                       int offsetA,
                                       java.lang.Object[] arrayB,
                                       int offsetB,
                                       int len)
                                throws java.lang.NullPointerException,
                                       java.lang.ArrayIndexOutOfBoundsException
Tests two given array regions for non-equality and returns the distance between the end of the regions and the first found regions mismatch. The search for mismatches is performed in the forward direction starting from the specified offsets. Negative len is treated as zero. Important notes: if no mismatch is found then zero is returned; the elements of the first array region are tested for equality against the elements of the second one.

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.
Returns:
the distance (non-negative) between the first found regions mismatch and the end 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(java.lang.Object[], int, int, java.lang.Object), reverse(java.lang.Object[]), countNonNull(java.lang.Object[]), hashCode(java.lang.Object[]), equals(java.lang.Object[], java.lang.Object[]), mismatches(java.lang.Object[], int, java.lang.Object[], int, int)

mismatches

public static final int mismatches(java.lang.Object[] arrayA,
                                   int offsetA,
                                   java.lang.Object[] arrayB,
                                   int offsetB,
                                   int len)
                            throws java.lang.NullPointerException,
                                   java.lang.ArrayIndexOutOfBoundsException
Count the mismatches of two given array regions. This method returns the count of elements of the first array region which are not equal to the corresponding elements of the second array region. Negative len is treated as zero. Important notes: the elements of the first array region are tested for equality against the elements of the second one.

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.
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(java.lang.Object[], int, int, java.lang.Object), reverse(java.lang.Object[]), countNonNull(java.lang.Object[]), hashCode(java.lang.Object[]), equals(java.lang.Object[], java.lang.Object[]), greater(java.lang.Object[], java.lang.Object[], net.sf.ivmaidns.util.GComparator)

greater

public static final boolean greater(java.lang.Object[] arrayA,
                                    java.lang.Object[] arrayB,
                                    GComparator comparator)
                             throws java.lang.NullPointerException
Tests whether or not the first array is greater than the second one according to the supplied comparator. Object arrays are compared here in the element-by-element manner, starting at index 0, and at each index elements are tested for equality and the first found non-equal elements pair is compared using comparator (returning the result of this final comparison). Important notes: if there is no non-equal elements pairs then the first array is considered to be greater than the second one only if its length is greater; the component type of arrays is not compared anyway.

Parameters:
arrayA - the first array (must be non-null) to be compared.
arrayB - the second array (must be non-null) to compare with.
comparator - the 'greater-than' comparator (must be non-null) to use.
Returns:
true if arrayA is semantically greater than arrayB, else false.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null, or comparator is null.
Since:
2.0
See Also:
array(), length(), greaterThan(java.lang.Object), indexOf(java.lang.Object, int, java.lang.Object[]), lastIndexOf(java.lang.Object, int, java.lang.Object[]), hashCode(java.lang.Object[]), equals(java.lang.Object[], java.lang.Object[]), sort(java.lang.Object[], int, int, net.sf.ivmaidns.util.GComparator), greater(net.sf.ivmaidns.util.Sortable[], net.sf.ivmaidns.util.Sortable[]), compare(java.lang.String[], int, int, java.lang.String[], int, int)

greater

public static final boolean greater(Sortable[] arrayA,
                                    Sortable[] arrayB)
                             throws java.lang.NullPointerException
Tests whether or not the first Sortable array is greater than the second one. Sortable arrays are compared here in the element-by-element manner, starting at index 0, and at each index elements are tested for equality and the first found non-equal elements pair is compared using the appropriate greaterThan(Object) method (returning the result of this final comparison). Important notes: if there is no non-equal elements pairs then the first array is considered to be greater than the second one only if its length is greater; the component type of arrays is not compared anyway.

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 arrayA is semantically greater than arrayB, else false.
Throws:
java.lang.NullPointerException - if arrayA is null or arrayB is null.
Since:
2.0
See Also:
array(), length(), equals(java.lang.Object[], java.lang.Object[]), greater(java.lang.Object[], java.lang.Object[], net.sf.ivmaidns.util.GComparator)

compare

public static final int compare(java.lang.String[] arrayA,
                                int offsetA,
                                int lenA,
                                java.lang.String[] arrayB,
                                int offsetB,
                                int lenB)
                         throws java.lang.NullPointerException,
                                java.lang.ArrayIndexOutOfBoundsException
Compares two given String array regions. This method returns a signed integer indicating 'less-equal-greater' case-sensitive relation between the specified array regions of strings (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; any null element is considered to be greater than a non-null one.

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.
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).
Since:
2.0
See Also:
array(), length(), equals(java.lang.Object[], java.lang.Object[]), greater(net.sf.ivmaidns.util.Sortable[], net.sf.ivmaidns.util.Sortable[]), greater(java.lang.Object[], java.lang.Object[], net.sf.ivmaidns.util.GComparator)

sort

public static final void sort(java.lang.Object[] array,
                              int offset,
                              int len,
                              GComparator comparator)
                       throws java.lang.NullPointerException,
                              java.lang.ArrayIndexOutOfBoundsException
Sorts the objects in the region of a given array according to the supplied comparator. The elements in the region are sorted (using 'Merge' algorithm) into the specified ascending order. Equal elements are not reordered (the algorithm is 'stable'). A temporary buffer of ((len + 1) / 2) objects is allocated. The algorithm cost is O(log(len) * len) in worst case, but may be near O(len) for nearly sorted arrays. 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.
comparator - the 'greater-than' comparator (must be non-null) to use.
Throws:
java.lang.NullPointerException - if array is null or comparator 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(), quickSort(java.lang.Object[], int, int, net.sf.ivmaidns.util.GComparator)

quickSort

public static final void quickSort(java.lang.Object[] array,
                                   int offset,
                                   int len,
                                   GComparator comparator)
                            throws java.lang.NullPointerException,
                                   java.lang.ArrayIndexOutOfBoundsException
Sorts the elements in the region of a given array using 'Quick' algorithm according to the supplied comparator. The elements in the region are sorted into the specified ascending 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.
comparator - the 'greater-than' comparator (must be non-null) to use.
Throws:
java.lang.NullPointerException - if array is null or comparator 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(), sort(java.lang.Object[], int, int, net.sf.ivmaidns.util.GComparator), binarySearch(java.lang.Object[], int, int, java.lang.Object, net.sf.ivmaidns.util.GComparator)

binarySearch

public static final int binarySearch(java.lang.Object[] array,
                                     int offset,
                                     int len,
                                     java.lang.Object value,
                                     GComparator comparator)
                              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 (according to the supplied comparator), or the result is undefined. The algorithm cost is of O(log(len)). The elements are compared against value. 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 value (may be null) to search for.
comparator - the 'greater-than' comparator (must be non-null) to use.
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 or comparator 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(), fill(java.lang.Object[], int, int, java.lang.Object), indexOf(java.lang.Object, int, java.lang.Object[]), lastIndexOf(java.lang.Object, int, java.lang.Object[]), sort(java.lang.Object[], int, int, net.sf.ivmaidns.util.GComparator), quickSort(java.lang.Object[], int, int, net.sf.ivmaidns.util.GComparator)

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:
ObjectVector(), array(), toArray(), getAt(int), equals(java.lang.Object)

hashCode

public int hashCode()
Computes and returns a hash code value for the object. This method mixes the hash codes of all the elements 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(java.lang.Object[]), array(), length(), getAt(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 the 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:
ObjectVector(), array(), length(), getAt(int), hashCode(), greaterThan(java.lang.Object), equals(java.lang.Object[], 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. Object vectors are compared in the element-by-element manner, starting at index 0 and at each index elements are tested for equality and the first non-equal elements pair is compared using INSTANCE of GComparator class.

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:
array(), getAt(int), length(), equals(java.lang.Object), greater(java.lang.Object[], java.lang.Object[], net.sf.ivmaidns.util.GComparator)

toString

public java.lang.String toString()
Converts this vector to its string representation. The string representations of the objects (if a value is null then "null") of the encapsulated array are placed into the resulting string in the direct index order, delimited by a single space.

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:
toString(java.lang.Object[], int, int, char), getAt(int), length()

integrityCheck

public void integrityCheck()
Verifies this object for its integrity. The array component type and array elements are not checked. For debug purpose only.

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