var registry = (function() {
	var _reg = {};
	return {
		'getAll' : function() {
			return _reg;
		},
		'getAllFromNamespace' : function(namespace) {
			if (_reg.hasOwnProperty(namespace) == true) {
				return _reg[namespace];
			} else {
				throw new Error('The namespace with the name ' + namespace + ' is not registered');
			}
		},
		'set' : function (namespace, key, elt) {
			if (_reg.hasOwnProperty(namespace) == false) {
				_reg[namespace] = {};
			}
			_reg[namespace][key] = elt;
		},
		'getNamespaceLength' : function(namespace) {
			if (this.issetNamespace(namespace) == true) {
				var _objects = this.getAllFromNamespace(namespace);
				var _count = 0;
				
				for (var index in _objects) {
					_count++;
				}
				return _count;
			} else {
				throw new Error('The namespace with name ' + namespace + ' is not registered');
			}
		},
		'setFromArray' : function(namespace, arr) {
			if (_reg.hasOwnProperty(namespace) == false) {
				_reg[namespace] = {};
			}
			for (var index in arr) {
				this.set(namespace, arr[index], true);
			}
		},
		'remove' : function (namespace, key) {
			if (this.isset(namespace, key) == true) {
				delete _reg[namespace][key];
			} else {
				throw new Error('The object with the key ' + key + ' is not registered');
			}
		},
		'removeNamespace' : function (namespace) {
			if (_reg.hasOwnProperty(namespace) == true) {
				delete _reg[namespace];
			} else {
				throw new Error('The namespace with the name ' + namespace + ' is not registered');
			}
		},
		'get' : function (namespace, key) {
			if (this.isset(namespace, key)) {
				return _reg[namespace][key];
			} else {
				throw new Error('The object with the key ' + key + ' is not registered');
			}
		},
		'isset' : function (namespace, key) {
			if (_reg.hasOwnProperty(namespace) == true) {
				var namespaceRegistry = _reg[namespace];
				if (namespaceRegistry.hasOwnProperty(key) == true) {
					return true;
				}
			}
			return false;
		},
		'issetNamespace' : function(namespace) {
			if (_reg.hasOwnProperty(namespace) == true) {
				return true;
			} else {
				return false;
			}
		}, 
		'lengthOfNamespace': function(namespace) {
			if (_reg.hasOwnProperty(namespace) == true) {
				var values = _reg[namespace];
				var count  = 0;
				for (var index in values) {
					count++;
				}
				return count;
			} else {
				return 0;
			}
		}
	}
})();
