Packagecom.ericfeminella.utils.iterators
Classpublic final class IteratorFactory

Iterator specific Factory Pattern implementation which defines an API for handling specific Iterator instantiation

See also

com.ericfeminella.utils.iterators.IteratorTypes


Public Methods
 MethodDefined 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:

  • IteratorTypes.OBJECT_ITERATOR;
  • IteratorTypes.ARRAY_ITERATOR;
  • IteratorTypes.COLLECTION_ITERATOR;

IteratorFactory
Method detail
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:

Parameters
type:String — a static constant representing a valid IteratorType

Returns
IIterator — concrete iterator implementation as specified by type argument

See also


Example
For instance, a client would typically create an iterator as follows
      
   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