/**
 *	The root interface in the collection hierarchy. A collection  represents a 
 *	group of objects, known as its elements. Some  collections allow duplicate
 *	elements and others do not. Some are ordered and others unordered. The 
 *	This interface is typically used to pass collections around and manipulate
 *	them where  maximum generality is desired.
 *	@author		Todd Ditchendorf
 */
function Collection(a) {
	if (a && !(a instanceof Array))
		throw new Error("IllegalArgumentException: Collections's " +
					"constructor's only argument must be an Array object");
	this._array = (a) ? a : new Array();
}

/**
 *	Returns an iterator over the elements in this collection. 
 *	@return Iterator
 */
Collection.prototype.iterator = function () {
	return new Iterator(this._array);
};

/**
 *	Returns the number of elements in this collection.
 *	@return	number
 */
Collection.prototype.size = function () {
	return this._array.length;
};

/**
 *	Returns true if this collection contains no elements.
 *	@return boolean
 */
Collection.prototype.isEmpty = function () {
	return this._array.length == 0;
};

/**
 *	Returns string representation of this collection.
 *	@return	String
 */
Collection.prototype.toString = function () {
	return this._array.toString();
};

/**
 *	Removes all of the elements from this collection 
 *	@return	void
 */
Collection.prototype.clear = function () {
	this._array.length = 0;
};


/**
 *	Ensures that this collection contains the specified element
 *	@param	Object o		Add this object.
 *	@return	boolean
 */
Collection.prototype.add = function (o) {
	this._array[this._array.length] = o;
	return true;
};

/**
 *	Adds all of the elements in the specified collection to this collection.
 *	@param	Array a		New Array to be added to this collection.  ??? change this to Collection?
 *	@return	boolean	
 */
Collection.prototype.addAll = function (a) {
	for (var i = 0; i < a.length; i++) { 
		this._array[this._array.length] = a[i];
	}
	return true;
};

/**
 *	Removes a single instance of the specified element from this  collection, 
 *	if it is present
 *	@param	Object o	Element to be removed from this collection.
 *	@return	boolean
 */
Collection.prototype.remove = function (o) {
	var theNum;
	var result = false;
	var tempArray = new Array();
	for ( var i = 0; i < this._array.length; i++ ) {
		if ( this._array[i] == o ) {
			theNum = i;
			result = true;
		}
	}
	for ( var i = 0; i < this._array.length; i++ ) {
		if ( i != theNum ) {
			tempArray[tempArray.length] = this._array[i];
		}
	}
	this._array = tempArray;
	return result;
};

/**
 *	Removes all this collection's elements that are also contained in the 
 *	specified array. 
 *	@param	a		New array to be added to the collection.
 *	@return	boolean
 */
Collection.prototype.removeAll = function (a) {
	if (!(a instanceof Array)) {
		throw new Error("IllegalArgumentException: " +
							"Usage: Collection.removeAll(<Array>);");
	}
	var result = false;
	var newArray = new Array();
	outerloop:
	for ( var i = 0; i < a.length; i++ ) {
		innerloop:
		for ( var j = 0; j < this._array.length; j++ ) {
			if ( a[i] == this._array[j] ) {
				this._array.splice(j,1);
				result = true;
				continue outerloop;
			}
		}
	}
	return result;
};

/**
 *	Returns true if this collection contains the specified  element.
 *	@param	Object o	Element to be searched for in this collection.
 *	@return	boolean
 */
Collection.prototype.contains = function (element) {
	for ( var i = 0; i < this._array.length; i++ ) {
		if (this._array[i] == element) {
			return true;
		}
	}
	return false;
};


/**
 *	Returns an array containing all of the elements in this collection.
 *	@return	Array
 */
Collection.prototype.toArray = function () {
	return this._array;
};



/*boolean
containsAll(Collectionc) 
 Returns true if this collection contains all of the elements  in the specified collection.


boolean
retainAll(Collectionc) 
 Retains only the elements in this collection that are contained in the  specified collection (optional operation).
*/


