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.


Constructor Index

 o Vector()
Construct an empty vector.
 o Vector(int)
Construct an empty vector capable of storing initial capacity values before the vector must be extended.
 o Vector(int, int)
Construct a vector with initial capacity, and growth characteristic.
 o Vector(int, int, Object)
Construct a vector with initial size, growth rate and default value.

Method Index

 o addElement(Object)
Add an element to the high end of the array, possibly expanding vector.
 o capacity()
Determine the capacity of the vector.
 o clear()
Remove all the values of the vector.
 o clone()
Construct a shallow copy of the vector.
 o contains(Object)
Determine if a value appears in a vector.
 o copyInto(Object[])
Copy the contents of the vector into an array.
 o elementAt(int)
Fetch the element at a particular index.
 o elements()
Construct an iterator over the elements of the vector.
 o ensureCapacity(int)
Ensure that the vector is capable of holding at least minCapacity values without expansion.
 o firstElement()
Get access to the first element of the vector.
 o indexOf(Object)
Assuming the data is not in order, find the index of a value, or return -1 if not found.
 o 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.
 o insertElementAt(Object, int)
Insert an element at a particular location.
 o isEmpty()
Determine if the Vector contains no values.
 o lastElement()
Fetch a reference to the last value in the vector.
 o lastIndexOf(Object)
Search for the last occurrence of a value within the vector.
 o lastIndexOf(Object, int)
Find the index of the last occurrence of the value in the vector before the indexth position.
 o removeAllElements()
Remove all the elements of the vector.
 o removeElement(Object)
Remove an element, by value, from vector.
 o removeElementAt(int)
Remove an element at a particular location.
 o setElementAt(Object, int)
Change the value stored at location index.
 o setSize(int)
Explicitly set the size of the array.
 o size()
Determine the number of elements in the vector.
 o toString()
Determine a string representation for the vector.
 o trimToSize()
Trim the vector to exactly the correct size.

Constructors

 o Vector
public Vector()
Construct an empty vector.

Postcondition:
constructs a vector with capacity for 10 elements

 o 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
 o 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.
 o 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.

Methods

 o 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.
 o 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.
 o 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.
 o 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
 o 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.
 o 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().
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o clear
public void clear()
Remove all the values of the vector.

Postcondition:
vector is empty

 o 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
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o trimToSize
public void trimToSize()
Trim the vector to exactly the correct size.

Postcondition:
minimizes allocated size of vector

 o 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