Packageorg.as3collections.iterators
Classpublic class MapIterator
InheritanceMapIterator Inheritance Object
Implements IIterator
Subclasses ReadOnlyMapIterator

An iterator to iterate over maps (implementations of the IMap interface).

View the examples



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

Constructor, creates a new MapIterator object.

Parameters
source:IMap — the source map 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.IMap;
     import org.as3collections.maps.ArrayListMap;
     
     var map1:IMap = new ArrayListMap();
     map1.put("element-1", 1);
     map1.put("element-3", 3);
     map1.put("element-5", 5);
     map1.put("element-7", 7);
     
     map1                             // ["element-1"=1,"element-3"=3,"element-5"=5,"element-7"=7]
     
     var it:IIterator = map1.iterator();
     var e:int;
     
     while (it.hasNext())
     {
         ITERATION N.1
     
         it.pointer()                  // null
     
         e = it.next();
         e                             // 1
     
         it.pointer()                  // "element-1"
     
         ITERATION N.2
     
         it.pointer()                  // "element-1"
     
         e = it.next();
         e                             // 3
     
         it.pointer()                  // "element-3"
     
         if (e == 3)
         {
             it.remove();
             map1                      // ["element-1"=1,"element-5"=5,"element-7"=7]
         }
     
         ITERATION N.3
     
         it.pointer()                  // "element-1"
     
         e = it.next();
         e                             // 5
     
         it.pointer()                  // "element-5"
     
         ITERATION N.4
     
         it.pointer()                  // "element-5"
     
         e = it.next();
         e                             // 7
     
         it.pointer()                  // "element-7"
     }