com.judoscript.util
Class IntVector

java.lang.Object
  extended by com.judoscript.util.IntVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class IntVector
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

See Also:
Serialized Form

Field Summary
protected  int capacityIncrement
           
protected  int elementCount
           
protected  int[] elementData
           
 
Constructor Summary
IntVector()
          Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.
IntVector(int initialCapacity)
          Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero.
IntVector(int[] init)
          Constructs a vector with the provided int array with capacityIncrement set to 0.
IntVector(int[] init, int capacityIncrement)
          Constructs a vector with the provided int array.
IntVector(int initialCapacity, int capacityIncrement)
          Constructs an empty vector with the specified initial capacity and capacity increment.
 
Method Summary
 void add(int o)
          Appends the specified element to the end of this IntVector.
 void add(int index, int element)
          Inserts the specified element at the specified position in this IntVector.
 void addElement(int obj)
          Adds the specified component to the end of this vector, increasing its size by one.
 void applyIntArray(int[] a)
          Applies the supplied int array as the content for this IntVector.
 int capacity()
          Returns the current capacity of this vector.
 void clear()
          Removes all of the elements from this IntVector.
 java.lang.Object clone()
          Returns a clone of this vector.
 boolean contains(int elem)
          Tests if the specified object is a component in this vector.
 void copyInto(int[] anArray)
          Copies the components of this vector into the specified array.
 int elementAt(int index)
          Returns the component at the specified index.
 void ensureCapacity(int minCapacity)
          Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.
 boolean equals(java.lang.Object o)
          Compares the specified int with this IntVector for equality.
 int firstElement()
          Returns the first component (the item at index 0) of this vector.
 int getAt(int index)
          Returns the element at the specified position in this IntVector.
 int hashCode()
          Returns the hash code value for this IntVector.
 int indexOf(int elem)
          Searches for the first occurence of the given argument, testing for equality using the equals method.
 int indexOf(int elem, int index)
          Searches for the first occurence of the given argument, beginning the search at index, and testing for equality using the equals method.
 void insertElementAt(int obj, int index)
          Inserts the specified object as a component in this vector at the specified index.
 boolean isEmpty()
          Tests if this vector has no components.
 int lastElement()
          Returns the last component of the vector.
 int lastIndexOf(int elem)
          Returns the index of the last occurrence of the specified object in this vector.
 int lastIndexOf(int elem, int index)
          Searches backwards for the specified object, starting from the specified index, and returns an index to it.
 void removeAllElements()
          Removes all components from this vector and sets its size to zero.
 int removeAt(int index)
          Removes the element at the specified position in this IntVector.
 boolean removeElement(int obj)
          Removes the first (lowest-indexed) occurrence of the argument from this vector.
 void removeElementAt(int index)
          Deletes the component at the specified index.
protected  void removeRange(int fromIndex, int toIndex)
          Removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive.
 int set(int index, int element)
          Replaces the element at the specified position in this IntVector with the specified element.
 void setElementAt(int obj, int index)
          Sets the component at the specified index of this vector to be the specified object.
 void setSize(int newSize)
          Sets the size of this vector.
 int size()
          Returns the number of components in this vector.
 int[] toArray(int[] a)
          Returns an array containing all of the elements in this IntVector in the correct order.
 int[] toIntArray()
          Returns an array containing all of the elements in this IntVector in the correct order.
 java.lang.String toString()
          Returns a string representation of this IntVector, containing the String representation of each element.
 void trimToSize()
          Trims the capacity of this vector to be the vector's current size.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

elementData

protected int[] elementData

elementCount

protected int elementCount

capacityIncrement

protected int capacityIncrement
Constructor Detail

IntVector

public IntVector(int initialCapacity,
                 int capacityIncrement)
Constructs an empty vector with the specified initial capacity and capacity increment.

Parameters:
initialCapacity - the initial capacity of the vector.
capacityIncrement - the amount by which the capacity is increased when the vector overflows.
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative

IntVector

public IntVector(int initialCapacity)
Constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero.

Parameters:
initialCapacity - the initial capacity of the vector.
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative

IntVector

public IntVector()
Constructs an empty vector so that its internal data array has size 10 and its standard capacity increment is zero.


IntVector

public IntVector(int[] init,
                 int capacityIncrement)
Constructs a vector with the provided int array.

Parameters:
init - the initial int array
capacityIncrement - the amount by which the capacity is increased when the vector overflows.
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative

IntVector

public IntVector(int[] init)
Constructs a vector with the provided int array with capacityIncrement set to 0.

Parameters:
init - the initial int array
capacityIncrement - the amount by which the capacity is increased when the vector overflows.
Throws:
java.lang.IllegalArgumentException - if the specified initial capacity is negative
Method Detail

applyIntArray

public void applyIntArray(int[] a)
Applies the supplied int array as the content for this IntVector.


copyInto

public void copyInto(int[] anArray)
Copies the components of this vector into the specified array. The item at index k in this vector is copied into component k of anArray. The array must be big enough to hold all the objects in this vector, else an IndexOutOfBoundsException is thrown.

Parameters:
anArray - the array into which the components get copied.

trimToSize

public void trimToSize()
Trims the capacity of this vector to be the vector's current size. If the capacity of this cector is larger than its current size, then the capacity is changed to equal the size by replacing its internal data array, kept in the field elementData, with a smaller one. An application can use this operation to minimize the storage of a vector.


ensureCapacity

public void ensureCapacity(int minCapacity)
Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument.

If the current capacity of this vector is less than minCapacity, then its capacity is increased by replacing its internal data array, kept in the field elementData, with a larger one. The size of the new data array will be the old size plus capacityIncrement, unless the value of capacityIncrement is nonpositive, in which case the new capacity will be twice the old capacity; but if this new size is still smaller than minCapacity, then the new capacity will be minCapacity.

Parameters:
minCapacity - the desired minimum capacity.

setSize

public void setSize(int newSize)
Sets the size of this vector. If the new size is greater than the current size, new null items are added to the end of the vector. If the new size is less than the current size, all components at index newSize and greater are discarded.

Parameters:
newSize - the new size of this vector.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if new size is negative.

capacity

public int capacity()
Returns the current capacity of this vector.

Returns:
the current capacity (the length of its internal data arary, kept in the field elementData of this vector.

size

public int size()
Returns the number of components in this vector.

Returns:
the number of components in this vector.

isEmpty

public boolean isEmpty()
Tests if this vector has no components.

Returns:
true if and only if this vector has no components, that is, its size is zero; false otherwise.

contains

public boolean contains(int elem)
Tests if the specified object is a component in this vector.

Parameters:
elem - an object.
Returns:
true if and only if the specified object is the same as a component in this vector, as determined by the equals method; false otherwise.

indexOf

public int indexOf(int elem)
Searches for the first occurence of the given argument, testing for equality using the equals method.

Parameters:
elem - an object.
Returns:
the index of the first occurrence of the argument in this vector, that is, the smallest value k such that elem.equals(elementData[k]) is true; returns -1 if the object is not found.
See Also:
int#equals(int)

indexOf

public int indexOf(int elem,
                   int index)
Searches for the first occurence of the given argument, beginning the search at index, and testing for equality using the equals method.

Parameters:
elem - an object.
index - the index to start searching from.
Returns:
the index of the first occurrence of the object argument in this vector at position index or later in the vector, that is, the smallest value k such that elem.equals(elementData[k]) && (k >= index) is true; returns -1 if the object is not found.
See Also:
int#equals(int)

lastIndexOf

public int lastIndexOf(int elem)
Returns the index of the last occurrence of the specified object in this vector.

Parameters:
elem - the desired component.
Returns:
the index of the last occurrence of the specified object in this vector, that is, the largest value k such that elem.equals(elementData[k]) is true; returns -1 if the object is not found.

lastIndexOf

public int lastIndexOf(int elem,
                       int index)
Searches backwards for the specified object, starting from the specified index, and returns an index to it.

Parameters:
elem - the desired component.
index - the index to start searching from.
Returns:
the index of the last occurrence of the specified object in this vector at position less than index in the vector, that is, the largest value k such that elem.equals(elementData[k]) && (k <= index) is true; -1 if the object is not found.

elementAt

public int elementAt(int index)
Returns the component at the specified index.

This method is identical in functionality to the get method (which is part of the List interface).

Parameters:
index - an index into this vector.
Returns:
the component at the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index is negative or not less than the current size of this IntVector object. given.
See Also:
#get(int), List

firstElement

public int firstElement()
Returns the first component (the item at index 0) of this vector.

Returns:
the first component of this vector.
Throws:
java.util.NoSuchElementException - if this vector has no components.

lastElement

public int lastElement()
Returns the last component of the vector.

Returns:
the last component of the vector, i.e., the component at index size() - 1.
Throws:
java.util.NoSuchElementException - if this vector is empty.

setElementAt

public void setElementAt(int obj,
                         int index)
Sets the component at the specified index of this vector to be the specified object. The previous component at that position is discarded.

The index must be a value greater than or equal to 0 and less than the current size of the vector.

This method is identical in functionality to the set method (which is part of the List interface). Note that the set method reverses the order of the parameters, to more closely match array usage. Note also that the set method returns the old value that was stored at the specified position.

Parameters:
obj - what the component is to be set to.
index - the specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
See Also:
size(), List, #set(int, java.lang.int)

removeElementAt

public void removeElementAt(int index)
Deletes the component at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted downward to have an index one smaller than the value it had previously. The size of this vector is decreased by 1.

The index must be a value greater than or equal to 0 and less than the current size of the vector.

This method is identical in functionality to the remove method (which is part of the List interface). Note that the remove method returns the old value that was stored at the specified position.

Parameters:
index - the index of the object to remove.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
See Also:
size(), #remove(int), List

insertElementAt

public void insertElementAt(int obj,
                            int index)
Inserts the specified object as a component in this vector at the specified index. Each component in this vector with an index greater or equal to the specified index is shifted upward to have an index one greater than the value it had previously.

The index must be a value greater than or equal to 0 and less than or equal to the current size of the vector. (If the index is equal to the current size of the vector, the new element is appended to the IntVector.)

This method is identical in functionality to the add(int, int) method (which is part of the List interface). Note that the add method reverses the order of the parameters, to more closely match array usage.

Parameters:
obj - the component to insert.
index - where to insert the new component.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.
See Also:
size(), add(int, int), List

addElement

public void addElement(int obj)
Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity.

This method is identical in functionality to the add(int) method (which is part of the List interface).

Parameters:
obj - the component to be added.
See Also:
add(int), List

removeElement

public boolean removeElement(int obj)
Removes the first (lowest-indexed) occurrence of the argument from this vector. If the object is found in this vector, each component in the vector with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously.

This method is identical in functionality to the remove(int) method (which is part of the List interface).

Parameters:
obj - the component to be removed.
Returns:
true if the argument was a component of this vector; false otherwise.
See Also:
List.remove(int), List

removeAllElements

public void removeAllElements()
Removes all components from this vector and sets its size to zero.

This method is identical in functionality to the clear method (which is part of the List interface).

See Also:
clear(), List

clone

public java.lang.Object clone()
Returns a clone of this vector. The copy will contain a reference to a clone of the internal data array, not a reference to the original internal data array of this IntVector object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this vector.

toIntArray

public int[] toIntArray()
Returns an array containing all of the elements in this IntVector in the correct order.


toArray

public int[] toArray(int[] a)
Returns an array containing all of the elements in this IntVector in the correct order. The runtime type of the returned array is that of the specified array. If the IntVector fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this IntVector.

If the IntVector fits in the specified array with room to spare (i.e., the array has more elements than the IntVector), the element in the array immediately following the end of the IntVector is set to null. This is useful in determining the length of the IntVector only if the caller knows that the IntVector does not contain any null elements.

Parameters:
a - the array into which the elements of the IntVector are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
Returns:
an array containing the elements of the IntVector.
Throws:
java.lang.ArrayStoreException - the runtime type of a is not a supertype of the runtime type of every element in this IntVector.

getAt

public int getAt(int index)
Returns the element at the specified position in this IntVector.

Parameters:
index - index of element to return.
Throws:
java.lang.ArrayIndexOutOfBoundsException - index is out of range (index < 0 || index >= size()).

set

public int set(int index,
               int element)
Replaces the element at the specified position in this IntVector with the specified element.

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
java.lang.ArrayIndexOutOfBoundsException - index out of range (index < 0 || index >= size()).
java.lang.IllegalArgumentException - fromIndex > toIndex.

add

public void add(int o)
Appends the specified element to the end of this IntVector.

Parameters:
o - element to be appended to this IntVector.

add

public void add(int index,
                int element)
Inserts the specified element at the specified position in this IntVector. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.
Throws:
java.lang.ArrayIndexOutOfBoundsException - index is out of range (index < 0 || index > size()).

removeAt

public int removeAt(int index)
Removes the element at the specified position in this IntVector. shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the IntVector.

Parameters:
index - the index of the element to removed.
Throws:
java.lang.ArrayIndexOutOfBoundsException - index out of range (index < 0 || index >= size()).

clear

public void clear()
Removes all of the elements from this IntVector. The IntVector will be empty after this call returns (unless it throws an exception).


equals

public boolean equals(java.lang.Object o)
Compares the specified int with this IntVector for equality. Returns true if and only if the specified int is also a List, both Lists have the same size, and all corresponding pairs of elements in the two Lists are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two Lists are defined to be equal if they contain the same elements in the same order.

Overrides:
equals in class java.lang.Object
Parameters:
o - the int to be compared for equality with this IntVector.
Returns:
true if the specified int is equal to this IntVector

hashCode

public int hashCode()
Returns the hash code value for this IntVector.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns a string representation of this IntVector, containing the String representation of each element.

Overrides:
toString in class java.lang.Object

removeRange

protected void removeRange(int fromIndex,
                           int toIndex)
Removes from this List all of the elements whose index is between fromIndex, inclusive and toIndex, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the ArrayList by (toIndex - fromIndex) elements. (If toIndex==fromIndex, this operation has no effect.)

Parameters:
fromIndex - index of first element to be removed.
fromIndex - index after last element to be removed.