Package | com.ericfeminella.utils.iterators |
Class | public final class IteratorFactory |
See also
Method | Defined by | ||
---|---|---|---|
getIterator(type:String):IIterator
[static]
Static method which handles Iterator instantiation based on static
constants defined in IteratorTypes:
As a best practice, use a constant defined by IteratorTypes:
| IteratorFactory |
getIterator | () | method |
public static function getIterator(type:String):IIterator
Static method which handles Iterator instantiation based on static constants defined in IteratorTypes:
As a best practice, use a constant defined by IteratorTypes:
type:String — a static constant representing a valid IteratorType
|
IIterator —
concrete iterator implementation as specified by type argument
|
See also
import com.ericfeminella.utils.iterators.IIterator; import com.ericfeminella.utils.iterators.IteratorFactory; import com.ericfeminella.utils.iterators.IteratorTypes; import mx.collections.ArrayCollection; var collection:ArrayCollection = new ArrayCollection(["A","B","C"]); var it:IIterator = IteratorFactory.getIterator( IteratorTypes.COLLECTION_ITERATOR ); it.setAggregate( collection ); while ( iterator.hasNext() ) { trace( it.next(), it.position()); } //A, 0 //B, 1 //C, 2 iterator = IteratorFactory.getIterator(IteratorTypes.ARRAY_ITERATOR); iterator.setAggregate(["A", "B", "C"]); while (iterator.hasNext()) { trace(iterator.next()); } //A, 0 //B, 1 //C, 2
By typing an Iterator instance as an IIterator, clients have the flexibility of changing the concrete iterator at runtime