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
-
elementCount
- The total number of valid elements in the vector.
-
OSVector()
- Constructs an empty vector.
-
OSVector(char)
- Constructs a hollow OSVector.
-
OSVector(ClassInfo)
- Constructs a hollow OSVector.
-
OSVector(int)
- Constructs an empty vector with the specified storage capacity.
-
OSVector(int, int)
- Constructs an empty vector with the specified storage
capacity and the specified capacityIncrement.
-
addElement(Object)
- Appends the element to the vector.
-
capacity()
- Obtains the current capacity of the vector.
-
clearContents()
- Resets the values of the fields of an active persistent object to the default
initial values of that class of object.
-
clone()
- Clones the vector.
-
contains(Object)
- Checks whether or not the object is an element in this vector.
-
copyInto(Object[])
- Copies the elements of this vector into the specified array.
-
destroy()
- Destroys the vector in the database.
-
elementAt(int)
- Obtains the element at the specified index within the vector.
-
elements()
- Obtains an enumeration of the elements.
-
ensureCapacity(int)
- Ensures that the vector has at least the specified capacity.
-
firstElement()
- Obtains the first element in the vector.
-
flushContents(GenericObject)
- Stores the values of the fields of an active persistent object in
an instance of GenericObject.
-
indexOf(Object)
- Finds the index of the object within the vector.
-
indexOf(Object, int)
- Finds the index of the object within the vector starting at a
specified position.
-
initializeContents(GenericObject)
- Initializes the values of the fields of a hollow persistent object from
data contained in an instance of GenericObject.
-
insertElementAt(Object, int)
- Inserts the specified object at the specified index.
-
isEmpty()
- Returns true if the elementCount is 0.
-
lastElement()
- Obtains the last element in the buffer.
-
lastIndexOf(Object)
- Finds the index of the last matching entry in the vector.
-
lastIndexOf(Object, int)
- Finds the last index of the object within the vector starting at a
specified postion.
-
removeAllElements()
- Removes all elements of the vector.
-
removeElement(Object)
- Removes the first occurance of the specified element from the vector.
-
removeElementAt(int)
- Deletes the element at the specified index and moves all elements with
index greater than the current index down.
-
setElementAt(Object, int)
- Sets the element at the specified index to the specified object.
-
setSize(int)
- Sets the size of the vector.
-
size()
- Returns the number of elements in the vector.
-
toString()
- Converts the vector's elementData to a string.
-
trimToSize()
- Trims the vector's capacity down to approximately elementCount.
elementCount
protected int elementCount
- The total number of valid elements in the vector.
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.
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.
OSVector
public OSVector()
- Constructs an empty vector.
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.
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.
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
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
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
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
addElement
public final synchronized void addElement(Object obj)
- Appends the element to the vector.
- Parameters:
- obj - The element to be added.
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.
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.
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.
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.
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.
ensureCapacity
public final synchronized void ensureCapacity(int minCapacity)
- Ensures that the vector has at least the specified capacity.
- Parameters:
- minCapacity - The desired minimum capacity.
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.
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.
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.
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.
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.
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.
size
public final int size()
- Returns the number of elements in the vector.
isEmpty
public final boolean isEmpty()
- Returns true if the elementCount is 0.
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.
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.
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.
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.
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.
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.
removeAllElements
public final synchronized void removeAllElements()
- Removes all elements of the vector.
clone
public synchronized Object clone()
- Clones the vector.
- Returns:
- The cloned object.
- Overrides:
- clone in class HashPersistent
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.