|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.AbstractStructure<ELTTYPE> structure.AbstractList<ELTTYPE> structure.Vector<ELTTYPE>
public class Vector<ELTTYPE>
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<String>
argVec = newVector<String>()
; for (int i = 0; i < arguments.length; i++) { argVec.add(arguments[i])
; } System.out.println(argVec
); }
Constructor Summary | |
---|---|
Vector()
Construct an empty vector. |
|
Vector(java.util.Collection<ELTTYPE> 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,
ELTTYPE initValue)
Construct a vector with initial size, growth rate and default value. |
|
Vector(Vector<ELTTYPE> that)
|
Method Summary | |
---|---|
void |
add(ELTTYPE obj)
Add an element to the high end of the array, possibly expanding vector. |
void |
add(int index,
ELTTYPE obj)
Insert an element at a particular location. |
void |
addElement(ELTTYPE 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(ELTTYPE elem)
Determine if a value appears in a vector. |
void |
copyInto(ELTTYPE[] dest)
Copy the contents of the vector into an array. |
ELTTYPE |
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. |
ELTTYPE |
firstElement()
Get access to the first element of the vector. |
ELTTYPE |
get(int index)
Fetch the element at a particular index. |
int |
indexOf(ELTTYPE elem)
Assuming the data is not in order, find the index of a value, or return -1 if not found. |
int |
indexOf(ELTTYPE 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(ELTTYPE obj,
int index)
Insert an element at a particular location. |
boolean |
isEmpty()
Determine if the Vector contains no values. |
java.util.Iterator<ELTTYPE> |
iterator()
Construct a iterator over the elements of the vector. |
ELTTYPE |
lastElement()
Fetch a reference to the last value in the vector. |
int |
lastIndexOf(ELTTYPE obj)
Search for the last occurrence of a value within the vector. |
int |
lastIndexOf(ELTTYPE obj,
int index)
Find the index of the last occurrence of the value in the vector before the indexth position. |
ELTTYPE |
remove(ELTTYPE element)
Remove an element, by value, from vector. |
ELTTYPE |
remove(int where)
Remove an element at a particular location. |
void |
removeAllElements()
Remove all the elements of the vector. |
void |
removeElementAt(int where)
Remove an element at a particular location. |
ELTTYPE |
set(int index,
ELTTYPE obj)
Change the value stored at location index. |
void |
setElementAt(ELTTYPE 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, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure.Structure |
---|
elements, values |
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, ELTTYPE 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<ELTTYPE> that)
public Vector(java.util.Collection<ELTTYPE> c)
Method Detail |
---|
public void ensureCapacity(int minCapacity)
minCapacity
- The minimum size of array before expansion.public void add(ELTTYPE obj)
add
in interface List<ELTTYPE>
add
in interface Structure<ELTTYPE>
add
in class AbstractList<ELTTYPE>
obj
- The object to be added to the end of the vector.AbstractList.addLast(ELTTYPE)
public void addElement(ELTTYPE o)
obj
- The object to be added to the end of the vector.public ELTTYPE remove(ELTTYPE element)
remove
in interface List<ELTTYPE>
remove
in interface Structure<ELTTYPE>
element
- the element to be removed.
public int capacity()
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean contains(ELTTYPE elem)
contains
in interface List<ELTTYPE>
contains
in interface Structure<ELTTYPE>
contains
in class AbstractList<ELTTYPE>
elem
- The value sought.
public void copyInto(ELTTYPE[] dest)
dest
- An array of size at least size().public ELTTYPE elementAt(int index)
index
- The index of the value sought.
public ELTTYPE get(int index)
get
in interface List<ELTTYPE>
index
- The index of the value sought.
public java.util.Iterator<ELTTYPE> iterator()
iterator
in interface java.lang.Iterable<ELTTYPE>
iterator
in interface List<ELTTYPE>
iterator
in interface Structure<ELTTYPE>
AbstractIterator
,
Iterator
,
Enumeration
,
Structure.elements()
public ELTTYPE firstElement()
public int indexOf(ELTTYPE elem)
indexOf
in interface List<ELTTYPE>
elem
- The value sought in vector.
public int indexOf(ELTTYPE elem, int index)
elem
- The value sought.index
- The first location considered.
public void insertElementAt(ELTTYPE obj, int index)
obj
- The value to be inserted.index
- The location of the new value.public void add(int index, ELTTYPE obj)
add
in interface List<ELTTYPE>
obj
- the value to be inserted.index
- the location of the new value.public boolean isEmpty()
isEmpty
in interface List<ELTTYPE>
isEmpty
in interface Structure<ELTTYPE>
isEmpty
in class AbstractList<ELTTYPE>
public ELTTYPE lastElement()
public int lastIndexOf(ELTTYPE obj)
lastIndexOf
in interface List<ELTTYPE>
obj
- The value sought.
public int lastIndexOf(ELTTYPE obj, int index)
obj
- The value sought.index
- The last acceptable index.
public void clear()
clear
in interface List<ELTTYPE>
clear
in interface Structure<ELTTYPE>
public void removeAllElements()
clear()
public void removeElementAt(int where)
where
- The location of the element to be removed.public ELTTYPE remove(int where)
remove
in interface List<ELTTYPE>
where
- The location of the element to be removed.
public void setElementAt(ELTTYPE obj, int index)
obj
- The new value to be stored.index
- The index of the new value.public ELTTYPE set(int index, ELTTYPE obj)
set
in interface List<ELTTYPE>
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<ELTTYPE>
size
in interface Structure<ELTTYPE>
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 |