/*
 Copyright (c) 2006 - 2009  Eric J. Feminella  <eric@ericfeminella.com>
 All rights reserved.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is 
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in 
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
 THE SOFTWARE.

 @internal
 */

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;
        }
    }
}