Methods Summary |
---|
public synchronized void | addElement(java.lang.Object 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.
int newcount = elementCount + 1;
if (newcount > elementData.length) {
ensureCapacityHelper(newcount);
}
elementData[elementCount++] = obj;
|
public int | capacity()Returns the current capacity of this vector.
return elementData.length;
|
public boolean | contains(java.lang.Object elem)Tests if the specified object is a component in this vector.
return indexOf(elem, 0) >= 0;
|
public synchronized void | copyInto(java.lang.Object[] anArray)Copies the components of this vector into the specified array.
The array must be big enough to hold all the objects in this vector.
int i = elementCount;
while (i-- > 0) {
anArray[i] = elementData[i];
}
|
public synchronized java.lang.Object | elementAt(int index)Returns the component at the specified index.
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(
/* #ifdef VERBOSE_EXCEPTIONS */
/// skipped index + " >= " + elementCount
/* #endif */
);
}
return elementData[index];
|
public synchronized java.util.Enumeration | elements()Returns an enumeration of the components of this vector.
return new VectorEnumerator(this);
|
public synchronized 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 (minCapacity > elementData.length) {
ensureCapacityHelper(minCapacity);
}
|
private void | ensureCapacityHelper(int minCapacity)This implements the unsynchronized semantics of ensureCapacity.
Synchronized methods in this class can internally call this
method for ensuring capacity without incurring the cost of an
extra synchronization.
int oldCapacity = elementData.length;
Object oldData[] = elementData;
int newCapacity = (capacityIncrement > 0) ?
(oldCapacity + capacityIncrement) : (oldCapacity * 2);
if (newCapacity < minCapacity) {
newCapacity = minCapacity;
}
elementData = new Object[newCapacity];
JVM.unchecked_obj_arraycopy(oldData, 0,
elementData, 0, elementCount);
|
public synchronized java.lang.Object | firstElement()Returns the first component of this vector.
if (elementCount == 0) {
throw new NoSuchElementException();
}
return elementData[0];
|
public int | indexOf(java.lang.Object elem)Searches for the first occurrence of the given argument, testing
for equality using the equals method.
return indexOf(elem, 0);
|
public synchronized int | indexOf(java.lang.Object elem, int index)Searches for the first occurrence of the given argument, beginning
the search at index , and testing for equality using
the equals method.
if (elem == null) {
for (int i = index ; i < elementCount ; i++)
if (elementData[i]==null)
return i;
} else {
for (int i = index ; i < elementCount ; i++)
if (elem.equals(elementData[i]))
return i;
}
return -1;
|
public synchronized void | insertElementAt(java.lang.Object 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.
int newcount = elementCount + 1;
if (index < 0 || index >= newcount) {
throw new ArrayIndexOutOfBoundsException(
/* #ifdef VERBOSE_EXCEPTIONS */
/// skipped index + " > " + elementCount
/* #endif */
);
}
if (newcount > elementData.length) {
ensureCapacityHelper(newcount);
}
JVM.unchecked_obj_arraycopy(elementData, index,
elementData, index + 1,
elementCount - index);
elementData[index] = obj;
elementCount++;
|
public boolean | isEmpty()Tests if this vector has no components.
return elementCount == 0;
|
public synchronized java.lang.Object | lastElement()Returns the last component of the vector.
if (elementCount == 0) {
throw new NoSuchElementException();
}
return elementData[elementCount - 1];
|
public int | lastIndexOf(java.lang.Object elem)Returns the index of the last occurrence of the specified object in
this vector.
return lastIndexOf(elem, elementCount-1);
|
public synchronized int | lastIndexOf(java.lang.Object elem, int index)Searches backwards for the specified object, starting from the
specified index, and returns an index to it.
if (index >= elementCount) {
throw new IndexOutOfBoundsException(
/* #ifdef VERBOSE_EXCEPTIONS */
/// skipped index + " >= " + elementCount
/* #endif */
);
}
if (elem == null) {
for (int i = index; i >= 0; i--)
if (elementData[i]==null)
return i;
} else {
for (int i = index; i >= 0; i--)
if (elem.equals(elementData[i]))
return i;
}
return -1;
|
public synchronized void | removeAllElements()Removes all components from this vector and sets its size to zero.
for (int i = 0; i < elementCount; i++) {
elementData[i] = null;
}
elementCount = 0;
|
public synchronized boolean | removeElement(java.lang.Object obj)Removes the first 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.
int i = indexOf(obj);
if (i >= 0) {
removeElementAt(i);
return true;
}
return false;
|
public synchronized 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 index must be a value greater than or equal to 0
and less than the current size of the vector.
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(
/* #ifdef VERBOSE_EXCEPTIONS */
/// skipped index + " >= " +
/// skipped elementCount
/* #endif */
);
}
else if (index < 0) {
throw new ArrayIndexOutOfBoundsException(
/* #ifdef VERBOSE_EXCEPTIONS */
/// skipped index
/* #endif */
);
}
int j = elementCount - index - 1;
if (j > 0) {
JVM.unchecked_obj_arraycopy(elementData, index + 1,
elementData, index, j);
}
elementCount--;
elementData[elementCount] = null; /* to let gc do its work */
|
public synchronized void | setElementAt(java.lang.Object 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.
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(
/* #ifdef VERBOSE_EXCEPTIONS */
/// skipped index + " >= " +
/// skipped elementCount
/* #endif */
);
}
elementData[index] = obj;
|
public synchronized 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.
if ((newSize > elementCount) && (newSize > elementData.length)) {
ensureCapacityHelper(newSize);
} else {
for (int i = newSize ; i < elementCount ; i++) {
elementData[i] = null;
}
}
elementCount = newSize;
|
public int | size()Returns the number of components in this vector.
return elementCount;
|
public synchronized java.lang.String | toString()Returns a string representation of this vector.
int max = size() - 1;
StringBuffer buf = new StringBuffer();
Enumeration e = elements();
buf.append("[");
for (int i = 0 ; i <= max ; i++) {
buf.append(e.nextElement());
if (i < max) {
buf.append(", ");
}
}
buf.append("]");
return buf.toString();
|
public synchronized void | trimToSize()Trims the capacity of this vector to be the vector's current
size. An application can use this operation to minimize the
storage of a vector.
int oldCapacity = elementData.length;
if (elementCount < oldCapacity) {
Object oldData[] = elementData;
elementData = new Object[elementCount];
JVM.unchecked_obj_arraycopy(oldData, 0,
elementData, 0, elementCount);
}
|