Class COM.odi.util.OSVector

java.lang.Object
   |
   +----COM.odi.Persistent
           |
           +----COM.odi.util.HashPersistent
                   |
                   +----COM.odi.util.OSVector

public class OSVector
extends HashPersistent
implements Cloneable, Serializable
OSVector implements a persistent growable array. The API is similar to java.util.Vector for ease of code conversion.

This class defines five persistent data fields. If you do not run the Class File Postprocessor on a subclass then you must be sure to number persistent fields starting at 6.

See Also:
Persistent, Vector

Variable Index

 o elementCount
The total number of valid elements in the vector.

Constructor Index

 o OSVector()
Constructs an empty vector.
 o OSVector(char)
Constructs a hollow OSVector.
 o OSVector(ClassInfo)
Constructs a hollow OSVector.
 o OSVector(int)
Constructs an empty vector with the specified storage capacity.
 o OSVector(int, int)
Constructs an empty vector with the specified storage capacity and the specified capacityIncrement.

Method Index

 o addElement(Object)
Appends the element to the vector.
 o capacity()
Obtains the current capacity of the vector.
 o clearContents()
Resets the values of the fields of an active persistent object to the default initial values of that class of object.
 o clone()
Clones the vector.
 o contains(Object)
Checks whether or not the object is an element in this vector.
 o copyInto(Object[])
Copies the elements of this vector into the specified array.
 o destroy()
Destroys the vector in the database.
 o elementAt(int)
Obtains the element at the specified index within the vector.
 o elements()
Obtains an enumeration of the elements.
 o ensureCapacity(int)
Ensures that the vector has at least the specified capacity.
 o firstElement()
Obtains the first element in the vector.
 o flushContents(GenericObject)
Stores the values of the fields of an active persistent object in an instance of GenericObject.
 o indexOf(Object)
Finds the index of the object within the vector.
 o indexOf(Object, int)
Finds the index of the object within the vector starting at a specified position.
 o initializeContents(GenericObject)
Initializes the values of the fields of a hollow persistent object from data contained in an instance of GenericObject.
 o insertElementAt(Object, int)
Inserts the specified object at the specified index.
 o isEmpty()
Returns true if the elementCount is 0.
 o lastElement()
Obtains the last element in the buffer.
 o lastIndexOf(Object)
Finds the index of the last matching entry in the vector.
 o lastIndexOf(Object, int)
Finds the last index of the object within the vector starting at a specified postion.
 o removeAllElements()
Removes all elements of the vector.
 o removeElement(Object)
Removes the first occurance of the specified element from the vector.
 o removeElementAt(int)
Deletes the element at the specified index and moves all elements with index greater than the current index down.
 o setElementAt(Object, int)
Sets the element at the specified index to the specified object.
 o setSize(int)
Sets the size of the vector.
 o size()
Returns the number of elements in the vector.
 o toString()
Converts the vector's elementData to a string.
 o trimToSize()
Trims the vector's capacity down to approximately elementCount.

Variables

 o elementCount
  protected int elementCount
The total number of valid elements in the vector.

Constructors

 o OSVector
  public OSVector(int initialBufferSize,
                  int capacityIncrement)
Constructs an empty vector with the specified storage capacity and the specified capacityIncrement.

Parameters:
initialCapacity - The initial storage capacity of the vector.

capacityIncrement - The amount by which the capacity should be increased when the vector needs to grow.
 o OSVector
  public OSVector(int initialBufferSize)
Constructs an empty vector with the specified storage capacity. This also sets capacityIncrement to the size of initialBufferSize for elementData growth.

Parameters:
initialCapacity - The initial storage capacity of the vector.
 o OSVector
  public OSVector()
Constructs an empty vector.

 o OSVector
  protected OSVector(ClassInfo ignored)
Constructs a hollow OSVector. This constructor should be used only for that purpose.

Parameters:
ignored - Only used to distinguish this overloading. The value is not used.
 o OSVector
  protected OSVector(char ignored)
Constructs a hollow OSVector. This constructor should be used only for that purpose. New code is encouraged to use the new-style hollow object constructor which accepts a ClassInfo argument.

Parameters:
ignored - Only used to distinguish this overloading. The value is not used.

Methods

 o initializeContents
  public void initializeContents(GenericObject genObject)
Initializes the values of the fields of a hollow persistent object from data contained in an instance of GenericObject. PSE/PSE Pro arranges to call this method when an application calls fetch() or dirty() on a persistent object. In the class you define, the method that overrides this method must initialize all fields in the hollow persistent object, including any fields defined by superclasses. Initialize superclass fields by invoking initializeContents() on the superclass. This is similar to calls to superclass constructors, although in this case the superclass initialization is not enforced by the compiler.

Parameters:
genObject - The representation of the persistent object that the method should read the field values from.

Overrides:
initializeContents in class HashPersistent
See Also:
initializeContents
 o flushContents
  public void flushContents(GenericObject genObject)
Stores the values of the fields of an active persistent object in an instance of GenericObject. PSE/PSE Pro arranges to call this method when a modified persistent object is evicted and when a transaction is committed. Your persistent class definition must define a method to override this one. Ensure that it writes all fields, even fields that were not modified.

Parameters:
genObj - The representation of the persistent object that this method should write the field values into.

Overrides:
flushContents in class HashPersistent
See Also:
flushContents
 o clearContents
  public void clearContents()
Resets the values of the fields of an active persistent object to the default initial values of that class of object. This causes the object to become a stale persistent object. As with initializeContents(), this method must invoke clearContents() on its superclass to ensure that all fields are correctly cleared.

Overrides:
clearContents in class HashPersistent
See Also:
clearContents
 o destroy
  public synchronized void destroy()
Destroys the vector in the database. The elements in the vector are unaffected by this operation. If the vector is persistent, the database must be open for update and there must be an update transaction in progress.

Throws: DatabaseNotOpenException
If the database containing the object is not open.
Throws: NoTransactionInProgressException
If there is no transaction in progress.
Throws: ObjectNotFoundException
The object was not found, either because the object itself, its segment, or its database were destroyed, or because the object was local and was fetched in a previous transaction.
Throws: ObjectStoreException
If PSE/PSE Pro is not initialized for the current thread or if the object is not associated with this thread.
Throws: UpdateReadOnlyException
If there is a read-only transaction in progress or if the database is open read-only.
Overrides:
destroy in class Persistent
 o addElement
  public final synchronized void addElement(Object obj)
Appends the element to the vector.

Parameters:
obj - The element to be added.
 o capacity
  public final int capacity()
Obtains the current capacity of the vector.

Returns:
The total number of elements that can be stored in the vector without any additional growth.
 o contains
  public final boolean contains(Object elem)
Checks whether or not the object is an element in this vector.

Parameters:
elem - The object to look for.

Returns:
The true constant if the specified object is in the vector. The false constant if it is not.
 o copyInto
  public final synchronized void copyInto(Object anArray[])
Copies the elements of this vector into the specified array.

Parameters:
anArray - The array into which the elements are copied.

Throws: ArrayIndexOutOfBoundsException
If anArray is not large enough to hold all elements of this vector.
Throws: NullPointerException
If anArray is null and the vector is not empty.
 o elementAt
  public final synchronized Object elementAt(int index)
Obtains the element at the specified index within the vector.

Parameters:
index - The index of the desired element.

Returns:
The element at the specified index.

Throws: ArrayIndexOutOfBoundsException
If the index is greater than the number of elements or less than 0.
 o firstElement
  public final synchronized Object firstElement()
Obtains the first element in the vector.

Returns:
The first element from the buffer.

Throws: NoSuchElementException
If the buffer is empty.
 o ensureCapacity
  public final synchronized void ensureCapacity(int minCapacity)
Ensures that the vector has at least the specified capacity.

Parameters:
minCapacity - The desired minimum capacity.
 o indexOf
  public final int indexOf(Object elem)
Finds the index of the object within the vector.

Parameters:
elem - The desired element.

Returns:
The index of the first matching vector entry or -1 if the element is not found.
 o indexOf
  public final synchronized int indexOf(Object elem,
                                        int index)
Finds the index of the object within the vector starting at a specified position.

Parameters:
elem - The desired element.

index - The index at which to start searching.

Returns:
The index of the first matching vector entry at or after the specified position or -1 if the element is not found.
 o lastIndexOf
  public final int lastIndexOf(Object elem)
Finds the index of the last matching entry in the vector.

Parameters:
elem - The desired element.

Returns:
The last index to the object or -1 if not found.
 o lastIndexOf
  public final synchronized int lastIndexOf(Object elem,
                                            int index)
Finds the last index of the object within the vector starting at a specified postion.

Parameters:
elem - The desired element.

index - The index at which to start searching.

Returns:
The last index to the object at or before the specified start index or -1 if not found.
 o lastElement
  public final synchronized Object lastElement()
Obtains the last element in the buffer.

Returns:
The last element in the buffer.

Throws: NoSuchElementException
If the buffer is empty.
 o setSize
  public final synchronized void setSize(int newSize)
Sets the size of the vector. If the size is less than elementCount, then elements beyond this number are lost. If the size increases, then new elements are set to null.

Parameters:
newSize - The new size of the vector.
 o size
  public final int size()
Returns the number of elements in the vector.

 o isEmpty
  public final boolean isEmpty()
Returns true if the elementCount is 0.

 o trimToSize
  public final synchronized void trimToSize()
Trims the vector's capacity down to approximately elementCount. Because OSVector uses a fixed size bucket allocation scheme, the capacity cannot be trimmed to an arbitrary size - the next largest suitable size is used instead.

 o elements
  public final synchronized Enumeration elements()
Obtains an enumeration of the elements. This can be used to fetch the elements sequentially.

Returns:
An enumeration of the elements in the vector.
 o setElementAt
  public final synchronized void setElementAt(Object obj,
                                              int index)
Sets the element at the specified index to the specified object. If an element already exists then it is replaced with new object.

Parameters:
obj - What the element is to be set to.

index - The specified index.

Throws: ArrayIndexOutOfBoundsException
If the index was invalid.
 o removeElementAt
  public final synchronized void removeElementAt(int index)
Deletes the element at the specified index and moves all elements with index greater than the current index down.

Parameters:
index - The element to remove.

Throws: ArrayIndexOutOfBoundsException
If the index was invalid.
 o insertElementAt
  public final synchronized void insertElementAt(Object obj,
                                                 int index)
Inserts the specified object at the specified index. Elements with an index greater than or equal to the current index are shifted up.

Parameters:
obj - The element to insert.

index - Where to insert the new element.

Throws: ArrayIndexOutOfBoundsException
If the index was invalid.
 o removeElement
  public final synchronized boolean removeElement(Object obj)
Removes the first occurance of the specified element from the vector.

Parameters:
obj - The element to be removed.

Returns:
The true constant if the element was actually removed. The false constant otherwise.
 o removeAllElements
  public final synchronized void removeAllElements()
Removes all elements of the vector.

 o clone
  public synchronized Object clone()
Clones the vector.

Returns:
The cloned object.
Overrides:
clone in class HashPersistent
 o toString
  public final synchronized String toString()
Converts the vector's elementData to a string. This is an overriding of the Object.toString() method.

Returns:
A string that represents the object.
Overrides:
toString in class Object

Copyright © 1996, 1997 Object Design, Inc. All rights reserved.