waba.util
Class Vector

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

public class Vector
extends java.lang.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
 java.lang.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(java.lang.Object[] startingWith)
          Constructs a vector starting with the given elements.
 
Method Summary
 void add(java.lang.Object obj)
          Deprecated. Use addElement method instead.
 void addElement(java.lang.Object obj)
          Adds an object to the end of the vector.
 void clear()
          Deprecated. Use removeAllElements method instead.
 void del(int index)
          Deprecated. Use removeElementAt method instead.
 boolean del(java.lang.Object obj)
          Deprecated. Use removeElement method instead.
 int find(java.lang.Object obj)
          Deprecated. Use indexOf method instead.
 int find(java.lang.Object obj, int startIndex)
          Deprecated. Use indexOf method instead.
 int getCount()
          Deprecated. Use size method instead.
 int indexOf(java.lang.Object elem)
          Finds the index of the given object.
 int indexOf(java.lang.Object obj, int startIndex)
          Finds the index of the given object.
 void insert(int index, java.lang.Object obj)
          Deprecated. Use insertElementAt method instead. CAUTION: insertElementAt has the parameters in inverted order!
 void insertElementAt(java.lang.Object obj, int index)
          same of insert(index, Object), but slower, since it adds one method call
 java.lang.Object peek()
          returns the last object, without removing it. returns null if no more elements.
 java.lang.Object pop()
          Returns the last object, removing it. returns null if no more elements.
 void push(java.lang.Object obj)
          pushes a object. simply calls add.
 boolean qsort()
          Sorts the elements of this Vector.
 void removeAllElements()
          clears all elements in this vector and sets its length to 0.
 boolean removeElement(java.lang.Object obj)
          Deletes the object.
 void removeElementAt(int index)
          Deletes the object reference at the given index.
 int size()
          Returns the number of objects in the vector.
 java.lang.Object[] toObjectArray()
          Converts the vector to an array of objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

public java.lang.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(java.lang.Object[] startingWith)
Constructs a vector starting with the given elements. The vector can grow after this. Note that the given array must be fullfilled with objects and must have no null elements in it.
Method Detail

add

public void add(java.lang.Object obj)
Deprecated. Use addElement method instead.

Adds an object to the end of the vector.

insert

public void insert(int index,
                   java.lang.Object obj)
Deprecated. Use insertElementAt method instead. CAUTION: insertElementAt has the parameters in inverted order!

Inserts an object at the given index.

del

public void del(int index)
Deprecated. Use removeElementAt method instead.

Deletes the object reference at the given index.

del

public boolean del(java.lang.Object obj)
Deprecated. Use removeElement method instead.

Deletes the object.

find

public int find(java.lang.Object obj)
Deprecated. Use indexOf method instead.

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(java.lang.Object obj,
                int startIndex)
Deprecated. Use indexOf method instead.

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()
Deprecated. Use size method instead.

Returns the number of objects in the vector.

clear

public void clear()
Deprecated. Use removeAllElements method instead.


toObjectArray

public java.lang.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(java.lang.Object obj)
pushes a object. simply calls add.

pop

public java.lang.Object pop()
                     throws ElementNotFoundError
Returns the last object, removing it. returns null if no more elements.
Throws:
ElementNotFoundError - Starting in SuperWaba version 5.8, this method can throw an ElementNotFoundError when the stack is empty and Settings.useExceptions is set to true.

peek

public java.lang.Object peek()
                      throws ElementNotFoundError
returns the last object, without removing it. returns null if no more elements.
Throws:
ElementNotFoundError - Starting in SuperWaba version 5.8, this method can throw an ElementNotFoundError when the stack is empty and Settings.useExceptions is set to true.

size

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

indexOf

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

indexOf

public int indexOf(java.lang.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.

removeElementAt

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

insertElementAt

public void insertElementAt(java.lang.Object obj,
                            int index)
same of insert(index, Object), but slower, since it adds one method call

addElement

public void addElement(java.lang.Object obj)
Adds an object to the end of the vector.

removeElement

public boolean removeElement(java.lang.Object obj)
Deletes the object.

removeAllElements

public void removeAllElements()
clears all elements in this vector and sets its length to 0. Note that this method sets all items in this vector to null, so, if you had directly assigned an array to this vector, all items inside it will be nulled.

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.