All Packages Class Hierarchy This Package Previous Next Index
Class structure.Vector
java.lang.Object
|
+----structure.Vector
- public class Vector
- extends Object
- implements Cloneable
An implementation of vectors, similar to that found in java.util.Vector.
Vector()
- Construct an empty vector.
Vector(int)
- Construct an empty vector capable of storing initial capacity
values before the vector must be extended.
Vector(int, int)
- Construct a vector with initial capacity, and growth characteristic.
Vector(int, int, Object)
- Construct a vector with initial size, growth rate and default
value.
addElement(Object)
- Add an element to the high end of the array, possibly expanding
vector.
capacity()
- Determine the capacity of the vector.
clear()
- Remove all the values of the vector.
clone()
- Construct a shallow copy of the vector.
contains(Object)
- Determine if a value appears in a vector.
copyInto(Object[])
- Copy the contents of the vector into an array.
elementAt(int)
- Fetch the element at a particular index.
elements()
- Construct an iterator over the elements of the vector.
ensureCapacity(int)
- Ensure that the vector is capable of holding at least
minCapacity values without expansion.
firstElement()
- Get access to the first element of the vector.
indexOf(Object)
- Assuming the data is not in order, find the index of a
value, or return -1 if not found.
indexOf(Object, int)
- Assuming the data is not in order, find the index of a value
or return -1 if the value is not found.
insertElementAt(Object, int)
- Insert an element at a particular location.
isEmpty()
- Determine if the Vector contains no values.
lastElement()
- Fetch a reference to the last value in the vector.
lastIndexOf(Object)
- Search for the last occurrence of a value within the
vector.
lastIndexOf(Object, int)
- Find the index of the last occurrence of the value in the vector before
the indexth position.
removeAllElements()
- Remove all the elements of the vector.
removeElement(Object)
- Remove an element, by value, from vector.
removeElementAt(int)
- Remove an element at a particular location.
setElementAt(Object, int)
- Change the value stored at location index.
setSize(int)
- Explicitly set the size of the array.
size()
- Determine the number of elements in the vector.
toString()
- Determine a string representation for the vector.
trimToSize()
- Trim the vector to exactly the correct size.
Vector
public Vector()
- Construct an empty vector.
- Postcondition:
- constructs a vector with capacity for 10 elements
Vector
public Vector(int initialCapacity)
- Construct an empty vector capable of storing initial capacity
values before the vector must be extended.
- Precondition:
- initialCapacity >= 0
- Postcondition:
- constructs an empty vector with initialCapacity capacity
- Parameters:
- initialCapacity - The size of vector before reallocation is necessary
Vector
public Vector(int initialCapacity,
int capacityIncr)
- Construct a vector with initial capacity, and growth characteristic.
- Precondition:
- initialCapacity >= 0, capacityIncr >= 0
- Postcondition:
- constructs an empty vector with initialCapacity capacity
that extends capacity by capacityIncr, or doubles if 0
- Parameters:
- initialCapacity - The initial number of slots in vector.
- capacityIncr - The size of growth of vector.
Vector
public Vector(int initialCapacity,
int capacityIncr,
Object initValue)
- Construct a vector with initial size, growth rate and default
value.
- Precondition:
- initialCapacity, capacityIncr >= 0
- Postcondition:
- constructs empty vector with capacity that begins at
initialCapacity and extends by capacityIncr or doubles
if 0. New entries in vector are initialized to initValue.
- Parameters:
- 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.
ensureCapacity
public void ensureCapacity(int minCapacity)
- Ensure that the vector is capable of holding at least
minCapacity values without expansion.
- Postcondition:
- the capacity of this vector is at least minCapacity.
- Parameters:
- minCapacity - The minimum size of array before expansion.
addElement
public void addElement(Object obj)
- Add an element to the high end of the array, possibly expanding
vector.
- Postcondition:
- adds new element to end of possibly extended vector
- Parameters:
- obj - The object to be added to the end of the vector.
capacity
public int capacity()
- Determine the capacity of the vector. The capacity is always
at least as large as its size.
- Postcondition:
- returns allocated size of the vector
- Returns:
- The size of the array underlying the vector.
clone
public Object clone()
- Construct a shallow copy of the vector. The vector
store is copied, but the individual elements are shared
objects.
- Postcondition:
- returns a copy of the vector, using same objects.
- Returns:
- A copy of the original vector.
- Overrides:
- clone in class Object
contains
public boolean contains(Object elem)
- Determine if a value appears in a vector.
- Postcondition:
- returns true iff Vector contains the value
(could be faster, if orderedVector is used)
- Parameters:
- elem - The value sought.
- Returns:
- True iff the value appears in the vector.
copyInto
public void copyInto(Object[] dest)
- Copy the contents of the vector into an array.
The array must be large enough to accept all the values in
the vector.
- Precondition:
- dest has at least size() elements
- Postcondition:
- a copy of the vector is stored in the dest array
- Parameters:
- dest - An array of size at least size().
elementAt
public Object elementAt(int index)
- Fetch the element at a particular index.
The index of the first element is zero.
- Precondition:
- 0 <= index && index < size()
- Postcondition:
- returns the element stored in location index
- Parameters:
- index - The index of the value sought.
- Returns:
- A reference to the value found in the vector.
elements
public Iterator elements()
- Construct an iterator over the elements of the vector.
The iterator considers elements with increasing
index.
- Postcondition:
- returns an iterator (ordered enumeration) allowing one to
view elements of vector
- Returns:
- An iterator to traverse the vector.
firstElement
public Object firstElement()
- Get access to the first element of the vector.
- Precondition:
- vector contains an element
- Postcondition:
- returns first value in vector
- Returns:
- Access to the first element of the vector.
indexOf
public int indexOf(Object elem)
- Assuming the data is not in order, find the index of a
value, or return -1 if not found.
- Postcondition:
- returns index of element equal to object, or -1. Starts at 0.
- Parameters:
- elem - The value sought in vector.
- Returns:
- The index of the first occurrence of the value.
indexOf
public int indexOf(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. Search starts at index.
- Postcondition:
- returns index of element equal to object, or -1. Starts at index.
- Parameters:
- elem - The value sought.
- index - The first location considered.
- Returns:
- The index of the first location, or -1 if not found.
insertElementAt
public void insertElementAt(Object obj,
int index)
- Insert an element at a particular location.
Vector is grown as needed
- Precondition:
- 0 <= index <= size()
- Postcondition:
- inserts new value in vector with desired index,
moving elements from index to size()-1 to right
- Parameters:
- obj - The value to be inserted.
- index - The location of the new value.
isEmpty
public boolean isEmpty()
- Determine if the Vector contains no values.
- Postcondition:
- returns true iff there are no elements in the vector
- Returns:
- True iff the vector is empty.
lastElement
public Object lastElement()
- Fetch a reference to the last value in the vector.
- Precondition:
- vector is not empty
- Postcondition:
- returns last element of the vector
- Returns:
- A reference to the last value.
lastIndexOf
public int lastIndexOf(Object obj)
- Search for the last occurrence of a value within the
vector. If none is found, return -1.
- Postcondition:
- returns index of last occurrence of object in the vector, or -1
- Parameters:
- obj - The value sought.
- Returns:
- The index of the last occurrence in the vector.
lastIndexOf
public int lastIndexOf(Object obj,
int index)
- Find the index of the last occurrence of the value in the vector before
the indexth position.
- Precondition:
- index >= 0
- Postcondition:
- returns the index of last occurrence of object at or before
index.
- Parameters:
- obj - The value sought.
- index - The last acceptable index.
- Returns:
- The index of the last occurrence of the value, or -1 if none.
clear
public void clear()
- Remove all the values of the vector.
- Postcondition:
- vector is empty
removeAllElements
public void removeAllElements()
- Remove all the elements of the vector.
Kept for compatibility with java.util.Vector.
- Postcondition:
- vector is empty
- See Also:
- clear
removeElement
public boolean removeElement(Object element)
- Remove an element, by value, from vector.
- Postcondition:
- element equal to parameter is removed
- Parameters:
- element - The element to be removed.
- Returns:
- The element actually removed, or if none, null.
removeElementAt
public void removeElementAt(int where)
- Remove an element at a particular location.
- Precondition:
- 0 <= where && where < size()
- Postcondition:
- indicated element is removed, size decreases by 1
- Parameters:
- where - The location of the element to be removed.
setElementAt
public void setElementAt(Object obj,
int index)
- Change the value stored at location index.
- Precondition:
- 0 <= index && index < size()
- Postcondition:
- element value is changed to obj
- Parameters:
- obj - The new value to be stored.
- index - The index of the new value.
setSize
public void setSize(int newSize)
- Explicitly set the size of the array.
Any new elements are initialized to the default value.
- Precondition:
- newSize >= 0
- Postcondition:
- vector is resized, any new elements are initialized
- Parameters:
- newSize - The ultimate size of the vector.
size
public int size()
- Determine the number of elements in the vector.
- Postcondition:
- returns the size of the vector
- Returns:
- The number of elements within the vector.
trimToSize
public void trimToSize()
- Trim the vector to exactly the correct size.
- Postcondition:
- minimizes allocated size of vector
toString
public String toString()
- Determine a string representation for the vector.
- Postcondition:
- returns a string representation of vector
- Returns:
- A string representation for the vector.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index