From 2f914dc35aed0c4cbb86571103e031c4044e9a4c Mon Sep 17 00:00:00 2001 From: Jan Schreiber Date: Thu, 28 Oct 2010 16:44:13 +0200 Subject: [PATCH] Reformatted code with jslint:indent:4 --- src/tm-src.js | 911 +++++++++++++++++++++++++++++--------------------- 1 file changed, 529 insertions(+), 382 deletions(-) diff --git a/src/tm-src.js b/src/tm-src.js index 5e938ff..3797e09 100644 --- a/src/tm-src.js +++ b/src/tm-src.js @@ -1,6 +1,6 @@ /*jslint browser: true, devel: true, onevar: true, undef: true, nomen: false, eqeqeq: true, plusplus: true, bitwise: true, - regexp: true, newcap: true, immed: true */ + regexp: true, newcap: true, immed: true, indent: 4 */ /*global exports*/ var TM, TopicMapSystemFactory; @@ -43,16 +43,36 @@ TM = (function () { this.length = 0; }; - // Simple hash implementation + /** + * @class Simple hash implementation. + */ Hash.prototype = { + /** + * Returns the object belonging to the key key or undefined if the + * key does not exist. + * @param key {String} The hash key. + * @returns {object} The stored object or undefined. + */ get: function (key) { - return this.hash[key]; + return this.hash[key]; }, + /** + * Checks if the key exists in the hash table. + * @param key {String} The hash key. + * @returns {boolean} True if key exists in the hash table. False + * otherwise. + */ contains: function (key) { - return this.get(key) !== undefined; + return this.get(key) !== undefined; }, + /** + * Stores an object in the hash table. + * @param key {String} The hash key. + * @param val {object} The value to be stored in the hash table. + * @returns val {object} A reference to the stored object. + */ put: function (key, val) { if (!this.hash[key]) { this.length += 1; @@ -61,12 +81,22 @@ TM = (function () { return val; }, + /** + * Removes the key and the corresponding value from the hash table. + * @param key {String} Removes value corresponding to key and the key + * from the hash table + * @returns {Hash} The hash table itself. + */ remove: function (key) { delete this.hash[key]; this.length -= 1; return this; }, + /** + * Returns an array with keys of the hash table. + * @returns {Array} An array with strings. + */ keys: function () { var ret = [], key; for (key in this.hash) { @@ -77,6 +107,11 @@ TM = (function () { return ret; }, + /** + * Returns an array with all values of the hash table. + * @returns {Array} An array with all objects stored as a value in + * the hash table. + */ values: function () { var ret = [], key; for (key in this.hash) { @@ -87,11 +122,22 @@ TM = (function () { return ret; }, + /** + * Empties the hash table by removing the reference to all objects. + * Note that the store objects themselves are not touched. + * @returns undefined + */ empty: function () { this.hash = {}; this.length = 0; }, + /** + * Returns the size of the hash table, that is the count of all + * key/value pairs. + * @returns {Number} The count of all key/value pairs stored in the + * hash table. + */ size: function () { return this.length; } @@ -116,6 +162,9 @@ TM = (function () { EventType.REMOVE_TYPE = 14; EventType.SET_TYPE = 15; + /** + * @namespace Namespace for XML Schema URIs. // FIXME!! + */ XSD = { 'string': "http://www.w3.org/2001/XMLSchema#string", 'integer': "http://www.w3.org/2001/XMLSchema#integer", @@ -195,7 +244,7 @@ TM = (function () { existing = this.getTopicMap()._ii2construct.get(itemIdentifier.getReference()); if (existing) { throw {name: 'IdentityConstraintException', - message: 'Topic Maps constructs with the same item identifier '+ + message: 'Topic Maps constructs with the same item identifier ' + 'are not allowed', reporter: this, existing: existing, @@ -288,7 +337,7 @@ TM = (function () { if (itemIdentifier === null) { return; } - for (var i=0; i 0) { + that.type2associations.put(type.getId(), + existing); + } else { + that.type2associations.remove(type.getId()); + } + break; + case EventType.REMOVE_NAME: + type = source.getType(); + existing = that.type2names.get(type.getId()); + existing.remove(source.getId()); + if (existing.length > 0) { + that.type2names.put(type.getId(), existing); + } else { + that.type2names.remove(type.getId()); + } + break; + case EventType.REMOVE_OCCURRENCE: + type = source.getType(); + existing = that.type2occurrences.get(type.getId()); + existing.remove(source.getId()); + if (existing.length > 0) { + that.type2occurrences.put(type.getId(), existing); + } else { + that.type2occurrences.remove(type.getId()); + } + break; + case EventType.REMOVE_ROLE: + type = source.getType(); + existing = that.type2roles.get(type.getId()); + existing.remove(source.getId()); + if (existing.length > 0) { + that.type2roles.put(type.getId(), existing); + } else { + that.type2roles.remove(type.getId()); + } + break; + case EventType.REMOVE_TOPIC: + // two cases: + // topic has types + types = source.getTypes(); + for (i = 0; i < types.length; i += 1) { + existing = that.type2topics.get(types[i].getId()); + existing.remove(source.getId()); + if (!existing.size()) { + that.type2topics.remove(types[i].getId()); + } + } + // topic used as type + that.type2topics.remove(source.getId()); + that.type2associations.remove(source.getId()); + that.type2roles.remove(source.getId()); + that.type2occurrences.remove(source.getId()); + that.type2variants.remove(source.getId()); + break; + case EventType.REMOVE_TYPE: + existing = that.type2topics.get(obj.type.getId()); + existing.remove(source.getId()); + if (!existing.size()) { + that.type2topics.remove(obj.type.getId()); + } + if (source.getTypes().length === 0) { + untyped = that.type2topics.get('null'); + if (typeof untyped === 'undefined') { + untyped = new Hash(); + } + untyped.put(source.getId(), source); + } + break; + case EventType.SET_TYPE: + if (source.isAssociation()) { + // remove source from type2associations(obj.old.getId()); + if (obj.old) { + existing = that.type2associations.get(obj.old.getId()); + for (i = 0; i < existing.length; i += 1) { + if (existing[i].equals(source)) { + existing.splice(i, 1); + break; + } + } + if (existing.length > 0) { + that.type2associations.put(obj.old.getId(), + existing); + } else { + that.type2associations.remove(obj.old.getId()); + } + } + existing = that.type2associations.get(obj.type.getId()); + if (typeof existing === 'undefined') { + existing = []; + } + existing.push(source); + that.type2associations.put(obj.type.getId(), existing); + } else if (source.isName()) { + existing = that.type2names.get(obj.old.getId()); + if (existing) { + existing.remove(source.getId()); + if (existing.length > 0) { + that.type2names.put(obj.old.getId(), existing); + } else { + that.type2names.remove(obj.old.getId()); + } + } existing = that.type2names.get(obj.type.getId()); if (typeof existing === 'undefined') { existing = new Hash(); } existing.put(source.getId(), source); that.type2names.put(obj.type.getId(), existing); - break; - case EventType.ADD_OCCURRENCE: + } else if (source.isOccurrence()) { + existing = that.type2occurrences.get(obj.old.getId()); + if (existing) { + existing.remove(source.getId()); + if (existing.length > 0) { + that.type2occurrences.put(obj.old.getId(), existing); + } else { + that.type2occurrences.remove(obj.old.getId()); + } + } existing = that.type2occurrences.get(obj.type.getId()); if (typeof existing === 'undefined') { existing = new Hash(); } existing.put(source.getId(), source); that.type2occurrences.put(obj.type.getId(), existing); - break; - case EventType.ADD_ROLE: + } else if (source.isRole()) { + existing = that.type2roles.get(obj.old.getId()); + if (existing) { + existing.remove(source.getId()); + if (existing.length > 0) { + that.type2roles.put(obj.old.getId(), existing); + } else { + that.type2roles.remove(obj.old.getId()); + } + } existing = that.type2roles.get(obj.type.getId()); if (typeof existing === 'undefined') { existing = new Hash(); } existing.put(source.getId(), source); that.type2roles.put(obj.type.getId(), existing); - break; - case EventType.ADD_TOPIC: - existing = that.type2topics.get('null'); - if (typeof existing === 'undefined') { - existing = new Hash(); - } - existing.put(source.getId(), source); - that.type2topics.put('null', existing); - break; - case EventType.ADD_TYPE: - // check if source exists with type null, remove it there - untyped = that.type2topics.get('null'); - if (untyped && untyped.get(source.getId())) { - untyped.remove(source.getId()); - that.type2topics.put('null', untyped); - } - - existing = that.type2topics.get(obj.type.getId()); - if (typeof existing === 'undefined') { - existing = new Hash(); - } - existing.put(source.getId(), source); - that.type2topics.put(obj.type.getId(), existing); - break; - case EventType.REMOVE_ASSOCIATION: - type = source.getType(); - if (!type) { break; } - existing = that.type2associations.get(type.getId()); - for (i=0; i 0) { - that.type2associations.put(type.getId(), - existing); - } else { - that.type2associations.remove(type.getId()); - } - break; - case EventType.REMOVE_NAME: - type = source.getType(); - existing = that.type2names.get(type.getId()); - existing.remove(source.getId()); - if (existing.length > 0) { - that.type2names.put(type.getId(), existing); - } else { - that.type2names.remove(type.getId()); - } - break; - case EventType.REMOVE_OCCURRENCE: - type = source.getType(); - existing = that.type2occurrences.get(type.getId()); - existing.remove(source.getId()); - if (existing.length > 0) { - that.type2occurrences.put(type.getId(), existing); - } else { - that.type2occurrences.remove(type.getId()); - } - break; - case EventType.REMOVE_ROLE: - type = source.getType(); - existing = that.type2roles.get(type.getId()); - existing.remove(source.getId()); - if (existing.length > 0) { - that.type2roles.put(type.getId(), existing); - } else { - that.type2roles.remove(type.getId()); - } - break; - case EventType.REMOVE_TOPIC: - // two cases: - // topic has types - types = source.getTypes(); - for (i=0; i 0) { - that.type2associations.put(obj.old.getId(), - existing); - } else { - that.type2associations.remove(obj.old.getId()); - } - } - existing = that.type2associations.get(obj.type.getId()); - if (typeof existing === 'undefined') { - existing = []; - } - existing.push(source); - that.type2associations.put(obj.type.getId(), existing); - } else if (source.isName()) { - existing = that.type2names.get(obj.old.getId()); - if (existing) { - existing.remove(source.getId()); - if (existing.length > 0) { - that.type2names.put(obj.old.getId(), existing); - } else { - that.type2names.remove(obj.old.getId()); - } - } - existing = that.type2names.get(obj.type.getId()); - if (typeof existing === 'undefined') { - existing = new Hash(); - } - existing.put(source.getId(), source); - that.type2names.put(obj.type.getId(), existing); - } else if (source.isOccurrence()) { - existing = that.type2occurrences.get(obj.old.getId()); - if (existing) { - existing.remove(source.getId()); - if (existing.length > 0) { - that.type2occurrences.put(obj.old.getId(), existing); - } else { - that.type2occurrences.remove(obj.old.getId()); - } - } - existing = that.type2occurrences.get(obj.type.getId()); - if (typeof existing === 'undefined') { - existing = new Hash(); - } - existing.put(source.getId(), source); - that.type2occurrences.put(obj.type.getId(), existing); - } else if (source.isRole()) { - existing = that.type2roles.get(obj.old.getId()); - if (existing) { - existing.remove(source.getId()); - if (existing.length > 0) { - that.type2roles.put(obj.old.getId(), existing); - } else { - that.type2roles.remove(obj.old.getId()); - } - } - existing = that.type2roles.get(obj.type.getId()); - if (typeof existing === 'undefined') { - existing = new Hash(); - } - existing.put(source.getId(), source); - that.type2roles.put(obj.type.getId(), existing); - } - break; + } + break; } }; tm.addAssociationEvent.registerHandler(eventHandler); @@ -2266,7 +2382,9 @@ TM = (function () { */ TypeInstanceIndex.prototype.getAssociations = function (type) { var ret = this.type2associations.get(type.getId()); - if (!ret) { return []; } + if (!ret) { + return []; + } return ret; }; @@ -2277,7 +2395,7 @@ TM = (function () { */ TypeInstanceIndex.prototype.getAssociationTypes = function () { var ret = [], keys = this.type2associations.keys(), i; - for (i=0; i 0 || ass.getReifier() !== null ||