Package | org.as3collections.iterators |
Class | public class ArrayIterator |
Inheritance | ArrayIterator Object |
Implements | IIterator |
Subclasses | ReadOnlyArrayIterator |
Array
object.
Method | Defined 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 | ||
pointer():*
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 |
ArrayIterator | () | Constructor |
public function ArrayIterator(source:Array)
Constructor, creates a new ArrayIterator object.
Parameterssource:Array — the source array 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():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
.
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.
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 }