// An object that maps keys to values. A map cannot contain duplicate keys; each 
// key can map to at most one value.
function Map()
{
  this.content = new Array();
	this.keys = new Array();
}

// Removes all mappings from this map.
Map.prototype.clear = function()
{
  this.content = new Array();
	this.keys = new Array();
}

// Returns true if this map contains a mapping for the specified key.
Map.prototype.containsKey = function(key)
{
  for ( var i = 0; i < this.content.length; i++ )
	{
	  if ( this.keys[i] == key ) return true;
	}
	
	return false;
}

// Returns true if this map maps one or more keys to the specified value.
Map.prototype.containsValue = function(value)
{
  for ( var i = 0; i < this.content.length; i++ )
	{
	  if ( this.content[i] == value ) return true;
	}
	
	return false;
}

// Returns a set view of the mappings contained in this map.
Map.prototype.entrySet = function()
{
  // TODO
}

// Compares the specified object with this map for equality.
Map.prototype.equals = function(o)
{
  // TODO
}

// Returns the value to which this map maps the specified key.
Map.prototype.get = function(key)
{
  for ( var i = 0; i < this.keys.length; i++ )
	{
	  if ( this.keys[i] == key ) return this.content[i];
	}
	
	return null;
}

// Returns the hash code value for this map.
Map.prototype.hashCode = function()
{
 // TODO
}

// Returns true if this map contains no key-value mappings.
Map.prototype.isEmpty = function()
{
  return this.content.length == 0;
}

// Returns a set view of the keys contained in this map.
Map.prototype.keySet = function()
{
  var set = new Set();
  for ( var i = 0; i < this.keys.length; i++ )
	{
	  set.add( this.keys[i] );
	}
	
	return set;
}

// Associates the specified value with the specified key in this map.
Map.prototype.put = function(key, value)
{
  for ( var i = 0; i < this.keys.length; i++ )
	{
	  if ( this.keys[i] == key )
		{
		  this.content[i] = value;	
			return;
		}
	} 
	  
	this.keys.push( key );
	this.content.push( value );
}

// Copies all of the mappings from the specified map to this map.
Map.prototype.putAll = function(t)
{
	for ( var i = t.keySet().iterator(); i.hasNext(); )
	{
	  var key = i.next();
		this.put( key, t.get(key) );
	}
}

// Removes the mapping for this key from this map if it is present.
Map.prototype.remove = function(key)
{
  for ( var i = 0; i < this.keys.length; i++ )
	{
	  if ( this.keys[i] == key )
		{
		  this.content.splice(i, 1);
			this.keys.splice(i, 1);
			return;
		}
	}
}

// Returns the number of key-value mappings in this map.
Map.prototype.size = function()
{
  return this.keys.length;
}

// Returns a collection view of the values contained in this map.
Map.prototype.values = function()
{
  var c = new Set();	// TODO: Should be a list?
  for ( var i = 0; i < this.content.length; i++ )
	{
	  c.add( this.content[i] );
	}
	
	return c;
}
