123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- var DICTIONARY_INVALID_KEY = -1;
- var DICTIONARY_SUCCESS = 1;
- function CDictionary()
- {
-
- this.m_aValues = {};
- }
- function CDictionary_add(sKey, oValue)
- {
- if (typeof sKey != "string" && typeof sKey != "number")
- {
- return DICTIONARY_INVALID_KEY;
- }
- this.m_aValues[sKey] = oValue;
- return DICTIONARY_SUCCESS;
- }
- function CDictionary_exists(sKey)
- {
- if (typeof sKey != "string" && typeof sKey != "number")
- {
- return false;
- }
- return (typeof this.m_aValues[sKey] != "undefined");
- }
- function CDictionary_get(sKey)
- {
- if (typeof sKey != "string" && typeof sKey != "number")
- {
- return null;
- }
- if (this.exists(sKey) === true)
- {
- return this.m_aValues[sKey];
- }
- else
- {
- return null;
- }
- }
- function CDictionary_keys()
- {
- var aKeys = [];
- for (var idxValue in this.m_aValues)
- {
- aKeys.push(idxValue);
- }
- return aKeys.sort();
- }
- function CDictionary_remove(sKey)
- {
- if (typeof sKey != "string" && typeof sKey != "number")
- {
- return DICTIONARY_INVALID_KEY;
- }
- var oRetVal = this.get(sKey);
- delete this.m_aValues[sKey];
- return oRetVal;
- }
- function CDictionary_removeAll()
- {
- this.m_aValues = [];
- return DICTIONARY_SUCCESS;
- }
- function CDictionary_append(oNewDictionary)
- {
- if (oNewDictionary instanceof CDictionary && oNewDictionary.keys().length > 0)
- {
- var aKeys = oNewDictionary.keys();
- for (var idxKeys = 0; idxKeys < aKeys.length; idxKeys++)
- {
- this.add(aKeys[idxKeys], oNewDictionary.get(aKeys[idxKeys]));
- }
- }
- }
- CDictionary.prototype.add = CDictionary_add;
- CDictionary.prototype.exists = CDictionary_exists;
- CDictionary.prototype.get = CDictionary_get;
- CDictionary.prototype.keys = CDictionary_keys;
- CDictionary.prototype.remove = CDictionary_remove;
- CDictionary.prototype.removeAll = CDictionary_removeAll;
- CDictionary.prototype.append = CDictionary_append;
|