|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.judoscript.util.IntVector
public class IntVector
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 |
---|
protected int[] elementData
protected int elementCount
protected int capacityIncrement
Constructor Detail |
---|
public IntVector(int initialCapacity, int capacityIncrement)
initialCapacity
- the initial capacity of the vector.capacityIncrement
- the amount by which the capacity is
increased when the vector overflows.
java.lang.IllegalArgumentException
- if the specified initial capacity
is negativepublic IntVector(int initialCapacity)
initialCapacity
- the initial capacity of the vector.
java.lang.IllegalArgumentException
- if the specified initial capacity
is negativepublic IntVector()
public IntVector(int[] init, int capacityIncrement)
init
- the initial int arraycapacityIncrement
- the amount by which the capacity is
increased when the vector overflows.
java.lang.IllegalArgumentException
- if the specified initial capacity
is negativepublic IntVector(int[] init)
init
- the initial int arraycapacityIncrement
- the amount by which the capacity is
increased when the vector overflows.
java.lang.IllegalArgumentException
- if the specified initial capacity
is negativeMethod Detail |
---|
public void applyIntArray(int[] a)
public void copyInto(int[] anArray)
anArray
- the array into which the components get copied.public void trimToSize()
public void ensureCapacity(int minCapacity)
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.
minCapacity
- the desired minimum capacity.public void setSize(int newSize)
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.
newSize
- the new size of this vector.
java.lang.ArrayIndexOutOfBoundsException
- if new size is negative.public int capacity()
public int size()
public boolean isEmpty()
true
if and only if this vector has
no components, that is, its size is zero;
false
otherwise.public boolean contains(int elem)
elem
- an object.
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.public int indexOf(int elem)
equals
method.
elem
- an object.
-1
if the object is not found.int#equals(int)
public int indexOf(int elem, int index)
index
, and testing for equality using
the equals
method.
elem
- an object.index
- the index to start searching from.
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.int#equals(int)
public int lastIndexOf(int elem)
elem
- the desired component.
-1
if the object is not found.public int lastIndexOf(int elem, int index)
elem
- the desired component.index
- the index to start searching from.
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.public int elementAt(int index)
This method is identical in functionality to the get method (which is part of the List interface).
index
- an index into this vector.
java.lang.ArrayIndexOutOfBoundsException
- if the index
is negative or not less than the current size of this
IntVector object.
given.#get(int)
,
List
public int firstElement()
java.util.NoSuchElementException
- if this vector has no components.public int lastElement()
size() - 1
.
java.util.NoSuchElementException
- if this vector is empty.public void setElementAt(int obj, int index)
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.
obj
- what the component is to be set to.index
- the specified index.
java.lang.ArrayIndexOutOfBoundsException
- if the index was invalid.size()
,
List
,
#set(int, java.lang.int)
public void removeElementAt(int index)
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.
index
- the index of the object to remove.
java.lang.ArrayIndexOutOfBoundsException
- if the index was invalid.size()
,
#remove(int)
,
List
public void insertElementAt(int obj, int index)
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.
obj
- the component to insert.index
- where to insert the new component.
java.lang.ArrayIndexOutOfBoundsException
- if the index was invalid.size()
,
add(int, int)
,
List
public void addElement(int obj)
This method is identical in functionality to the add(int) method (which is part of the List interface).
obj
- the component to be added.add(int)
,
List
public boolean removeElement(int obj)
This method is identical in functionality to the remove(int) method (which is part of the List interface).
obj
- the component to be removed.
true
if the argument was a component of this
vector; false
otherwise.List.remove(int)
,
List
public void removeAllElements()
This method is identical in functionality to the clear method (which is part of the List interface).
clear()
,
List
public java.lang.Object clone()
clone
in class java.lang.Object
public int[] toIntArray()
public int[] toArray(int[] a)
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.
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.
java.lang.ArrayStoreException
- the runtime type of a is not a supertype
of the runtime type of every element in this IntVector.public int getAt(int index)
index
- index of element to return.
java.lang.ArrayIndexOutOfBoundsException
- index is out of range (index
< 0 || index >= size()).public int set(int index, int element)
index
- index of element to replace.element
- element to be stored at the specified position.
java.lang.ArrayIndexOutOfBoundsException
- index out of range
(index < 0 || index >= size()).
java.lang.IllegalArgumentException
- fromIndex > toIndex.public void add(int o)
o
- element to be appended to this IntVector.public void add(int index, int element)
index
- index at which the specified element is to be inserted.element
- element to be inserted.
java.lang.ArrayIndexOutOfBoundsException
- index is out of range
(index < 0 || index > size()).public int removeAt(int index)
index
- the index of the element to removed.
java.lang.ArrayIndexOutOfBoundsException
- index out of range (index
< 0 || index >= size()).public void clear()
public boolean equals(java.lang.Object o)
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.
equals
in class java.lang.Object
o
- the int to be compared for equality with this IntVector.
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
protected void removeRange(int fromIndex, int toIndex)
fromIndex
- index of first element to be removed.fromIndex
- index after last element to be removed.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |