public class Vector extends AbstractList implements List, java.util.RandomAccess, java.lang.Cloneable, java.io.Serializable, Rollbackable
Vector
classes implements growable arrays of Objects.
You can access elements in a Vector with an index, just as you
can in a built in array, but Vectors can grow and shrink to accommodate
more or fewer objects.
Vectors try to mantain efficiency in growing by having a
capacityIncrement
that can be specified at instantiation.
When a Vector can no longer hold a new Object, it grows by the amount
in capacityIncrement
. If this value is 0, the vector doubles in
size.
Vector implements the JDK 1.2 List interface, and is therefore a fully compliant Collection object. The iterators are fail-fast - if external code structurally modifies the vector, any operation on the iterator will then throw a {
Collection
,
List
,
ArrayList
,
LinkedList
,
Serialized Form$CHECKPOINT, $RECORD$$CHECKPOINT
Constructor and Description |
---|
Vector()
Constructs an empty vector with an initial size of 10, and
a capacity increment of 0
|
Vector(Collection c)
Constructs a vector containing the contents of Collection, in the
order given by the collection.
|
Vector(int initialCapacity)
Constructs a Vector with the initial capacity specified, and a capacity
increment of 0 (double in size).
|
Vector(int initialCapacity,
int capacityIncrement)
Constructs a Vector with the initial capacity and capacity
increment specified.
|
Modifier and Type | Method and Description |
---|---|
void |
$COMMIT(long timestamp)
Commit changes up to the given timestamp, but not including changes
made at timestamp and afterward.
|
void |
$RESTORE(long timestamp,
boolean trim)
Restore a previous state to all the private fields of this rollbackable
object.
|
void |
add(int index,
java.lang.Object element)
Adds an object at the specified index.
|
boolean |
add(java.lang.Object o)
Adds an object to the Vector.
|
boolean |
addAll(Collection c)
Appends all elements of the given collection to the end of this Vector.
|
boolean |
addAll(int index,
Collection c)
Inserts all elements of the given collection at the given index of
this Vector.
|
void |
addElement(java.lang.Object obj)
Adds an element to the Vector at the end of the Vector.
|
int |
capacity()
Returns the size of the internal data array (not the amount of elements
contained in the Vector).
|
void |
clear()
Clears all elements in the Vector and sets its size to 0.
|
java.lang.Object |
clone()
Creates a new Vector with the same contents as this one.
|
boolean |
contains(java.lang.Object elem)
Returns true when
elem is contained in this Vector. |
boolean |
containsAll(Collection c)
Returns true if this Vector contains all the elements in c.
|
void |
copyInto(java.lang.Object[] a)
Copies the contents of the Vector into the provided array.
|
java.lang.Object |
elementAt(int index)
Returns the Object stored at
index . |
java.util.Enumeration |
elements()
Returns an Enumeration of the elements of this Vector.
|
void |
ensureCapacity(int minCapacity)
Ensures that
minCapacity elements can fit within this Vector. |
boolean |
equals(java.lang.Object o)
Compares this to the given object.
|
java.lang.Object |
firstElement()
Returns the first element (index 0) in the Vector.
|
java.lang.Object |
get(int index)
Returns the element at position
index . |
protected int |
getCapacityIncrement() |
protected int |
getElementCount() |
protected java.lang.Object[] |
getElementData() |
int |
hashCode()
Computes the hashcode of this object.
|
int |
indexOf(java.lang.Object elem)
Returns the first occurrence of
elem in the Vector, or -1 if
elem is not found. |
int |
indexOf(java.lang.Object e,
int index)
Searches the vector starting at
index for object
elem and returns the index of the first occurrence of this
Object. |
void |
insertElementAt(java.lang.Object obj,
int index)
Inserts a new element into the Vector at
index . |
boolean |
isEmpty()
Returns true if this Vector is empty, false otherwise
|
java.lang.Object |
lastElement()
Returns the last element in the Vector.
|
int |
lastIndexOf(java.lang.Object elem)
Returns the last index of
elem within this Vector, or -1
if the object is not within the Vector. |
int |
lastIndexOf(java.lang.Object e,
int index)
Returns the index of the first occurrence of
elem , when
searching backwards from index . |
java.lang.Object |
remove(int index)
Removes the element at the specified index, and returns it.
|
boolean |
remove(java.lang.Object o)
Removes the given Object from the Vector.
|
boolean |
removeAll(Collection c)
Remove from this vector all elements contained in the given collection.
|
void |
removeAllElements()
Removes all elements from the Vector.
|
boolean |
removeElement(java.lang.Object obj)
Removes the first (the lowestindex) occurance of the given object from
the Vector.
|
void |
removeElementAt(int index)
Removes the element at
index , and shifts all elements at
positions greater than index to their index - 1. |
protected void |
removeRange(int fromIndex,
int toIndex)
Removes a range of elements from this list.
|
boolean |
retainAll(Collection c)
Retain in this vector only the elements contained in the given collection.
|
java.lang.Object |
set(int index,
java.lang.Object element)
Puts
element into the Vector at position index
and returns the Object that previously occupied that position. |
protected void |
setCapacityIncrement(int capacityIncrement) |
void |
setElementAt(java.lang.Object obj,
int index)
Changes the element at
index to be obj |
protected int |
setElementCount(int elementCount) |
protected void |
setElementData(java.lang.Object[] elementData) |
void |
setSize(int newSize)
Explicitly sets the size of the vector (but not necessarily the size of
the internal data array).
|
int |
size()
Returns the number of elements stored in this Vector.
|
List |
subList(int fromIndex,
int toIndex)
Obtain a List view of a subsection of this list, from fromIndex
(inclusive) to toIndex (exclusive).
|
java.lang.Object[] |
toArray()
Returns an Object array with the contents of this Vector, in the order
they are stored within this Vector.
|
java.lang.Object[] |
toArray(java.lang.Object[] a)
Returns an array containing the contents of this Vector.
|
java.lang.String |
toString()
Returns a string representation of this Vector in the form
"[element0, element1, ...
|
void |
trimToSize()
Trims the Vector down to size.
|
getModCount, iterator, listIterator, listIterator, setModCount
$GET$CHECKPOINT, $SET$CHECKPOINT
finalize, getClass, notify, notifyAll, wait, wait, wait
$GET$CHECKPOINT, $SET$CHECKPOINT, iterator, listIterator, listIterator
public Vector()
public Vector(Collection c)
c
- collection of elements to add to the new vectorjava.lang.NullPointerException
- if c is nullpublic Vector(int initialCapacity, int capacityIncrement)
initialCapacity
- the initial size of the Vector's internal arraycapacityIncrement
- the amount the internal array should be
increased by when necessary, 0 to double the sizejava.lang.IllegalArgumentException
- if initialCapacity < 0public Vector(int initialCapacity)
initialCapacity
- the initial size of the Vector's internal arrayjava.lang.IllegalArgumentException
- if initialCapacity < 0public void copyInto(java.lang.Object[] a)
a
- target array for the copyjava.lang.IndexOutOfBoundsException
- the array is not large enoughjava.lang.NullPointerException
- the array is nulltoArray(Object[])
public void trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity
elements can fit within this Vector.
If elementData
is too small, it is expanded as follows:
If the elementCount + capacityIncrement
is adequate, that
is the new size. If capacityIncrement
is non-zero, the
candidate size is double the current. If that is not enough, the new
size is minCapacity
.minCapacity
- the desired minimum capacity, negative values ignoredpublic void setSize(int newSize)
newSize
- The new size of the internal arrayjava.lang.ArrayIndexOutOfBoundsException
- if the new size is negativepublic int capacity()
public int size()
size
in interface Collection
size
in interface List
size
in class AbstractCollection
public boolean isEmpty()
isEmpty
in interface Collection
isEmpty
in interface List
isEmpty
in class AbstractCollection
AbstractCollection.size()
public java.util.Enumeration elements()
AbstractList.iterator()
public boolean contains(java.lang.Object elem)
elem
is contained in this Vector.contains
in interface Collection
contains
in interface List
contains
in class AbstractCollection
elem
- the element to checkpublic int indexOf(java.lang.Object elem)
elem
in the Vector, or -1 if
elem
is not found.indexOf
in interface List
indexOf
in class AbstractList
elem
- the object to search forpublic int indexOf(java.lang.Object e, int index)
index
for object
elem
and returns the index of the first occurrence of this
Object. If the object is not found, or index is larger than the size
of the vector, -1 is returned.e
- the Object to search forindex
- start searching at this indexjava.lang.IndexOutOfBoundsException
- if index < 0public int lastIndexOf(java.lang.Object elem)
elem
within this Vector, or -1
if the object is not within the Vector.lastIndexOf
in interface List
lastIndexOf
in class AbstractList
elem
- the object to search forpublic int lastIndexOf(java.lang.Object e, int index)
elem
, when
searching backwards from index
. If the object does not
occur in this Vector, or index is less than 0, -1 is returned.e
- the object to search forindex
- the index to start searching in reverse fromjava.lang.IndexOutOfBoundsException
- if index >= size()public java.lang.Object elementAt(int index)
index
.index
- the index of the Object to retrieveindex
java.lang.ArrayIndexOutOfBoundsException
- index < 0 || index >= size()get(int)
public java.lang.Object firstElement()
java.util.NoSuchElementException
- the Vector is emptypublic java.lang.Object lastElement()
java.util.NoSuchElementException
- the Vector is emptypublic void setElementAt(java.lang.Object obj, int index)
index
to be obj
obj
- the object to storeindex
- the position in the Vector to store the objectjava.lang.ArrayIndexOutOfBoundsException
- the index is out of rangeset(int, Object)
public void removeElementAt(int index)
index
, and shifts all elements at
positions greater than index to their index - 1.index
- the index of the element to removejava.lang.ArrayIndexOutOfBoundsException
- index < 0 || index >= size();remove(int)
public void insertElementAt(java.lang.Object obj, int index)
index
. Any elements
at or greater than index are shifted up one position.obj
- the object to insertindex
- the index at which the object is insertedjava.lang.ArrayIndexOutOfBoundsException
- index < 0 || index > size()add(int, Object)
public void addElement(java.lang.Object obj)
obj
- the object to add to the Vectorpublic boolean removeElement(java.lang.Object obj)
obj
- the object to remove from the Vectorremove(Object)
public void removeAllElements()
clear()
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.Object[] toArray()
toArray
in interface Collection
toArray
in interface List
toArray
in class AbstractCollection
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface Collection
toArray
in interface List
toArray
in class AbstractCollection
a
- an array to copy the Vector into if large enoughjava.lang.ArrayStoreException
- the runtime type of the provided array
cannot hold the elements of the Vectorjava.lang.NullPointerException
- if a
is nullpublic java.lang.Object get(int index)
index
.get
in interface List
get
in class AbstractList
index
- the position from which an element will be retrievedjava.lang.ArrayIndexOutOfBoundsException
- index < 0 || index >= size()public java.lang.Object set(int index, java.lang.Object element)
element
into the Vector at position index
and returns the Object that previously occupied that position.set
in interface List
set
in class AbstractList
index
- the index within the Vector to place the Objectelement
- the Object to store in the Vectorjava.lang.ArrayIndexOutOfBoundsException
- index < 0 || index >= size()public boolean add(java.lang.Object o)
add
in interface Collection
add
in interface List
add
in class AbstractList
o
- the element to add to the VectorAbstractList.add(int, Object)
public boolean remove(java.lang.Object o)
remove
in interface Collection
remove
in interface List
remove
in class AbstractCollection
o
- the object to remove from the VectorIterator.remove()
public void add(int index, java.lang.Object element)
add
in interface List
add
in class AbstractList
index
- the index at which to add the elementelement
- the element to add to the Vectorjava.lang.ArrayIndexOutOfBoundsException
- index < 0 || index > size()AbstractList.modCount
public java.lang.Object remove(int index)
remove
in interface List
remove
in class AbstractList
index
- the position from which to remove the elementjava.lang.ArrayIndexOutOfBoundsException
- index < 0 || index >= size()AbstractList.modCount
public void clear()
clear
in interface Collection
clear
in interface List
clear
in class AbstractList
AbstractList.remove(int)
,
AbstractList.removeRange(int, int)
public boolean containsAll(Collection c)
containsAll
in interface Collection
containsAll
in interface List
containsAll
in class AbstractCollection
c
- the collection to compare tojava.lang.NullPointerException
- if c is nullAbstractCollection.contains(Object)
public boolean addAll(Collection c)
addAll
in interface Collection
addAll
in interface List
addAll
in class AbstractCollection
c
- the collection to appendjava.lang.NullPointerException
- if c is nullAbstractCollection.add(Object)
public boolean removeAll(Collection c)
removeAll
in interface Collection
removeAll
in interface List
removeAll
in class AbstractCollection
c
- the collection to filter outjava.lang.NullPointerException
- if c is nullIterator.remove()
public boolean retainAll(Collection c)
retainAll
in interface Collection
retainAll
in interface List
retainAll
in class AbstractCollection
c
- the collection to filter byjava.lang.NullPointerException
- if c is nullIterator.remove()
public boolean addAll(int index, Collection c)
addAll
in interface List
addAll
in class AbstractList
c
- the collection to appendindex
- the location to insert the collectionjava.lang.NullPointerException
- if c is nulljava.lang.ArrayIndexOutOfBoundsException
- index < 0 || index > size()AbstractList.add(int, Object)
public boolean equals(java.lang.Object o)
equals
in interface Collection
equals
in interface List
equals
in class AbstractList
o
- the object to compare toObject.equals(Object)
,
AbstractList.hashCode()
public int hashCode()
hashCode
in interface Collection
hashCode
in interface List
hashCode
in class AbstractList
Object.hashCode()
,
AbstractList.equals(Object)
public java.lang.String toString()
toString
in class AbstractCollection
public List subList(int fromIndex, int toIndex)
subList
in interface List
subList
in class AbstractList
fromIndex
- the index that the returned list should start from
(inclusive)toIndex
- the index that the returned list should go to (exclusive)java.lang.IndexOutOfBoundsException
- if fromIndex < 0
|| toIndex > size()java.lang.IllegalArgumentException
- if fromIndex > toIndexConcurrentModificationException
protected void removeRange(int fromIndex, int toIndex)
removeRange
in class AbstractList
fromIndex
- the index to start deleting from (inclusive)toIndex
- the index to delete up to (exclusive)java.lang.IndexOutOfBoundsException
- if fromIndex > toIndexprotected void setCapacityIncrement(int capacityIncrement)
protected int getCapacityIncrement()
protected int setElementCount(int elementCount)
protected int getElementCount()
protected void setElementData(java.lang.Object[] elementData)
protected java.lang.Object[] getElementData()
public void $COMMIT(long timestamp)
Rollbackable
$COMMIT
in interface Rollbackable
$COMMIT
in interface Collection
$COMMIT
in interface List
$COMMIT
in class AbstractList
timestamp
- The timestamp.public void $RESTORE(long timestamp, boolean trim)
Rollbackable
$RESTORE
in interface Rollbackable
$RESTORE
in interface Collection
$RESTORE
in interface List
$RESTORE
in class AbstractList
timestamp
- The timestamp taken at the time when the previous
state was recorded.trim
- Whether to delete the records used for the rollback.Checkpoint.rollback(long, boolean)