jds.collection
Class Vector

java.lang.Object
  |
  +--jds.collection.Vector

public class Vector
extends java.lang.Object
implements Indexed, Stack

Vector - an indexed collection; for use with book Classic Data Structures in Java by Timothy A Budd, published by Addison-Wesley, 2001.

See Also:
Collection, Serialized Form

Constructor Summary
Vector()
           
 
Method Summary
 void addElementAt(java.lang.Object val, int index)
          add a new element into the collection, making collection one element larger
 void addLast(java.lang.Object val)
          add a new value to end of the collection
 java.lang.Object elementAt(int index)
          find value at specific index location
 java.util.Enumeration elements()
          Yields enumerator for collection
 void ensureCapacity(int newCapacity)
          ensure buffer has sufficient number of elements
 java.lang.Object getLast()
          access the last value in collection
 boolean isEmpty()
          Determines whether the collection is empty
 void removeElementAt(int index)
          remove a value from a collection, making collection one element smaller
 void removeLast()
          remove last value in collection
 void setElementAt(java.lang.Object v, int index)
          set value at specific location
 void setSize(int newSize)
          set number of elements in collection
 int size()
          Determines number of elements in collection
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Vector

public Vector()
Method Detail

isEmpty

public boolean isEmpty()
Determines whether the collection is empty
Returns:
true if the collection is empty

size

public int size()
Determines number of elements in collection
Returns:
number of elements in collection as integer

elements

public java.util.Enumeration elements()
Yields enumerator for collection
Returns:
an Enumeration that will yield the elements of the collection
See Also:
Enumeration

setSize

public void setSize(int newSize)
set number of elements in collection
Specified by:
setSize in interface Indexed
Parameters:
size - the new size of the collection

elementAt

public java.lang.Object elementAt(int index)
find value at specific index location
Specified by:
elementAt in interface Indexed
Parameters:
index - the index of the desired value
Returns:
the desired value
Throws:
java.lang.ArrayIndexOutOfBoundsException - array index is illegal

setElementAt

public void setElementAt(java.lang.Object v,
                         int index)
set value at specific location
Specified by:
setElementAt in interface Indexed
Parameters:
v - the value to be inserted
index - the position at which value will be inserted
Throws:
java.lang.ArrayIndexOutOfBoundsException - array index is illegal

addElementAt

public void addElementAt(java.lang.Object val,
                         int index)
add a new element into the collection, making collection one element larger
Specified by:
addElementAt in interface Indexed
Parameters:
val - the value to be inserted
index - the position at which value will be inserted, other elements will be moved upwards

removeElementAt

public void removeElementAt(int index)
remove a value from a collection, making collection one element smaller
Specified by:
removeElementAt in interface Indexed
Parameters:
index - the index of the element to be removed
Throws:
java.util.NoSuchElementException - array index is illegal

addLast

public void addLast(java.lang.Object val)
add a new value to end of the collection
Specified by:
addLast in interface Stack
Parameters:
value - element to be inserted into collection

getLast

public java.lang.Object getLast()
access the last value in collection
Specified by:
getLast in interface Stack
Returns:
element at top of collection
Throws:
java.lang.ArrayIndexOutOfBoundsException - no matching value

removeLast

public void removeLast()
remove last value in collection
Specified by:
removeLast in interface Stack
Throws:
java.lang.ArrayIndexOutOfBoundsException - no matching value

ensureCapacity

public void ensureCapacity(int newCapacity)
ensure buffer has sufficient number of elements
Parameters:
newCapacity - capacity of collection after operation