waba.util
Class IntVector

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

public class IntVector
extends java.lang.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
protected  int count
           
static int INVALID
           
 int[] items
           
 
Constructor Summary
IntVector()
          Constructs an empty vector.
IntVector(DataStream in)
          Deprecated. This constructor will be removed in the future. Grab the code and put it in your program.
IntVector(int size)
          Constructs an empty vector with a given initial size.
IntVector(int[] items)
          Constructs a vector by directly assigning the given int array.
 
Method Summary
 void add(int obj)
          Deprecated. Use addElement instead.
 void addElement(int obj)
          Adds an int to the end of the vector.
 void clear()
          Deprecated. Use removeAllElements instead.
 void del(int index)
          Deprecated. Use removeElementAt method instead.
 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)
          Deprecated. Use indexOf method instead.
 int find(int obj, int startIndex)
          Deprecated. Use indexOf method instead.
 int getCount()
          Deprecated. Use size method instead.
 int indexOf(int elem)
          Finds the index of the given int.
 int indexOf(int elem, int index)
          Finds the index of the given int.
 void insert(int index, int obj)
          Deprecated. Use insertElementAt method instead. CAUTION: insertElementAt has the parameters in inverted order!
 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 pop(int howMany)
          Pops the given number of elements from this vector.
 void push(int obj)
          pushes a int. simply calls add.
 void qsort()
          Do a quick sort in the elements of this IntVector
 void removeAllElements()
          Sets all elements in this vector to 0 and its size to 0.
 void removeElement(int obj)
          Deletes the int reference.
 void removeElementAt(int index)
          Deletes the int reference at the given 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
 int size()
          Returns the number of ints in the vector.
 int[] toIntArray()
          Returns a new array with just the added elements
 void writeTo(DataStream out)
          Deprecated. This method will be removed in the future. Grab the code and put it in your program.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INVALID

public static final int INVALID

items

public int[] items

count

protected int count
Constructor Detail

IntVector

public IntVector()
Constructs an empty vector.

IntVector

public IntVector(DataStream in)
Deprecated. This constructor will be removed in the future. Grab the code and put it in your program.

Constructs a 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!

IntVector

public IntVector(int[] items)
Constructs a vector by directly assigning the given int array. Changes on the original array will reflect the items of this array and vice-versa.
Since:
SuperWaba 5.11
Method Detail

add

public void add(int obj)
Deprecated. Use addElement instead.

Adds an int to the end of the vector.

insert

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

Inserts an int at the given index.

del

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

Deletes the int reference at the given index.

find

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

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

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

Returns the number of ints in the vector.

writeTo

public void writeTo(DataStream out)
Deprecated. This method will be removed in the future. Grab the code and put it in your program.

writes this int vector to the stream

clear

public void clear()
Deprecated. Use removeAllElements instead.

clears all elements in this vector and sets its length to 0.

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 void pop(int howMany)
Pops the given number of elements from this vector.
Since:
SuperWaba 5.0

pop

public int pop()
        throws ElementNotFoundError
returns the last int, removing it. returns INVALID 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 int peek()
         throws ElementNotFoundError
returns the last int, without removing it. returns INVALID 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 ints in the vector.

indexOf

public int indexOf(int elem)
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.

indexOf

public int indexOf(int elem,
                   int index)
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.

removeElementAt

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

insertElementAt

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

addElement

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

removeElement

public void removeElement(int obj)
Deletes the int reference.

removeAllElements

public void removeAllElements()
Sets all elements in this vector to 0 and its size to 0.

qsort

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

toIntArray

public int[] toIntArray()
Returns a new array with just the added elements
Since:
SuperWaba 5.54