ewe.util
Class Vector

java.lang.Object
  extended byewe.data.DataObject
      extended byewe.util.Vector
All Implemented Interfaces:
Comparable, Copyable, DataUnit
Direct Known Subclasses:
CheckBoxGroup, Grid, ImageList, MultiListSelect.SelectedItems, PropertyList, RangeList

public class Vector
extends DataObject

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)
 ...
 


Constructor Summary
Vector()
          Constructs an empty vector.
Vector(int size)
          Constructs an empty vector with a given initial size.
Vector(Object[] items)
           
 
Method Summary
 void add(int index, Object obj)
          Inserts an object at the given index.
 void add(Object obj)
          Adds an object to the end of the vector.
static Vector add(Vector v, Object toAdd)
          This adds an object to the end of the Vector v.
 void addAll(Object[] objs)
           
 void addAll(Object[] objs, int start, int length)
           
 void addAll(Vector objs)
           
 void addCopiesFrom(Object[] object, int start, int length)
           
 void addElement(Object what)
           
 void clear()
           
 int compare(Object one, Object two)
           
 boolean contains(Object obj)
           
 void copyCopiesFrom(Object other)
           
 void copyFrom(Object other)
          Copy all appropriate data from another object.
 void copyInto(Object[] array)
          The destination array MUST be big enough to hold the vector.
 void copyInto(Object[] array, int destPos)
          The destination array MUST be big enough to hold the vector.
 void del(int index)
          Deletes the object reference at the given index.
 Object elementAt(int index)
          This is the same as get().
 Enumeration elements()
          Get an Enumeration for the elements of the vector.
 int find(Object obj)
          Finds the index of the given object.
 Object find(ObjectFinder finder)
           
 Object get(int index)
          Returns the object at the given index.
 int getCount()
          Returns the number of objects in the vector.
 Vector getFullCopy()
          This returns a Vector that is a copy of this one, where all the items are themselves copies of the original items.
 void insert(int index, Object obj)
          Deprecated. Use add(index,obj) instead.
 void insertElementAt(Object obj, int index)
           
 boolean isEmpty()
           
 Iterator iterator()
          Get an Iterator for the vector.
static Iterator iterator(Vector v)
          This returns an iterator for the specified Vector.
static Object pop(Vector v)
          This removes and returns the object at the front of the Vector v.
static Vector push(Vector v, Object toPush)
          This inserts an object to the front of the Vector v.
 void remove(Object obj)
           
 void removeAllElements()
           
 void removeElementAt(int index)
           
 void set(int index, Object obj)
          Sets the object at the given index.
 void setElementAt(Object obj, int index)
           
 void setSize(int size)
           
 int size()
           
 void sort(Comparer comparer, boolean descending)
           
 boolean sort(Handle h, Comparer comparer, boolean descending)
           
 Object[] toArray()
          Create a new Object array and copy all the elements into it.
 Object[] toArray(Object[] dest)
          Copy the vector into the destination array, creating a new one if the provided destination is not big enough to hold all the elements.
 Object[] toObjectArray()
          Converts the vector to an array of objects.
 String toString()
          Return a String representation of this object.
 void zero()
           
 
Methods inherited from class ewe.data.DataObject
_getSetField, appendAllFields, compareTo, copied, equals, getCopy, getDeclaredField, getDeclaredFieldValue, getDeclaredFieldValue, getFieldList, getFieldList, getMyFieldList, getNew
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode
 

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.


Vector

public Vector(Object[] items)
Method Detail

copyFrom

public void copyFrom(Object other)
Description copied from interface: DataUnit
Copy all appropriate data from another object.

Specified by:
copyFrom in interface DataUnit
Overrides:
copyFrom in class DataObject

addCopiesFrom

public void addCopiesFrom(Object[] object,
                          int start,
                          int length)

copyCopiesFrom

public void copyCopiesFrom(Object other)

getFullCopy

public Vector getFullCopy()
This returns a Vector that is a copy of this one, where all the items are themselves copies of the original items.


add

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


insert

public void insert(int index,
                   Object obj)
Deprecated. Use add(index,obj) instead.

Insert an object at the given index.

Parameters:
index - The index to insert the object.
obj - The object to add.

add

public void add(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.


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.


getCount

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


toObjectArray

public Object[] toObjectArray()
Converts the vector to an array of objects.


clear

public void clear()

iterator

public Iterator iterator()
Get an Iterator for the vector. The iterator that is returned supports the remove() method.

Returns:
an Iterator for the vector.

elements

public Enumeration elements()
Get an Enumeration for the elements of the vector.

Returns:
an Enumeration for the elements of the vector.

size

public int size()

compare

public int compare(Object one,
                   Object two)

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.


contains

public boolean contains(Object obj)

remove

public void remove(Object obj)

addAll

public void addAll(Object[] objs,
                   int start,
                   int length)

addAll

public void addAll(Object[] objs)

addAll

public void addAll(Vector objs)

copyInto

public void copyInto(Object[] array,
                     int destPos)
The destination array MUST be big enough to hold the vector.


copyInto

public void copyInto(Object[] array)
The destination array MUST be big enough to hold the vector.


find

public Object find(ObjectFinder finder)

add

public static Vector add(Vector v,
                         Object toAdd)
This adds an object to the end of the Vector v. If v is null a new Vector is created and returned.


push

public static Vector push(Vector v,
                          Object toPush)
This inserts an object to the front of the Vector v. If v is null a new Vector is created and returned. This is not meant to be a high-performance Stack implementation.


pop

public static Object pop(Vector v)
This removes and returns the object at the front of the Vector v. If v is null OR v is empty, it will return null. This is not meant to be a high-performance Stack implementation.


iterator

public static Iterator iterator(Vector v)
This returns an iterator for the specified Vector. If the vector is null it will return an Iterator with no elements.


toString

public String toString()
Description copied from class: Object
Return a String representation of this object.

Overrides:
toString in class Object
Returns:
a String representing this object.

toArray

public Object[] toArray(Object[] dest)
Copy the vector into the destination array, creating a new one if the provided destination is not big enough to hold all the elements. If the provided destination array is big enough for the vector, the elements are copied into the array starting from the first index. If the array is bigger than the size of the vector, the extra elements of the array are set to null. If the array is smaller than the vector, then a new array is created, whose runtime type is the same as the destination parameter, and whose size is the same size as the vector. The vector elements are then copied into the newly created array and this array is then returned.

Returns:
The destination object array if it is big enough, or a new array if it is not.

toArray

public Object[] toArray()
Create a new Object array and copy all the elements into it.

Returns:
A new Object array containing the vector's elements.

elementAt

public Object elementAt(int index)
This is the same as get().


addElement

public void addElement(Object what)

setElementAt

public void setElementAt(Object obj,
                         int index)

setSize

public void setSize(int size)

removeElementAt

public void removeElementAt(int index)

insertElementAt

public void insertElementAt(Object obj,
                            int index)

isEmpty

public boolean isEmpty()

removeAllElements

public void removeAllElements()

sort

public boolean sort(Handle h,
                    Comparer comparer,
                    boolean descending)

sort

public void sort(Comparer comparer,
                 boolean descending)

zero

public void zero()