ostore.util
Class QSVector

java.lang.Object
  |
  +--ostore.util.QSVector
All Implemented Interfaces:
QuickSerializable

public class QSVector
extends Object
implements QuickSerializable

A QSVector is a cousin of java.lang.Vector which implements ostore.util.QuickSerializable. All elements of the QSVector must also be QuickSerializable. Most of the functionality from the Vector has not been ported. If you require the use of a missing method, implement it.

Version:
$Id: QSVector.java,v 1.14 2001/11/24 21:58:27 strib Exp $
Author:
Dennis Geels

Field Summary
protected  int capacityIncrement
          The number of elements by which to grow the storage array when necessary.
static int DEFAULT_CAPACITY
           
protected  int elementCount
          The number of elements currently in the QSVector.
protected  QuickSerializable[] elementData
          The array of objects stored in this QSVector.
 
Constructor Summary
QSVector()
          Constructs a small QSVector.
QSVector(byte[] data, int[] offset)
          Constructs a QSVector from its QuickSerializable form.
QSVector(int initial_capacity)
          Constructs a QSVector of the specified capacity.
QSVector(int initial_capacity, int capacity_increment)
          Constructs a QSVector of the specified capacity and capacity increment.
QSVector(QuickSerializable[] array)
          Constructs a QSVector containing the contents of the specified array
 
Method Summary
 boolean add(int index, QuickSerializable object)
          Append the specified object to the QSVector at index index, shifting up the objects following the index, if any.
 boolean add(QuickSerializable object)
          Append the specified object to the QSVector.
 boolean add(QuickSerializable[] objects)
          Append the specified objects, in order, to the QSVector.
 void ensureCapacity(int size)
          Grow the storage array if necessary.
 boolean equals(Object o)
          Compare this QSVector to another Object.
 QuickSerializable get(int index)
          Return the object at the specified index.
 int hashCode()
          Return a hashcode, generated as in java.util.Vector, which was in turn specified by java.util.List.
 QuickSerializable remove(int index)
          Remove the object at the specified index.
 void removeAllElements()
          Remove all elements.
 void removeRange(int from, int to)
          Remove a range of elements.
 QuickSerializable set(int index, QuickSerializable object)
          Insert the specified object at the specified index.
 int size()
          Return the number of elements in this QSVector
 void to_bytes(byte[] data, int[] offset)
          Store the object in its "on the wire" form in the byte array data, starting at index offset [0], and increment offset [0] by the number of bytes written; if data == null, increment offset [0] by the number of bytes that would have been written otherwise.
 QuickSerializable[] toArray()
          Returns the elements of this QSVector as an array.
 String toString()
          Produce a human-readable version of this QSVector, which includes all the elements.
 int type_code()
          Returns the unique integer associated with this class in the TypeTable.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY

elementData

protected QuickSerializable[] elementData
The array of objects stored in this QSVector. All must by QuickSerializable.

elementCount

protected int elementCount
The number of elements currently in the QSVector.

capacityIncrement

protected int capacityIncrement
The number of elements by which to grow the storage array when necessary. A value of zero causes the storage to double each time.
Constructor Detail

QSVector

public QSVector(int initial_capacity,
                int capacity_increment)
Constructs a QSVector of the specified capacity and capacity increment.
Parameters:
initial_capacity - The initial size for the storage array.
capacity_increment - The number of elements by which to increase the storage array when necessary.

QSVector

public QSVector(int initial_capacity)
Constructs a QSVector of the specified capacity.
Parameters:
initial_capacity - The initial size for the storage array.

QSVector

public QSVector()
Constructs a small QSVector.

QSVector

public QSVector(QuickSerializable[] array)
Constructs a QSVector containing the contents of the specified array
Parameters:
array - The array whose contents to add

QSVector

public QSVector(byte[] data,
                int[] offset)
         throws QSException
Constructs a QSVector from its QuickSerializable form.
Method Detail

to_bytes

public void to_bytes(byte[] data,
                     int[] offset)
Description copied from interface: QuickSerializable
Store the object in its "on the wire" form in the byte array data, starting at index offset [0], and increment offset [0] by the number of bytes written; if data == null, increment offset [0] by the number of bytes that would have been written otherwise.
Specified by:
to_bytes in interface QuickSerializable
Following copied from interface: ostore.util.QuickSerializable
Parameters:
data - The byte array to store into, or null.
offset - A single element array whose first element is the index in data to begin writing at on function entry, and which on function exit has been incremented by the number of bytes written.

type_code

public int type_code()
Description copied from interface: QuickSerializable
Returns the unique integer associated with this class in the TypeTable.
Specified by:
type_code in interface QuickSerializable
Following copied from interface: ostore.util.QuickSerializable
Returns:
an integer unique to this class

size

public int size()
Return the number of elements in this QSVector
Returns:
elementCount;

add

public boolean add(QuickSerializable object)
Append the specified object to the QSVector.
Parameters:
object - The QuickSerializable to add.
Returns:
true, just like Vector.add().

add

public boolean add(int index,
                   QuickSerializable object)
Append the specified object to the QSVector at index index, shifting up the objects following the index, if any.
Parameters:
object - The QuickSerializable to add.
index - The index at which to add the QuickSerializable. Must be valid.
Returns:
true, just like Vector.add().
Throws:
ArrayIndexOutOfBoundsException - if index is out of range

add

public boolean add(QuickSerializable[] objects)
Append the specified objects, in order, to the QSVector.
Parameters:
objects - The QuickSerializables to add.
Returns:
true, just like Vector.add().

ensureCapacity

public void ensureCapacity(int size)
Grow the storage array if necessary.
Parameters:
size - The minimum acceptable capacity for the storage array.

set

public QuickSerializable set(int index,
                             QuickSerializable object)
Insert the specified object at the specified index.
Parameters:
index - the index for the element.
Returns:
the QuickSerializable object previously stored at the specified index.

get

public QuickSerializable get(int index)
Return the object at the specified index.
Parameters:
index - the index of the element to return.
Returns:
the specified QuickSerializable object, or null if index is out of range.

remove

public QuickSerializable remove(int index)
Remove the object at the specified index.
Parameters:
index - the index of the element to remove.
Returns:
the QuickSerializable object previously stored at the specified index.

removeRange

public void removeRange(int from,
                        int to)
Remove a range of elements.
Parameters:
from - The index of the first element to remove.
to - The index after the last element to remove.

removeAllElements

public void removeAllElements()
Remove all elements.

toArray

public QuickSerializable[] toArray()
Returns the elements of this QSVector as an array. Useful for repeated iterations over the contents.
Returns:
an array of size this.size() containing the elements of this QSVector in order.

hashCode

public int hashCode()
Return a hashcode, generated as in java.util.Vector, which was in turn specified by java.util.List.
Overrides:
hashCode in class Object
Returns:
a hashcode which incorporates the hashcodes of all the elements in the QSVector

equals

public boolean equals(Object o)
Compare this QSVector to another Object.
Overrides:
equals in class Object
Returns:
true iff the other Object is also a QSVector and contains equal elements.

toString

public String toString()
Produce a human-readable version of this QSVector, which includes all the elements.
Overrides:
toString in class Object
Returns:
a String representation of this QSVector.