/*******************************************************************************************
 * Object: Multidimensional Hashtable
 * Author: Danilo Ercoli
 *******************************************************************************************/

Hashtable.prototype.hash	 	= null;
Hashtable.prototype.keys		= null;
Hashtable.prototype.location	= null;

/**
 * Hashtable - Constructor
 * Create a new Hashtable object.
 */
function Hashtable(){
	this.hash = new Array();
	this.keys = new Array();
	this.location = -1;
}

/**
 * put
 * Add new key
 * param: key - String, key name
 * param: value - Object, the object to insert
 */
Hashtable.prototype.put = function (key, value){
	if (key == null || value == null) 
        throw "HashTable Put NullPointerException {" + key + "},{" + value + "}";
    
	if (this.hash[key] == null){
		this.keys[this.keys.length] = key;
	    this.hash[key]=new Array();
	}

	var arrayTemp=this.hash[key];
	var lung= arrayTemp.length;
	arrayTemp[lung]=value;
}

/**
 * get
 * Return an element
 * param: key - String, key name
 * Return: object - The requested object
 */
Hashtable.prototype.get = function (key){
		return this.hash[key];
}

/**
 * remove
 * Rimuove tutti gli elementi con una data chiave
 * param: key - String, key name
 */
Hashtable.prototype.remove = function (key){
	for (var i = 0; i < this.keys.length; i++){
		//did we found our key?
		if (key == this.keys[i]){
			//remove it from the hash
			this.hash[this.keys[i]] = null;
			//and throw away the key...
			this.keys.splice(i ,1);
			return;
		}
	}
}

/**
 * Grandezze della hash Table rispetto alla prima dimensione
 * Return: Number of elements in the hashtable
 */
Hashtable.prototype.size = function (){
    return this.keys.length;
}


/**
 * reset 
 * resetta il puntatore nella hashTable
 * Return: 
 */
Hashtable.prototype.reset = function (){
		this.location = -1;
		return true;
}

/**
 * next
 * Return: true if theres more items
 */
Hashtable.prototype.next = function (){
	if (++this.location < this.keys.length)
		return true;
	else
		return false;
}


/**
 * getKey
 * Return: The value of item in the hash
 */
Hashtable.prototype.getKey = function (){
	try {
		return this.keys[this.location];
	} catch(e) {
		return null;
	}
}

/**
 * getValue
 * Return: l'array contenenti i valori per quella chiave
 */
Hashtable.prototype.getValue = function (){
	try {
		return this.hash[this.keys[this.location]];
	} catch(e) {
		return null;
	}
}



