package com.ericfeminella.collections
{
import mx.collections.ArrayCollection;
/**
*
* <code>Collection</code> is a convenience class which extends <code>ArrayCollection</code>
* in order to provide access to an <code>Iterator</code> of the collection.
*
* @example A basic example is as follows:
*
* <listing version="3.0" >
*
* var collection:Collection = new Collection( [ "A", "B", "C"] );
* var it:Iterator = collection.iterator;
*
* while ( it.hasNext() )
* {
* trace( it.next(), it.position());
* }
*
* //outputs:
* //A
* //B
* //C
*
* </listing>
*
* @see com.ericfeminella.collections.Iterator
*
*/
public class Collection extends ArrayCollection implements Iterable
{
/**
*
* <code>Collection</code> constructor accepts an optional argument of
* type <code>Array</code>
*
* @param underlying <code>Array</code> wrapped by the collection
*
*/
public function Collection(source:Array = null)
{
super( source );
}
/**
*
* Retrieves the <code>Iterator</code> object for the collection.
*
* @return <code>Iterator</code>
*
*/
public function get iterator() : Iterator
{
return new CollectionIterator( this );
}
/**
*
* Convenience factory method which creates an <code>ArrayList</code>
* from an <code>Array</code>
*
* @param <code>Array</code> from which an <code>ArrayList</code> is to be created
* @return <code>ArrayList</code> referencing the underlying <code>Array</code>
*
*/
public static function createCollection(arrayCollection:ArrayCollection) : Collection
{
var collection:Collection = new Collection( arrayCollection.source );
return collection;
}
}
}