FileDocCategorySizeDatePackage
Vector.javaAPI DocGlassfish v2 API3241Wed Aug 30 15:34:16 BST 2006persistence.antlr.collections.impl

Vector

public class Vector extends Object implements Cloneable

Fields Summary
protected Object[]
data
protected int
lastElement
Constructors Summary
public Vector()


      
        this(10);
    
public Vector(int size)

        data = new Object[size];
    
Methods Summary
public synchronized voidappendElement(java.lang.Object o)

        ensureCapacity(lastElement + 2);
        data[++lastElement] = o;
    
public intcapacity()
Returns the current capacity of the vector.

        return data.length;
    
public java.lang.Objectclone()

        Vector v = null;
        try {
            v = (Vector)super.clone();
        }
        catch (CloneNotSupportedException e) {
            System.err.println("cannot clone Vector.super");
            return null;
        }
        v.data = new Object[size()];
        System.arraycopy(data, 0, v.data, 0, size());
        return v;
    
public synchronized java.lang.ObjectelementAt(int i)
Returns the element at the specified index.

param
index the index of the desired element
exception
ArrayIndexOutOfBoundsException If an invalid index was given.

        if (i >= data.length) {
            throw new ArrayIndexOutOfBoundsException(i + " >= " + data.length);
        }
        if (i < 0) {
            throw new ArrayIndexOutOfBoundsException(i + " < 0 ");
        }
        return data[i];
    
public synchronized java.util.Enumerationelements()

        return new VectorEnumerator(this);
    
public synchronized voidensureCapacity(int minIndex)

        if (minIndex + 1 > data.length) {
            Object oldData[] = data;
            int n = data.length * 2;
            if (minIndex + 1 > n) {
                n = minIndex + 1;
            }
            data = new Object[n];
            System.arraycopy(oldData, 0, data, 0, oldData.length);
        }
    
public synchronized booleanremoveElement(java.lang.Object o)

        // find element
        int i;
        for (i = 0; i <= lastElement && data[i] != o; i++) {
            ;
        }
        if (i <= lastElement) { // if found it
            data[i] = null;		// kill ref for GC
            int above = lastElement - i;
            if (above > 0) {
                System.arraycopy(data, i + 1, data, i, above);
            }
            lastElement--;
            return true;
        }
        else {
            return false;
        }
    
public synchronized voidsetElementAt(java.lang.Object obj, int i)

        if (i >= data.length) {
            throw new ArrayIndexOutOfBoundsException(i + " >= " + data.length);
        }
        data[i] = obj;
        // track last element in the vector so we can append things
        if (i > lastElement) {
            lastElement = i;
        }
    
public intsize()

        return lastElement + 1;