/**
* An example file for our generic collections class..
*
* @author Michael Avila
* ...
* @version 1.0.0
*/
class GenericCollection
{
// the datatype that this collection holds
private var thetype:Function;
// the collection interior
private var collection:Array;
/**
* Constructor
*
* @param The datatype this collection will hold
*/
public function GenericCollection( datatype:Function )
{
if (datatype == undefined)
{
trace("Constructor GenericCollection requires parameter datatype");
}
thetype = datatype;
collection = new Array();
}
/**
* Adds an item to the collection... must be of the specified type
*/
public function add( object:Object ):Boolean
{
if ( !(object instanceof thetype) )
{
trace("Invalid type: Class GenericCollection");
return false;
}
var len:Number = collection.length;
for (var i:Number = 0; i < len; i++)
{
if (collection* == object) return false;
}
collection.push( object );
return true;
}
/**
* Returns the object at the specified index.
*/
public function get( index:Number )
{
return thetype( collection[index] );
}
/**
* Removes the item from the collection
*/
public function remove( object:Object ):Object
{
var len:Number = collection.length;
for (var i:Number = 0; i<len; i++)
{
if ( collection* == object ) return collection.splice(0, 1);
}
}
/**
* Removes the item at the specified index
*/
public function removeAt( index:Number ):Object
{
return collection.splice(index, 1);
}
}
Here is it’s usage so far in the fla
var gcol = new GenericCollection( Array );
trace( gcol.add( new Array(5, 10, 15) ) );
trace( gcol.add( new Object() ) );
trace( gcol.removeAt(0) );
The spec may state that they are, but thats quite wrong - because they have methods provided that allow you to operate on the data contained, this makes them abstract.
From the language def…
The String class is a wrapper for the string primitive data type, and provides methods and properties that let you manipulate primitive string value types.
The Number class is a simple wrapper object for the Number data type - number cant be a primitive, how can a primitive handle, int, bigint, double, single and so on…
The Boolean class is a wrapper object with the same functionality as the standard JavaScript Boolean object.
and so on…
I’m just being pedantic and you probably meant string rather than String, I should probably be ignored lol, but a primitive is completely different, it is a base type that provides a container for data with a certain amount of bytes allocated in the stack when its created, the abstraction happens when you add functionality to this base type, ala String and so on…