package com.ericfeminella.commons.collections
{
/**
*
* Concrete <code>IIterator</code> implementation which provides
* an API for iterating over a <code>Vector</code>.
*
* @example The following demonstrates a basic example of a
* <code>VectorIterator</code> instance which is to be iterated
* over by a <code>VectorIterator</code>.
*
* <listing version="3.0" >
*
* var personalNames:Vector.<PersonalName> = new Vector.<PersonalName>();
* personalNames.push( new PersonalName( "Eric", "Feminella" ) );
* personalNames.push( new PersonalName( "Christopher", "Feminella" ) );
* personalNames.push( new PersonalName( "Anthony", "Feminella" ) );
*
* var it:IIterator = new VectorIterator( personalNames );
*
* while ( it.hasNext() )
* {
* trace( it.next().toString() );
* }
*
* // outputs:
* // Feminella, Eric
* // Feminella, Christopher
* // Feminella, Anthony
*
* </listing>
*
* @see com.ericfeminella.collections.IIterator
*
*/
public class VectorIterator implements Iterator
{
/**
*
* <code>Vector</code> in which the <code>VectorIterator</code>
* is to traverse.
*
*/
private var _vector:* = null;
/**
*
* Defines the index in which the <code>VectorIterator</code>
* is to be traversed at.
*
*/
private var _index:int = 0;
/**
*
* Instantiates a new <code>VectorIterator</code> instance.
*
* @param <code>Vector</code> in which to iterate over
*
*/
public function VectorIterator(vector:*)
{
_vector = vector;
}
/**
*
* Determines if elements remain in the <code>Vector</code>.
*
* @inheritDoc
*
*/
public function hasNext() : Boolean
{
return _index < _vector.length;
}
/**
*
* Returns the next item element in the <code>Vector</code>.
*
* @return next Vector element based on the current index
*
*/
public function next() : *
{
return _vector[_index++];
}
/**
*
* Resets the index of the <code>VectorIterator</code>
* instance to 0.
*
*/
public function reset() : void
{
_index = 0;
}
/**
*
* Determines the indexed position of the <code>Vector</code>.
*
*/
public function position() : int
{
return _index;
}
}
}