// A collection that contains no duplicate elements. More formally, sets contain no pair of 
// elements e1 and e2 such that e1.equals(e2), and at most one null element. As implied by 
// its name, this interface models the mathematical set abstraction.
function Set()
{
  this.content = new Array();
}

// Adds the specified element to this set if it is not already present (optional operation).
Set.prototype.add = function(o)
{
  if ( ! this.contains(o) )
	{
	  this.content.push(o);
	}
}

// Adds all of the elements in the specified collection to this set if they're not already present (optional operation).
Set.prototype.addAll = function(c)
{
  for ( var i = c.iterator(); i.hasNext(); )
	{
	  this.add( i.next() );
	}
}

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

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

// Returns true if this set contains all of the elements in the specified collection.
Set.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 set for equality.
Set.prototype.equals = function(o)
{
  return this.containsAll(o) && o.containsAll(this);
}

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

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

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

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

// Retains only the elements in this set that are contained in the specified collection (optional operation).
Set.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 set.
Set.prototype.size = function()
{
	return this.content.length;
}

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