Packagecom.ericfeminella.utils.iterators
Classpublic class IteratorFactory

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



Public Methods
 MethodDefined by
  
getIterator(iteratorType:String):IIterator
[static] Static method which handles Iterator instantiation based on static constants defined in IteratorTypes:
   To avoid this error as a best practice only use an IteratorTypes constant:
   
   IteratorTypes.OBJECT_ITERATOR;
   IteratorTypes.ARRAY_ITERATOR;
   IteratorTypes.ARRAY_COLLECTION_ITERATOR; 
   
   

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;
   
      private var iterator:IIterator;
      
      this.iterator = IteratorFactory.getIterator(IteratorTypes.OBJECT_ITERATOR);
      this.iterator.setAggregate({name: 'IteratorFactory', version: 1.0, author: 'Eric Feminella'});
      
   while (this.iterator.hasNext())
   {
         trace(this.iterator.next());
   }
   
   traces:
   IteratorFactory
   1.0
   Eric Feminella
   
   this.iterator = IteratorFactory.getIterator(IteratorTypes.ARRAY_ITERATOR);
   this.iterator.setAggregate(['IteratorFactory', 1.0, 'Eric Feminella']);
   
   while (this.iterator.hasNext())
   {
         trace(this.iterator.next());
   }
   
   traces:
   IteratorFactory
   1.0
   Eric Feminella
   
   

By typing an Iterator instance as an IIterator, a client has the flexibility of changing the type of iteration at anytime.

IteratorFactory
Method detail
getIterator()method
public static function getIterator(iteratorType:String):IIterator

Static method which handles Iterator instantiation based on static constants defined in IteratorTypes:

   To avoid this error as a best practice only use an IteratorTypes constant:
   
   IteratorTypes.OBJECT_ITERATOR;
   IteratorTypes.ARRAY_ITERATOR;
   IteratorTypes.ARRAY_COLLECTION_ITERATOR; 
   
   

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;
   
      private var iterator:IIterator;
      
      this.iterator = IteratorFactory.getIterator(IteratorTypes.OBJECT_ITERATOR);
      this.iterator.setAggregate({name: 'IteratorFactory', version: 1.0, author: 'Eric Feminella'});
      
   while (this.iterator.hasNext())
   {
         trace(this.iterator.next());
   }
   
   traces:
   IteratorFactory
   1.0
   Eric Feminella
   
   this.iterator = IteratorFactory.getIterator(IteratorTypes.ARRAY_ITERATOR);
   this.iterator.setAggregate(['IteratorFactory', 1.0, 'Eric Feminella']);
   
   while (this.iterator.hasNext())
   {
         trace(this.iterator.next());
   }
   
   traces:
   IteratorFactory
   1.0
   Eric Feminella
   
   

By typing an Iterator instance as an IIterator, a client has the flexibility of changing the type of iteration at anytime.

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

Returns
IIterator — IIterator interface which defines the Iterator instance which is returned

Throws
— IteratorFactoryTypeError specifying that the iterator type does not exist

See also