structure
Class VectorIterator
java.lang.Object
|
+--structure.AbstractIterator
|
+--structure.VectorIterator
- All Implemented Interfaces:
- Enumeration, Iterator
- class VectorIterator
- extends AbstractIterator
A private class for implementing an iterator over a Vector.
Typical usage:
import structure.Vector;
import java.util.Iterator;
public static void main(String[] args)
{
Vector argVec = new Vector();
for (int i = 0; i < args.length; i++)
{
argVec.addElement(args[i]);
}
Iterator it = argVec.iterator();
while (it.hasNext())
{
System.out.println(it.next());
}
}
Field Summary |
protected int |
current
The index of the current value. |
protected Vector |
theVector
The associated vector |
Method Summary |
Object |
get()
Fetch a reference to the current value. |
boolean |
hasNext()
Determine if some of the elements have yet to be considered. |
Object |
next()
Return current value, and increment iterator. |
void |
reset()
Reset the vector iterator to the first value in the vector. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
theVector
protected Vector theVector
- The associated vector
current
protected int current
- The index of the current value.
VectorIterator
public VectorIterator(Vector v)
- Construct a vector iterator to traverse vector v
- Parameters:
v
- The underlying vector.
reset
public void reset()
- Reset the vector iterator to the first value in the vector.
- Overrides:
reset
in class AbstractIterator
- Postcondition:
- the iterator is reset to the beginning of the traversal
hasNext
public boolean hasNext()
- Determine if some of the elements have yet to be considered.
- Overrides:
hasNext
in class AbstractIterator
- Postcondition:
- returns true if there is more structure to be traversed
- Returns:
- True if more elements are to be considered.
get
public Object get()
- Fetch a reference to the current value.
- Overrides:
get
in class AbstractIterator
- Precondition:
- traversal has more elements
- Postcondition:
- returns the current value referenced by the iterator
- Returns:
- A reference to the current value being considered.
next
public Object next()
- Return current value, and increment iterator.
- Overrides:
next
in class AbstractIterator
- Precondition:
- traversal has more elements
- Postcondition:
- increments the iterated traversal
- Returns:
- A reference to the current value, before increment.