package com.ericfeminella.collections
{
/**
*
* <code>ArrayList</code> is a convenience class which extends <code>Array</code>
* in order to provide access to an <code>Iterator</code> of the collection.
*
* <p>
* <code>ArrayList</code> provides the same API as the top level <code>Array</code>
* class, with the only exception being <code>[]</code> notation can not be used as
* with <code>Array</code>. New instances of <code>ArrayList</code> must be instantiated
* via <code>new ArrayList()</code>.
* </p>
*
* <p>
* <code>ArrayList</code> is also not an <code>ArrayList</code> in terms of boxing and
* unboxing to explicit types. References to each index of an <code>ArrayList</code>
* return an object of the type which was placed in the <code>Array</code>.
* </p>
*
* @example A basic example is as follows:
*
* <listing version="3.0" >
*
* var list:ArrayList = new ArrayList()
* list.push( "A" );
* list.push( "B" );
* list.push( "C" );
*
* var it:Iterator = list.iterator;
*
* while ( it.hasNext() )
* {
* trace( it.next(), it.position());
* }
*
* //outputs:
* //A
* //B
* //C
*
* </listing>
*
* @see com.ericfeminella.collections.Iterator
*
*/
public class ArrayList extends Array implements Iterable
{
/**
*
* <code>ArrayList</code> constructor accepts an optional argument of
* type <code>Array</code>
*
* @param underlying <code>Array</code> wrapped by the collection
*
*/
public function ArrayList(numElements:int = 0)
{
super( numElements );
}
/**
*
* Retrieves the <code>Iterator</code> object for the <code>ArrayList</code>.
*
* @return <code>Iterator</code>
*
*/
public function get iterator() : Iterator
{
return new ArrayIterator( 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 createArrayList(array:Array) : ArrayList
{
var n:uint = array.length;
var list:ArrayList = new ArrayList( n );
for (var i:int = 0; i < n; i++)
{
list.push( array[i] );
}
return list;
}
}
}