// 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.
function Collection()
{
  this.content = new Array();
}

// Adds the specified element to this Collection.
Collection.prototype.add = function(o)
{
  this.content.push(o);
}

// Adds all of the elements in the specified collection to this Collection.
Collection.prototype.addAll = function(c)
{
  for ( var i = c.iterator(); i.hasNext(); )
	{
	  this.add( i.next() );
	}
}

// Removes all of the elements from this Collection.
Collection.prototype.clear = function()
{
  this.content = new Array();
}

// Returns true if this Collection contains the specified element.
Collection.prototype.contains = function(o)
{
  for ( var i = this.iterator(); i.hasNext(); )
	{
	  if ( i.next() == o ) return true;
	}
	return false;
}

// Returns true if this Collection contains all of the elements in the specified collection.
Collection.prototype.containsAll = function(c)
{
  for ( var i = c.iterator(); i.hasNext(); )
	{
	  if ( !this.contains(i.next()) ) return false;
	}
	return true;
}

// Compares the specified object with this Collection for equality.
Collection.prototype.equals = function(o)
{
  return this.containsAll(o) && o.containsAll(this);
}

// Returns true if this Collection contains no elements.
Collection.prototype.isEmpty = function()
{
  return this.content.length == 0;
}

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

// Removes a single instance of the specified element from this Collection, if it is present.
Collection.prototype.remove = function(o)
{
  for ( var i = this.iterator(); i.hasNext(); )
	{
	  if ( i.next() == o ) 
		{
		  i.remove();
			break;
		}
	}
}

// Removes all this Collection's elements that are also contained in the specified collection (optional operation).
Collection.prototype.removeAll = function(c)
{
  for ( var i = c.iterator(); i.hasNext(); )
	{
	  this.remove( i.next() );
	}
}

// Retains only the elements in this Collection that are contained in the specified collection (optional operation).
Collection.prototype.retainAll = function(c)
{
  for ( var i = this.iterator(); i.hasNext(); )
	{
	  if ( !c.contains(i.next()) )
		{
		  i.remove();
		}
	}
}

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

// Returns an array containing all of the elements in this Collection.
Collection.prototype.toArray = function()
{
  return this.content;
}
