Packageorg.as3collections.iterators
Classpublic class ArrayIterator
InheritanceArrayIterator Inheritance Object
Implements IIterator
Subclasses ReadOnlyArrayIterator

An iterator to iterate over an Array object.

View the examples



Public Methods
 MethodDefined By
  
ArrayIterator(source:Array)
Constructor, creates a new ArrayIterator object.
ArrayIterator
  
hasNext():Boolean
Returns true if the iteration has more elements.
ArrayIterator
  
next():*
Returns the next element in the iteration.
ArrayIterator
  
Returns the internal pointer of the iteration.
ArrayIterator
  
remove():void
Removes from the underlying collection the last element returned by the iterator (optional operation).
ArrayIterator
  
reset():void
Resets the internal pointer of the iterator.
ArrayIterator
Constructor Detail
ArrayIterator()Constructor
public function ArrayIterator(source:Array)

Constructor, creates a new ArrayIterator object.

Parameters
source:Array — the source array to iterate over.

Throws
ArgumentError — if the source argument is null.
Method Detail
hasNext()method
public function hasNext():Boolean

Returns true if the iteration has more elements.

Returns
Booleantrue if the iteration has more elements.
next()method 
public function next():*

Returns the next element in the iteration.

Returns
* — the next element in the iteration.

Throws
NoSuchElementError — if the iteration has no more elements.
pointer()method 
public function pointer():*

Returns the internal pointer of the iteration.

In a list or queue, the pointer should be the index (position) of the iteration, typically an int.

In a map, the pointer should be the key of the iteration.

Returns
* — the internal pointer of the iteration.
remove()method 
public function remove():void

Removes from the underlying collection the last element returned by the iterator (optional operation).

This method can be called only once per call to next.


Throws
org.as3coreaddendum.errors:IllegalStateError — if the next method has not yet been called, or the remove method has already been called after the last call to the next method.
reset()method 
public function reset():void

Resets the internal pointer of the iterator.

Examples
     import org.as3collections.IIterator;
     import org.as3collections.IList;
     import org.as3collections.lists.ArrayList;
     
     var list1:IList = new ArrayList([1, 3, 5, 7]);
     
     list1                             // [1,3,5,7]
     
     var it:IIterator = list1.iterator();
     var e:int;
     
     while (it.hasNext())
     {
         ITERATION N.1
     
         it.pointer()                  // -1
     
         e = it.next();
         e                             // 1
     
         it.pointer()                  // 0
     
         ITERATION N.2
     
         it.pointer()                  // 0
     
         e = it.next();
         e                             // 3
     
         it.pointer()                  // 1
     
         if (e == 3)
         {
             it.remove();
             list1                     // [1,5,7]
         }
     
         ITERATION N.3
     
         it.pointer()                  // 0
     
         e = it.next();
         e                             // 5
     
         it.pointer()                  // 1
     
         ITERATION N.4
     
         it.pointer()                  // 1
     
         e = it.next();
         e                             // 7
     
         it.pointer()                  // 2
     }