/* Copyright 2009 Palm, Inc.  All rights reserved. */

var CallerDetailsTable = Class.create({
	initialize: function() {
		this.detailsHash = $H();
		this.orderedKeys = [];
	},
	
	get: function(number) {
		return this.detailsHash.get(number);
	},
	
	set: function(number, details) {
		var keyToRemove, existingDetails;
		var orderedKeys = this.orderedKeys;
		var detailsHash = this.detailsHash;
		existingDetails = detailsHash.get(number);
		if (!existingDetails && orderedKeys.length >= this.kMaxDetailsCount) {
			keyToRemove = orderedKeys.shift();
			detailsHash.unset(keyToRemove);
		}
		detailsHash.set(number, details);
		if (!existingDetails) {
			orderedKeys.push(number);			
		}
	},
	
	unset: function(number) {
		var orderedKeys = this.orderedKeys;
		var detailsHash = this.detailsHash;
		var indexOfNumber;
		var existingDetails = detailsHash.get(number);
		if (existingDetails) {
			detailsHash.unset(number);
			indexOfNumber = orderedKeys.indexOf(number);
			if (indexOfNumber !== -1) {
				orderedKeys.splice(indexOfNumber, 1);
			}
		}
	},

	kMaxDetailsCount: 100
});
