public class ObjectVector extends Object implements Cloneable
This version is based on a "realloc" strategy -- a simle array is used, and when more storage is needed, a larger array is obtained and all existing data is recopied into it. As a result, read/write access to existing nodes is O(1) fast but appending may be O(N**2) slow.
| Modifier and Type | Field and Description |
|---|---|
protected int |
m_blocksize
Size of blocks to allocate
|
protected int |
m_firstFree
Number of ints in array
|
protected Object[] |
m_map
Array of objects
|
protected int |
m_mapSize
Size of array
|
| Constructor and Description |
|---|
ObjectVector(int blocksize,
int increaseSize)
Construct a IntVector, using the given block size.
|
ObjectVector(ObjectVector v)
Copy constructor for ObjectVector
|
| Modifier and Type | Method and Description |
|---|---|
void |
addElement(Object value)
Append an object onto the vector.
|
Object |
clone() |
Object |
elementAt(int i)
Get the nth element.
|
void |
setElementAt(Object value,
int index)
Sets the component at the specified index of this vector to be the specified object.
|
void |
setToSize(int size) |
int |
size()
Get the length of the list.
|
protected final int m_blocksize
protected Object[] m_map
protected int m_firstFree
protected int m_mapSize
public ObjectVector(int blocksize,
int increaseSize)
blocksize - Size of block to allocateincreaseSize - the size to incpublic ObjectVector(ObjectVector v)
v - Existing ObjectVector to copypublic final int size()
public final void addElement(Object value)
value - Object to add to the listpublic final void setElementAt(Object value, int index)
The index must be a value greater than or equal to 0 and less than the current size of the vector.
value - object to setindex - Index of where to set the objectpublic final Object elementAt(int i)
i - index of object to getpublic final void setToSize(int size)
public Object clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionCopyright © 2022. All rights reserved.