ostore.util
Class QSVector

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

public class QSVector
extends Object
implements QuickSerializable, Cloneable

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.27 2002/12/10 09:51:18 hweather 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(InputBuffer buffer)
           
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 clear()
          Removes all of the elements from this Vector.
 Object clone()
          Create an exact copy of this hash
 boolean contains(QuickSerializable elem)
          Tests if the specified QuickSerializable object is a component in this vector.
 Object elementAt(int index)
          Returns the component at the specified index.
 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.
 void serialize(OutputBuffer buffer)
          Add the object to the buffer.
 QuickSerializable set(int index, QuickSerializable object)
          Insert the specified object at the specified index.
 int size()
          Return the number of elements in this QSVector
 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.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
See Also:
Constant Field Values

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(InputBuffer buffer)
         throws QSException
Method Detail

serialize

public void serialize(OutputBuffer buffer)
Description copied from interface: QuickSerializable
Add the object to the buffer.

Specified by:
serialize in interface QuickSerializable
Parameters:
buffer - the output buffer to add the object to

clone

public Object clone()
             throws CloneNotSupportedException
Create an exact copy of this hash

Overrides:
clone in class Object
Returns:
new SHA1Hash identical in value to this one
Throws:
CloneNotSupportedException - if clone() is not supported

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.

elementAt

public Object elementAt(int index)
Returns the component at the specified index.

This method is identical in functionality to the get method (which is part of the List interface).

Parameters:
index - an index into this vector.
Returns:
the component at the specified index.
Throws:
ArrayIndexOutOfBoundsException - if the index is negative or not less than the current size of this Vector object. given.
See Also:
get(int), List

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.

See Also:
clear()

contains

public boolean contains(QuickSerializable elem)
Tests if the specified QuickSerializable object is a component in this vector.

Parameters:
elem - a QuickSerializable object
Returns:
true if and only if the specified object is the same as a component of this vector, as determined by the equals method, false otherwise.

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.

clear

public void clear()
Removes all of the elements from this Vector. The Vector will be empty after this call returns (unless it throws an exception).

Since:
1.2

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.