/************************************************************************
JavaScript.net
File: System.Collections.js
Author: Scott Wood
Version: 2.4.0.0
Description: Provides set of collections classes
This software is provided under the Open Software License v. 2.1 Agreement
=========================================================================
* 2.4.0.0
* Created
* 2.4.0.1
+ Added method argument assertions
*************************************************************************/
namespace('System.Collections',2,4,0,1)
//Represents an array list
System.Collections.ArrayList = function(array)
{
	this.count = 0;
	with(System.Collections)
	{
		if(!ArrayList.initialize())
		{
			//Adds the supplied object to the list
			ArrayList.prototype.add = function(object)
			{
				//Add the item to the list at the specified count
				this[this.count] = object;
				//Add the count by 1
				this.count++;
				//Return the position of the added element
				return (this.count -1);
			}
			//Adds the supplied array to the list
			ArrayList.prototype.addRange = function(array)
			{
				//Assert input parameters
				if(array == null)
				{
					throw new ArgumentNullException('array');
				}
				//For each item in the array
				for(var index = 0; index < array.length; index++)
				{
					//Add the item to the list
					this.add(array[index]);
				}	
			}
			//Returns the index of the supplied object
			ArrayList.prototype.indexOf = function(object)
			{
				//For each element in the collection
				var result = -1;
				for(var index = 0; index < this.count; index++)
				{
					//If the item at the specified index equals the supplied object
					alert(this[index] +''+ object);
					if(this[index] == object)
					{
						//Assign the result and break the loop
						result = index;
						break;
					}
				}  
				return result;
			}
			//Returns true if the object exists within the list
			ArrayList.prototype.contains = function(object)
			{
				return (this.indexOf(object) > -1);
			}
			//Removes the object at the specified index
			ArrayList.prototype.removeAt = function(index)
			{
				//Assert input parameters
				if(index == null)
				{
					throw new ArgumentNullException('index');
				}
				//For each item in the list
				for(var $index = 0; $index < this.count; $index++)
				{
					//If the index is equal to the loop index skip it
					if($index == index)
					{
						$index ++;
					}
					//If the index is greater than the loop index re assign it to the lesser index value
					//and add the supplied index by 1.
					if($index > index)
					{
						this[index] = this[$index];
						index ++;
					}
				}
				delete this[this.count -1];
				this.count--;
			}
			//Removes the supplied object from the list
			ArrayList.prototype.remove = function(object)
			{
				this.removeAt(this.indexOf(object));
			}
			//Clears all elements from the list
			ArrayList.prototype.clear = function()
			{
				//For each object in the list
				for(var index = 0; index < this.count; index++)
				{
					//Delete the item
					delete this[index];
				}
				//Set the list count to zero
				this.count = 0;
			}
		}
		if(array)
		{
			this.addRange(array)
		}
	}
}
