|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.AbstractStructure | +--structure.AbstractList | +--structure.Vector
An implementation of extensible arrays, similar to that of java.util.Vector
.
This vector class implements a basic extensible array. It does not implement
any of the additional features of the Sun class, including list-like operations.
Those operations are available in other implementors of List
in this
package.
Example usage: To put a program's parameters into a Vector, we would use the following:
public static void main(String[] arguments) {Vector
argVec = newVector()
; for (int i = 0; i < arguments.length; i++) { argVec.add(arguments[i])
; } System.out.println(argVec
); }
Field Summary | |
protected int |
capacityIncrement
The size of size increment, should the vector become full. |
protected static int |
defaultCapacity
The default size of the vector; may be overridden in the Vector(int) constructor. |
protected int |
elementCount
The actual number of elements logically stored within the vector. |
protected java.lang.Object[] |
elementData
The data associated with the vector. |
protected java.lang.Object |
initialValue
The initial value of any new elements that are appended to the vector. |
Constructor Summary | |
Vector()
Construct an empty vector. |
|
Vector(java.util.Collection c)
|
|
Vector(int initialCapacity)
Construct an empty vector capable of storing initialCapacity
values before the vector must be extended. |
|
Vector(int initialCapacity,
int capacityIncr)
Construct a vector with initial capacity, and growth characteristic. |
|
Vector(int initialCapacity,
int capacityIncr,
java.lang.Object initValue)
Construct a vector with initial size, growth rate and default value. |
|
Vector(Vector that)
|
Method Summary | |
void |
add(int index,
java.lang.Object obj)
Insert an element at a particular location. |
void |
add(java.lang.Object obj)
Add an element to the high end of the array, possibly expanding vector. |
void |
addElement(java.lang.Object o)
Add an element to the high end of the array, possibly expanding vector. |
int |
capacity()
Determine the capacity of the vector. |
void |
clear()
Remove all the values of the vector. |
java.lang.Object |
clone()
Construct a shallow copy of the vector. |
boolean |
contains(java.lang.Object elem)
Determine if a value appears in a vector. |
void |
copyInto(java.lang.Object[] dest)
Copy the contents of the vector into an array. |
java.lang.Object |
elementAt(int index)
Fetch the element at a particular index. |
void |
ensureCapacity(int minCapacity)
Ensure that the vector is capable of holding at least minCapacity values without expansion. |
java.lang.Object |
firstElement()
Get access to the first element of the vector. |
java.lang.Object |
get(int index)
Fetch the element at a particular index. |
int |
indexOf(java.lang.Object elem)
Assuming the data is not in order, find the index of a value, or return -1 if not found. |
int |
indexOf(java.lang.Object elem,
int index)
Assuming the data is not in order, find the index of a value or return -1 if the value is not found. |
void |
insertElementAt(java.lang.Object obj,
int index)
Insert an element at a particular location. |
boolean |
isEmpty()
Determine if the Vector contains no values. |
java.util.Iterator |
iterator()
Construct a iterator over the elements of the vector. |
java.lang.Object |
lastElement()
Fetch a reference to the last value in the vector. |
int |
lastIndexOf(java.lang.Object obj)
Search for the last occurrence of a value within the vector. |
int |
lastIndexOf(java.lang.Object obj,
int index)
Find the index of the last occurrence of the value in the vector before the indexth position. |
java.lang.Object |
remove(int where)
Remove an element at a particular location. |
java.lang.Object |
remove(java.lang.Object element)
Remove an element, by value, from vector. |
void |
removeAllElements()
Remove all the elements of the vector. |
void |
removeElementAt(int where)
Remove an element at a particular location. |
java.lang.Object |
set(int index,
java.lang.Object obj)
Change the value stored at location index. |
void |
setElementAt(java.lang.Object obj,
int index)
Change the value stored at location index. |
void |
setSize(int newSize)
Explicitly set the size of the array. |
int |
size()
Determine the number of elements in the vector. |
java.lang.String |
toString()
Determine a string representation for the vector. |
void |
trimToSize()
Trim the vector to exactly the correct size. |
Methods inherited from class structure.AbstractList |
addFirst, addLast, get, getFirst, getLast, remove, removeFirst, removeLast |
Methods inherited from class structure.AbstractStructure |
elements, hashCode, values |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure.Structure |
elements, values |
Field Detail |
protected java.lang.Object[] elementData
protected int elementCount
protected int capacityIncrement
protected java.lang.Object initialValue
protected static final int defaultCapacity
Vector(int)
constructor.
Constructor Detail |
public Vector()
public Vector(int initialCapacity)
initialCapacity
values before the vector must be extended.
initialCapacity
- The size of vector before reallocation is necessarypublic Vector(int initialCapacity, int capacityIncr)
initialCapacity
- The initial number of slots in vector.capacityIncr
- The size of growth of vector.capacityIncrement
public Vector(int initialCapacity, int capacityIncr, java.lang.Object initValue)
initialCapacity
- The initial number of slots in vector.capacityIncr
- The size of the increment when vector grows.initValue
- The initial value stored in vector elements.public Vector(Vector that)
public Vector(java.util.Collection c)
Method Detail |
public void ensureCapacity(int minCapacity)
minCapacity
- The minimum size of array before expansion.public void add(java.lang.Object obj)
add
in interface List
add
in class AbstractList
obj
- The object to be added to the end of the vector.AbstractList.addLast(java.lang.Object)
public void addElement(java.lang.Object o)
public java.lang.Object remove(java.lang.Object element)
remove
in interface List
element
- the element to be removed.
public int capacity()
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean contains(java.lang.Object elem)
contains
in interface List
contains
in class AbstractList
elem
- The value sought.
public void copyInto(java.lang.Object[] dest)
dest
- An array of size at least size().public java.lang.Object elementAt(int index)
index
- The index of the value sought.
public java.lang.Object get(int index)
get
in interface List
index
- The index of the value sought.
public java.util.Iterator iterator()
iterator
in interface List
public java.lang.Object firstElement()
public int indexOf(java.lang.Object elem)
indexOf
in interface List
elem
- The value sought in vector.
public int indexOf(java.lang.Object elem, int index)
elem
- The value sought.index
- The first location considered.
public void insertElementAt(java.lang.Object obj, int index)
obj
- The value to be inserted.index
- The location of the new value.public void add(int index, java.lang.Object obj)
add
in interface List
obj
- the value to be inserted.index
- the location of the new value.public boolean isEmpty()
isEmpty
in interface List
isEmpty
in class AbstractList
public java.lang.Object lastElement()
public int lastIndexOf(java.lang.Object obj)
lastIndexOf
in interface List
obj
- The value sought.
public int lastIndexOf(java.lang.Object obj, int index)
obj
- The value sought.index
- The last acceptable index.
public void clear()
clear
in interface List
public void removeAllElements()
clear()
public void removeElementAt(int where)
where
- The location of the element to be removed.public java.lang.Object remove(int where)
remove
in interface List
where
- The location of the element to be removed.
public void setElementAt(java.lang.Object obj, int index)
obj
- The new value to be stored.index
- The index of the new value.public java.lang.Object set(int index, java.lang.Object obj)
set
in interface List
obj
- The new value to be stored.index
- The index of the new value.
public void setSize(int newSize)
newSize
- The ultimate size of the vector.public int size()
size
in interface List
public void trimToSize()
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |