waba.util
Class IntVector

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

public final class IntVector
extends Object

An int vector is an array of int's. The vector grows and shrinks dynamically as ints are added and removed.

Here is an example showing a vector being used:

 ...
 IntVector vec = new IntVector();
 vec.add(int1);
 vec.add(int22);
 ...
 vec.insert(3, int3);
 vec.del(2);
 if (vec.getCount() > 5)
 ...
 

For efficiency, get and set is made directly through the public array. please use add and del to insert and remove elements


Field Summary
static int INVALID
           
 int[] items
           
 
Constructor Summary
IntVector()
          Constructs an empty vector.
IntVector(DataStream in)
          Constructs an vector read from the stream
IntVector(int size)
          Constructs an empty vector with a given initial size.
 
Method Summary
 void add(int obj)
          Adds an int to the end of the vector.
 void addElement(int obj)
          same of add(int)
 void clear()
          clears all elements in this vector and sets its length to 0
 void del(int index)
          Deletes the int reference at the given index.
 int elementAt(int index)
          same of items[index]
 void ensureBit(int index)
          Useful method to use when this IntVector will act like a bit vector, through the methods isBitSet and setBit.
 int find(int obj)
          Finds the index of the given int.
 int find(int obj, int startIndex)
          Finds the index of the given int.
 int getCount()
          Returns the number of ints in the vector.
 int indexOf(int elem)
          same of find(int)
 int indexOf(int elem, int index)
          same of find(int, index)
 void insert(int index, int obj)
          Inserts an int at the given index.
 void insertElementAt(int obj, int index)
          same of insert(index, int)
 boolean isBitSet(int index)
          Used to let this int vector act like a bit vector. returns true if the bit specified is set. you must guarantee that the index exists in the vector. guich@102
 int peek()
          returns the last int, without removing it. returns INVALID if no more elements.
 int pop()
          returns the last int, removing it. returns INVALID if no more elements.
 void push(int obj)
          pushes a int. simply calls add.
 void qsort()
          Do a quick sort in the elements of this IntVector
 void removeElement(int obj)
          same of del(int)
 void removeElementAt(int index)
          same of del(index)
 void setBit(int index, boolean on)
          Used to let this int vector act like a bit vector. returns true if the bit specified is set. you must guarantee that the index exists in the vector. guich@102
 void setElementAt(int obj, int index)
          Set the element at the given index.
 int size()
          same of getCount()
 void writeTo(DataStream out)
          writes this int vector to the stream
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, toString, wait, wait
 

Field Detail

INVALID

public static final int INVALID

items

public int[] items
Constructor Detail

IntVector

public IntVector()
Constructs an empty vector.

IntVector

public IntVector(DataStream in)
Constructs an vector read from the stream

IntVector

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

add

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

insert

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

del

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

find

public int find(int obj)
Finds the index of the given int. The list is searched using a O(n) linear search through all the ints in the vector.
Returns:
-1 if the object is not found.

find

public int find(int obj,
                int startIndex)
Finds the index of the given int. The list is searched using a O(n) linear search starting in startIndex up through all the ints in the vector.
Returns:
-1 if the object is not found.

getCount

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

writeTo

public void writeTo(DataStream out)
writes this int vector to the stream

ensureBit

public void ensureBit(int index)
Useful method to use when this IntVector will act like a bit vector, through the methods isBitSet and setBit. Just call it with the maximum bit index what will be used (starting from 0); then you can safely use the two methods. This must be done because those methods does not check the bounds of the array.

isBitSet

public boolean isBitSet(int index)
Used to let this int vector act like a bit vector. returns true if the bit specified is set. you must guarantee that the index exists in the vector. guich@102

setBit

public void setBit(int index,
                   boolean on)
Used to let this int vector act like a bit vector. returns true if the bit specified is set. you must guarantee that the index exists in the vector. guich@102

push

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

pop

public int pop()
returns the last int, removing it. returns INVALID if no more elements.

peek

public int peek()
returns the last int, without removing it. returns INVALID 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(int elem)
same of find(int)

indexOf

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

elementAt

public int elementAt(int index)
same of items[index]

setElementAt

public void setElementAt(int obj,
                         int index)
Set the element at the given index.

removeElementAt

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

insertElementAt

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

addElement

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

removeElement

public void removeElement(int obj)
same of del(int)

qsort

public void qsort()
Do a quick sort in the elements of this IntVector