scale.common
Class Vector<T>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<T>
              extended by scale.common.Vector<T>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, java.util.RandomAccess
Direct Known Subclasses:
Stack

public class Vector<T>
extends java.util.ArrayList<T>
implements java.lang.Cloneable

Implement our own Vector class that is un-synchronized and allows us to collect statictics on the number of Vectors in use.

$Id: Vector.java,v 1.19 2007-10-04 19:58:11 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
Vector()
          Constructs an empty vector.
Vector(java.util.Collection<T> set)
          Constructs an empty vector.
Vector(int initialCapacity)
          Constructs an empty vector with the specified initial capacity.
Vector(int initialCapacity, int dummy)
          Constructs an empty vector with the specified initial capacity.
 
Method Summary
 void addElement(T element)
          Add the element to the end of the vector.
 void addVectors(java.util.Enumeration<T> e)
          Add the elements of an enumeration to this Vector.
 void addVectors(T[] c)
          Add the elements of an array to this Vector.
 void addVectors(Vector<T> c)
          Add the elements of a Vector to this vector.
 Vector<T> clone()
          Returns a clone of this vector.
 T elementAt(int i)
          Return the specified element.
 java.util.Enumeration<T> elements()
          Returns an enumeration of the components of this vector.
 T firstElement()
          Returns the first component (the item at index 0) of this vector.
 void insertElementAt(T element, int i)
          Inserts the specified object as a component in this vector at the specified index.
 T lastElement()
          Returns the last component of the vector.
 void removeAllElements()
          Removes all components from this vector and sets its size to zero.
 boolean removeElement(java.lang.Object element)
          Removes the first (lowest-indexed) occurrence of the argument from this vector.
 T removeElementAt(int i)
          Deletes the component at the specified index.
 void reverse()
          Revrese the order of the elements in the Vector.
 void setElementAt(T element, int i)
          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.
 
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, set, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
containsAll, removeAll, retainAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList
 

Constructor Detail

Vector

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

Parameters:
initialCapacity - the initial capacity of the vector.

Vector

public Vector(int initialCapacity,
              int dummy)
Constructs an empty vector with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the vector.

Vector

public Vector()
Constructs an empty vector.


Vector

public Vector(java.util.Collection<T> set)
Constructs an empty vector.

Method Detail

clone

public Vector<T> clone()
Returns a clone of this vector.

Overrides:
clone in class java.util.ArrayList<T>

setSize

public final 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.


elementAt

public final T elementAt(int i)
Return the specified element.


addElement

public final void addElement(T element)
Add the element to the end of the vector.


insertElementAt

public final void insertElementAt(T element,
                                  int i)
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.


setElementAt

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


removeElementAt

public final T removeElementAt(int i)
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.

Returns:
the deleted component.

removeAllElements

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


removeElement

public final boolean removeElement(java.lang.Object element)
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.

Returns:
true if the eelement was removed

firstElement

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


lastElement

public final T lastElement()
Returns the last component of the vector.


elements

public final java.util.Enumeration<T> elements()
Returns an enumeration of the components of this vector. The returned enumeration object will generate all items in this vector. The first item generated is the item at index 0, then the item at index 1, and so on.


addVectors

public final void addVectors(T[] c)
Add the elements of an array to this Vector.


addVectors

public final void addVectors(Vector<T> c)
Add the elements of a Vector to this vector.


addVectors

public final void addVectors(java.util.Enumeration<T> e)
Add the elements of an enumeration to this Vector.


reverse

public final void reverse()
Revrese the order of the elements in the Vector.