waba.util
Class Vector

java.lang.Object
  |
  +--waba.util.Vector

public final class Vector
extends Object

A vector is an array of object references. The vector grows and shrinks dynamically as objects are added and removed.

Here is an example showing a vector being used:

 ...
 Vector vec = new Vector();
 vec.add(obj1);
 vec.add(obj2);
 ...
 vec.insert(3, obj3);
 vec.del(2);
 if (vec.getCount() > 5)
 ...
 


Field Summary
 Object[] items
          This member is public for fast access.
 
Constructor Summary
Vector()
          Constructs an empty vector.
Vector(int size)
          Constructs an empty vector with a given initial size.
Vector(Object[] startingWith)
          Constructs a vector starting with the given elements.
 
Method Summary
 void add(Object obj)
          Adds an object to the end of the vector.
 void addElement(Object obj)
          same of add(Object)
 void clear()
          clears all elements in this vector and sets its length to 0
 void del(int index)
          Deletes the object reference at the given index.
 boolean del(Object obj)
          Deletes the object
 Object elementAt(int index)
          same of get(index)
 int find(Object obj)
          Finds the index of the given object.
 int find(Object obj, int startIndex)
          Finds the index of the given object.
 Object get(int index)
          Returns the object at the given index.
 int getCount()
          Returns the number of objects in the vector.
 int indexOf(Object elem)
          same of find(Object)
 int indexOf(Object elem, int index)
          same of find(Object, index)
 void insert(int index, Object obj)
          Inserts an object at the given index.
 void insertElementAt(Object obj, int index)
          same of insert(index, Object)
 Object peek()
          returns the last object, without removing it. returns null if no more elements.
 Object pop()
          returns the last object, removing it. returns null if no more elements.
 void push(Object obj)
          pushes a object. simply calls add.
 boolean qsort()
          Sorts the elements of this Vector.
 void removeAllElements()
          same of clear()
 boolean removeElement(Object obj)
          same of del(Object)
 void removeElementAt(int index)
          same of del(index)
 void set(int index, Object obj)
          Sets the object at the given index.
 void setElementAt(Object obj, int index)
          same of set(index, Object)
 int size()
          same of getCount()
 Object[] toObjectArray()
          Converts the vector to an array of objects.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, toString, wait, wait
 

Field Detail

items

public Object[] items
This member is public for fast access. Always use the correct methods for add and remove, otherwise you'll be in trouble.
Constructor Detail

Vector

public Vector()
Constructs an empty vector.

Vector

public Vector(int size)
Constructs an empty vector with a given initial size. The size is the initial size of the vector's internal object array. The vector will grow as needed when objects are added. SIZE CANNOT BE 0!

Vector

public Vector(Object[] startingWith)
Constructs a vector starting with the given elements. The vector can grow after this
Method Detail

add

public void add(Object obj)
Adds an object to the end of the vector.

insert

public void insert(int index,
                   Object obj)
Inserts an object at the given index.

del

public void del(int index)
Deletes the object reference at the given index.

del

public boolean del(Object obj)
Deletes the object

get

public Object get(int index)
Returns the object at the given index.

set

public void set(int index,
                Object obj)
Sets the object at the given index.

find

public int find(Object obj)
Finds the index of the given object. The list is searched using a O(n) linear search through all the objects in the vector.

find

public int find(Object obj,
                int startIndex)
Finds the index of the given object. The list is searched using a O(n) linear search starting in startIndex up through all the objects in the vector.

getCount

public int getCount()
Returns the number of objects in the vector.

toObjectArray

public Object[] toObjectArray()
Converts the vector to an array of objects. Because of a bug in the SuperWaba VM about zero-sized arrays, if there are no elements in this vector, returns null. Note that if the elements are Strings, you can cast the result to a String[] array.

push

public void push(Object obj)
pushes a object. simply calls add.

pop

public Object pop()
returns the last object, removing it. returns null if no more elements.

peek

public Object peek()
returns the last object, without removing it. returns null if no more elements.

clear

public void clear()
clears all elements in this vector and sets its length to 0

size

public int size()
same of getCount()

indexOf

public int indexOf(Object elem)
same of find(Object)

indexOf

public int indexOf(Object elem,
                   int index)
same of find(Object, index)

elementAt

public Object elementAt(int index)
same of get(index)

setElementAt

public void setElementAt(Object obj,
                         int index)
same of set(index, Object)

removeElementAt

public void removeElementAt(int index)
same of del(index)

insertElementAt

public void insertElementAt(Object obj,
                            int index)
same of insert(index, Object)

addElement

public void addElement(Object obj)
same of add(Object)

removeElement

public boolean removeElement(Object obj)
same of del(Object)

removeAllElements

public void removeAllElements()
same of clear()

qsort

public boolean qsort()
Sorts the elements of this Vector. If they are Strings, the sort will be much faster because a cast to String is done; if they are not strings, the toString() method is used to return the string that will be used for comparision.