[all packages] [package gj.util] [class hierarchy] [index]

public class gj.util.Vector<A>

(source file: util/Vector.java)
java.lang.Object
   |
   +----gj.util.Vector<A>

The pure class interface.
public class Vector<A>
  implements java.io.Serializable, Cloneable
Vector class (a growable array).

Each vector tries to optimize storage management by maintaining a capacity and a capacityIncrement. The capacity is always at least as large as the vector size; it is usually larger because as elements are added to the vector, the vector's storage increases in chunks the size of capacityIncrement. Setting the capacity to what you want before inserting a large number of objects will reduce the amount of incremental reallocation. You can safely ignore the capacity and the vector will still work correctly.


Constuctor Index

O Vector()
Constructs an empty vector.
O Vector(int)
Constructs an empty vector with the specified storage capacity.
O Vector(int, int)
Constructs an empty vector with the specified storage capacity and the specified

Variables Index

O capacityIncrement
The size of the increment
O elementCount
The number of elements in the buffer.
O elementData
The buffer where elements are stored.

Methods

O addElement(A)
Adds the specified object as the last element of the vector.
O capacity()
Returns the current capacity of the vector.
O clone()
Clones this vector
O contains(A)
Returns true if the specified object is a value of the collection.
O copyInto(A[])
Copies the elements of this vector into the specified array.
O elementAt(int)
Returns the element at the specified index.
O elements()
Returns an enumeration of the elements
O ensureCapacity(int)
Ensures that the vector has at least the specified capacity.
O firstElement()
Returns the first element of the sequence.
O indexOf(A, int)
Searches for the specified object, starting at the specified position and returns an index
O indexOf(A)
Searches for the specified object, starting from the first position and returns an index to
O insertElementAt(A, int)
Inserts the specified object as an element at the specified index. Elements with an index
O isEmpty()
Returns true if the collection contains no values.
O lastElement()
Returns the last element of the sequence.
O lastIndexOf(A, int)
Searches backwards for the specified object, starting from the specified position and
O lastIndexOf(A)
Searches backwards for the specified object, starting from the last position and returns an
O removeAllElements()
Removes all elements of the vector
O removeElement(A)
Removes the element from the vector
O removeElementAt(int)
Deletes the element at the specified index
O setElementAt(A, int)
Sets the element at the specified index to be the specified object. The previous element at
O setSize(int)
Sets the size of the vector
O size()
Returns the number of elements in the vector. Note that this is not the same as the
O toString()
Converts the vector to a string
O trimToSize()
Trims the vector's capacity down to size

Constructors

O Vector
public Vector(int initialCapacity,
              int capacityIncrement);
Constructs an empty vector with the specified storage capacity and the specified capacityIncrement.

Parameters:
initialCapacity - the initial storage capacity of the vector
capacityIncrement - how much to increase the element's size by.

O Vector

public Vector(int initialCapacity);
Constructs an empty vector with the specified storage capacity.

Parameters:
initialCapacity - the initial storage capacity of the vector

O Vector

public Vector();
Constructs an empty vector.

Variables

O elementData
protected A[] elementData;
The buffer where elements are stored.

O elementCount

protected int elementCount;
The number of elements in the buffer.

O capacityIncrement

protected int capacityIncrement;
The size of the increment. If it is 0 the size of the the buffer is doubled everytime it needs to grow.

Methods

O copyInto
public final synchronized void copyInto(A[] anArray);
Copies the elements of this vector into the specified array.

Parameters:
anArray - the array where elements get copied into

O trimToSize

public final synchronized void trimToSize();
Trims the vector's capacity down to size. Use this operation to minimize the storage of a vector. Subsequent insertions will cause reallocation.

O ensureCapacity

public final synchronized void ensureCapacity(int minCapacity);
Ensures that the vector has at least the specified capacity.

Parameters:
minCapacity - the desired minimum capacity

O setSize

public final synchronized void setSize(int newSize);
Sets the size of the vector. If the size shrinks, the extra elements (at the end of the vector) are lost; if the size increases, the new elements are set to null.

Parameters:
newSize - the new size of the vector

O capacity

public final int capacity();
Returns the current capacity of the vector.

O size

public final int size();
Returns the number of elements in the vector. Note that this is not the same as the vector's capacity.

O isEmpty

public final boolean isEmpty();
Returns true if the collection contains no values.

O elements

public final synchronized Enumeration<A> elements();
Returns an enumeration of the elements. Use the Enumeration methods on the returned object to fetch the elements sequentially.

O contains

public final boolean contains(A elem);
Returns true if the specified object is a value of the collection.

Parameters:
elem - the desired element

O indexOf

public final int indexOf(A elem);
Searches for the specified object, starting from the first position and returns an index to it.

Parameters:
elem - the desired element
Returns:
the index of the element, or -1 if it was not found.

O indexOf

public final synchronized int indexOf(A elem,
                                      int index);
Searches for the specified object, starting at the specified position and returns an index to it.

Parameters:
elem - the desired element
index - the index where to start searching
Returns:
the index of the element, or -1 if it was not found.

O lastIndexOf

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

Parameters:
elem - the desired element
Returns:
the index of the element, or -1 if it was not found.

O lastIndexOf

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

Parameters:
elem - the desired element
index - the index where to start searching
Returns:
the index of the element, or -1 if it was not found.

O elementAt

public final synchronized A elementAt(int index);
Returns the element at the specified index.

Parameters:
index - the index of the desired element
Throws:
ArrayIndexOutOfBoundsException -If an invalid index was given.

O firstElement

public final synchronized A firstElement();
Returns the first element of the sequence.

Throws:
NoSuchElementException -If the sequence is empty.

O lastElement

public final synchronized A lastElement();
Returns the last element of the sequence.

Throws:
NoSuchElementException -If the sequence is empty.

O setElementAt

public final synchronized void setElementAt(A obj,
                                            int index);
Sets the element at the specified index to be the specified object. The previous element at that position is discarded.

Parameters:
obj - what the element is to be set to
index - the specified index
Throws:
ArrayIndexOutOfBoundsException -If the index was invalid.

O removeElementAt

public final synchronized void removeElementAt(int index);
Deletes the element at the specified index. Elements with an index greater than the current index are moved down.

Parameters:
index - the element to remove
Throws:
ArrayIndexOutOfBoundsException -If the index was invalid.

O insertElementAt

public final synchronized void insertElementAt(A obj,
                                               int index);
Inserts the specified object as an element at the specified index. Elements with an index greater or equal to the current index are shifted up.

Parameters:
obj - the element to insert
index - where to insert the new element
Throws:
ArrayIndexOutOfBoundsException -If the index was invalid.

O addElement

public final synchronized void addElement(A obj);
Adds the specified object as the last element of the vector.

Parameters:
obj - the element to be added

O removeElement

public final synchronized boolean removeElement(A obj);
Removes the element from the vector. If the object occurs more than once, only the first is removed. If the object is not an element, returns false.

Parameters:
obj - the element to be removed
Returns:
true if the element was actually removed; false otherwise.

O removeAllElements

public final synchronized void removeAllElements();
Removes all elements of the vector. The vector becomes empty.

O clone

public synchronized Object clone();
Clones this vector. The elements are not cloned.

Overrides:
clone in class Object

O toString

public final synchronized String toString();
Converts the vector to a string. Useful for debugging.

Overrides:
toString in class Object


[all packages] [package gj.util] [class hierarchy] [index]
gj.util.Vector.html