| Package | org.as3collections.iterators |
| Class | public class MapIterator |
| Inheritance | MapIterator Object |
| Implements | IIterator |
| Subclasses | ReadOnlyMapIterator |
IMap interface).
| Method | Defined By | ||
|---|---|---|---|
MapIterator(source:IMap)
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 | ||
pointer():*
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 | ||
| MapIterator | () | Constructor |
public function MapIterator(source:IMap)
Constructor, creates a new MapIterator object.
source:IMap — the source map to iterate over.
|
ArgumentError — if the source argument is null.
|
| hasNext | () | method |
public function hasNext():Boolean
Returns true if the iteration has more elements.
Boolean — true 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.
|
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():voidRemoves from the underlying collection the last element returned by the iterator (optional operation).
This method can be called only once per call to next.
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():voidResets the internal pointer of the iterator.
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"
}