Class COM.odi.util.OSVector
java.lang.Object
|
+----COM.odi.util.OSVector
- public class OSVector
- extends Object
- implements Collection, IPersistent, Cloneable, Serializable
OSVector implements a persistent expandable array. The API is
similar to java.util.Vector for ease of code conversion.
You do not need to run the postprocessor on OSVector. It is
already persistence-capable. If you
define a subclass that extends OSVector and you want the subclass
to be persistence-capable, you must either run the postprocessor on the
subclass or manually annotate the subclass.
Additional information about OSVector
is in the user guide.
Here are exceptions that might be thrown by many of the
methods in this class:
DatabaseNotOpenException
If the database containing the object is not open.
NoTransactionInProgressException
If there is no transaction in progress.
ObjectNotFoundException
If the object was not found, either because the object itself, its segment,
or its database was destroyed.
ObjectException
Ifthe object was local and was fetched in a previous transaction.
ObjectStoreException
If the session implied by an argument
to the call or the object the method is called on is not the same as
the session associated with the current thread.
UpdateReadOnlyException
If there is a readonly
transaction in progress or if the database is open for readonly.
- See Also:
- IPersistent, Vector
-
elementCount
- The number of valid elements in the vector.
-
OSVector()
- Constructs an empty vector.
-
OSVector(char)
- Constructs a hollow OSVector but is deprecated in this release.
-
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 and allocates
internal structures.
-
OSVector(int, int, boolean)
- Constructs an empty vector with the specified storage
capacity and the specified capacityIncrement and can
allocate or delay allocating internal structures.
-
add(int, Object)
- Inserts the specified element at the specified position in this
List.
-
add(Object)
- Appends the specified element to the end of this List.
-
addAll(Collection)
- Appends all of the elements in the specified Collection to the
end of this this List, in the order that they are returned by
the specified Collection's Iterator.
-
addAll(int, Collection)
- Inserts all of the elements in in the specified Collection into
this List at the specified position.
-
addElement(Object)
- Appends the element to the vector.
-
capacity()
- Obtains the current capacity of the vector.
-
clear()
- Removes all of the elements from this List.
-
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.
-
containsAll(Collection)
- Returns true if this List contains all of the elements of the
specified Collection.
-
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.
-
get(int)
- Returns the element at the specified position in this List.
-
hashCode()
- Returns the hash code for the object.
-
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 elementCount is 0.
-
iterator()
- Returns an Iterator over the elements in this List in proper
sequence.
-
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 index of the last entry within the vector starting at a
specified postion.
-
listIterator()
- Returns a ListIterator of the elements in this List (in proper
sequence).
-
listIterator(int)
- Returns a ListIterator of the elements in this List (in proper
sequence), starting at the specified position in the List.
-
remove(int)
- Removes the element at the specified position in this List.
-
remove(Object)
- Removes the first occurence of the specified element in this
List.
-
removeAll(Collection)
- Removes from this List all of its elements that are contained
in the specified Collection.
-
removeAllElements()
- Removes all elements of the vector.
-
removeElement(Object)
- Removes from the vector the first occurence of the specified element.
-
removeElementAt(int)
- Deletes the element at the specified index and moves down all elements with
indexes greater than the current index.
-
removeRange(int, int)
- Removes from this List all of the elements whose index is
between fromIndex, inclusive and toIndex, exclusive.
-
retainAll(Collection)
- Retains only the elements in this List that are contained in
the specified Collection.
-
set(int, Object)
- Replaces the element at the specified position in this List
with the specified element.
-
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.
-
toArray()
- Returns an array containing all of the elements in this List.
-
toString()
- Converts the vector's elementData to a string.
-
trimToSize()
- Trims the vector's capacity down to approximately elementCount.
elementCount
protected int elementCount
- The 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 and allocates
internal structures.
- 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,
int capacityIncrement,
boolean lazy)
- Constructs an empty vector with the specified storage
capacity and the specified capacityIncrement and can
allocate or delay allocating internal structures.
- 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.
- lazy - A true argument delays allocation of the internal
structures used to represent the vector until the first element is added
to it. This option helps minimize storage associated with vectors that are
empty. A false argument causes the internal structures to be created
immediately; this is the default initial representation used by OSvector.
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 but is deprecated in this release.
This constructor will be removed in a future release.
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.
ObjectStore arranges to call this
method when an application calls fetch() or dirty() on a
persistent object. If you define a subclass of this class, you must
define a method that overrides this method and initializes 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.
- 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. ObjectStore arranges to call this
method when a modified persistent object is evicted and when a transaction
is committed. If you define a subclass of this class, you must
define a method that overrides this method and
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.
- 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. If you define a subclass of this class, you must
define a method that overrides this method and invokes
clearContents() on its superclass to ensure that all fields are correctly
cleared.
- 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 was
destroyed, or because the object was local and was fetched in a
previous transaction.
- Throws: ObjectStoreException
- If the session implied by the vector
has been terminated or if the current thread is associated with a
session other than the session implied by the vector.
- Throws: UpdateReadOnlyException
- If there is a read-only
transaction in progress or if the database is open read-only.
addElement
public synchronized void addElement(Object obj)
- Appends the element to the vector.
- Parameters:
- obj - The element to be added.
capacity
public final synchronized 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: IndexOutOfBoundsException
- 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: IndexOutOfBoundsException
- If the index is greater
than or equal to 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 index to the last matching entry or -1 if a
matching entry is not found.
lastIndexOf
public final synchronized int lastIndexOf(Object elem,
int index)
- Finds the index of the last entry within the vector starting at a
specified postion.
- Parameters:
- elem - The desired element.
- index - The index at which to start searching.
- Returns:
- The index to the last entry 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 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 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 synchronized void setElementAt(Object obj,
int index)
- Sets the element at the specified index to the specified object.
If an element already exists at the specified index, it is replaced with the new object.
- Parameters:
- obj - What the element is to be set to.
- index - The index of the modified element.
- Throws: IndexOutOfBoundsException
- If the index was
invalid.
removeElementAt
public synchronized void removeElementAt(int index)
- Deletes the element at the specified index and moves down all elements with
indexes greater than the current index.
- Parameters:
- index - The element to remove.
- Throws: IndexOutOfBoundsException
- If the index was invalid.
insertElementAt
public 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: IndexOutOfBoundsException
- If the index was invalid.
removeElement
public final synchronized boolean removeElement(Object obj)
- Removes from the vector the first occurence of the specified element.
- Parameters:
- obj - The element to be removed.
- Returns:
- The true constant if the element was removed.
The false constant otherwise.
removeAllElements
public synchronized void removeAllElements()
- Removes all elements of the vector.
hashCode
public int hashCode()
- Returns the hash code for the object.
- Overrides:
- hashCode in class Object
clone
public synchronized Object clone()
- Clones the vector.
- Returns:
- The cloned object.
- Overrides:
- clone in class Object
toString
public final synchronized String toString()
- Converts the vector's elementData to a string.
This overrides the Object.toString() method.
- Returns:
- A string that represents the object.
- Overrides:
- toString in class Object
iterator
public synchronized Iterator iterator()
- Returns an Iterator over the elements in this List in proper
sequence.
toArray
public synchronized Object[] toArray()
- Returns an array containing all of the elements in this List.
Obeys the general contract of Collection.toArray.
add
public boolean add(Object obj)
- Appends the specified element to the end of this List.
- Parameters:
- o - element to be appended to this List.
- Returns:
- true (as per the general contract of Collection.add).
- Throws: ClassCastException
- class of the specified element
prevents it from being added to this Set.
- Throws: IllegalArgumentException
- some aspect of this element prevents
it from being added to this Collection.
remove
public boolean remove(Object obj)
- Removes the first occurence of the specified element in this
List. If the List does not contain the
element, it is unchanged. More formally, removes the element
with the lowest index i such that
(o==null ? get(i)==null
: o.equals(get(i)))
(if such an element exists).
- Parameters:
- o - element to be removed from this List, if present.
- Returns:
- true if the List contained the specified element.
containsAll
public synchronized boolean containsAll(Collection coll)
- Returns true if this List contains all of the elements of the
specified Collection. Both this list and the specified collection
are treated as sets for the purposes of this operation (that is,
duplicate elements are ignored).
addAll
public synchronized boolean addAll(Collection coll)
- Appends all of the elements in the specified Collection to the
end of this this List, in the order that they are returned by
the specified Collection's Iterator. This operation
takes into account duplicate elements (for example, if the
specified collection contains duplicates, then they will be
appended multiple times to the end of this list.)
The behavior of this operation is unspecified if the specified
Collection is modified while the operation is in progress.
(Note that this will occur if the specified Collection is this
List, and it's nonempty.)
- Returns:
- true if this List changed as a result of the call.
- Throws: ClassCastException
- class of an element in the specified
Collection prevents it from being added to this List.
- Throws: IllegalArgumentException
- some aspect of an element in the
specified Collection prevents it from being added to this
List.
removeAll
public synchronized boolean removeAll(Collection coll)
- Removes from this List all of its elements that are contained
in the specified Collection. This operation takes into
account duplicate elements (that is, if an element appears
multiple times in the specified collection, it will be removed
multiple times from tis list). Elements are removed from the
tail of the list.
- Returns:
- true if this List changed as a result of the call.
retainAll
public synchronized boolean retainAll(Collection coll)
- Retains only the elements in this List that are contained in
the specified Collection. In other words,
removes from this List all of its elements that are not
contained in the specified Collection. Both this list and
the specified collection are treated as sets for the purposes
of this operation (that is, duplicate elements are ignored).
- Returns:
- true if this List changed as a result of the call.
clear
public void clear()
- Removes all of the elements from this List.
The List will be empty after this call returns.
get
public Object get(int index)
- Returns the element at the specified position in this List.
- Parameters:
- index - index of element to return.
- Throws: IndexOutOfBoundsException
- index is out of range (index
< 0 || index > = size()).
set
public synchronized Object set(int index,
Object obj)
- Replaces the element at the specified position in this List
with the specified element.
- Parameters:
- index - index of element to replace.
- element - element to be stored at the specified position.
- Returns:
- the element previously at the specified position.
- Throws: ClassCastException
- class of the specified element
prevents it from being added to this List.
- Throws: IllegalArgumentException
- some aspect of the specified
element prevents it from being added to this List.
- Throws: IndexOutOfBoundsException
- index out of range
(index < 0 || index >= size()).
add
public void add(int index,
Object obj)
- Inserts the specified element at the specified position in this
List. Shifts the element currently at
that position (if any) and any subsequent elements to the right
(adds one to their indices).
- Parameters:
- index - index at which the specified element is to be inserted.
- element - element to be inserted.
- Throws: ClassCastException
- class of the specified element
prevents it from being added to this List.
- Throws: IllegalArgumentException
- some aspect of the specified
element prevents it from being added to this List.
- Throws: IndexOutOfBoundsException
- index is out of range
(index < 0 || index > size()).
remove
public synchronized Object remove(int index)
- Removes the element at the specified position in this List.
Shifts any subsequent elements to the
left (subtracts one from their indices). Returns the element
that was removed from the List.
- Parameters:
- index - the index of the element to removed.
- Returns:
- the element previously at the specified position.
- Throws: IndexOutOfBoundsException
- index out of range (index
< 0 || index > = size()).
removeRange
public synchronized void removeRange(int from,
int to)
- Removes from this List all of the elements whose index is
between fromIndex, inclusive and toIndex, exclusive.
Shifts any succeeding elements to the left
(reduces their index). This call shortens the List by (toIndex
- fromIndex) elements. (If toIndex==fromIndex, this operation
has no effect.)
- Parameters:
- fromIndex - index of first element to be removed.
- toIndex - index after last element to be removed.
- Throws: IndexOutOfBoundsException
- fromIndex or toIndex out of
range (fromIndex < 0 || fromIndex >= size() || toIndex
> size() || toIndex < fromIndex).
addAll
public synchronized boolean addAll(int index,
Collection coll)
- Inserts all of the elements in in the specified Collection into
this List at the specified position.
Shifts the element currently at that position (if any) and any
subsequent elements to the right (increases their indices).
The new elements will appear in the List in the order that they
are returned by the specified Collection's iterator. The
behavior of this operation is unspecified if the specified
Collection is modified while the operation is in progress.
(Note that this will occur if the specified Collection is this
List, and it's nonempty.)
- Parameters:
- index - index at which to insert first element from the specified
Collection.
- c - elements to be inserted into this List.
- Returns:
- true if this List changed as a result of the call.
- Throws: ClassCastException
- class of one of elements of the specified
Collection prevents it from being added to this List.
- Throws: IllegalArgumentException
- some aspect of one of elements of
the specified Collection prevents it from being added to
this List.
- Throws: IndexOutOfBoundsException
- index out of range (index
< 0 || index > size()).
listIterator
public synchronized ListIterator listIterator()
- Returns a ListIterator of the elements in this List (in proper
sequence).
listIterator
public synchronized ListIterator listIterator(int index)
- Returns a ListIterator of the elements in this List (in proper
sequence), starting at the specified position in the List. The
specified index indicates the first element that would be
returned by an initial call to nextElement. An initial call to
previousElement would return the element with the specified
index minus one.
- Parameters:
- index - index of first element to be returned from the
ListIterator (by a call to getNext).
- Throws: IndexOutOfBoundsException
- index is out of range
(index < 0 || index > size()).
Copyright © 1996, 1997, 1998 Object Design, Inc. All rights reserved.