typescript-dotnet-core
Version:
A the core classes and utilities of a JavaScript-Friendly .NET Based TypeScript Library.
7 lines (6 loc) • 3.9 kB
JavaScript
;
/*!
* @author electricessence / https://github.com/electricessence/
* Licensing: MIT https://github.com/electricessence/TypeScript.NET-Core/blob/master/LICENSE.md
*/Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib"),Compare_1=require("../../Compare"),Enumerator_1=require("../Enumeration/Enumerator"),CollectionBase_1=require("../CollectionBase"),EnumeratorBase_1=require("../Enumeration/EnumeratorBase"),ArgumentNullException_1=require("../../Exceptions/ArgumentNullException"),InvalidOperationException_1=require("../../Exceptions/InvalidOperationException"),KeyValueExtract_1=require("../../KeyValueExtract"),KeyNotFoundException_1=require("../KeyNotFoundException"),VOID0=void 0,DictionaryBase=function(t){function e(e){return t.call(this,e)||this}return tslib_1.__extends(e,t),e.prototype._onValueModified=function(e,t,r){},e.prototype._addInternal=function(e){var r=this;if(!e)throw new ArgumentNullException_1.default("item","Dictionaries must use a valid key/value pair. '"+e+"' is not allowed.");return KeyValueExtract_1.extractKeyValue(e,function(e,t){return r.addByKeyValue(e,t)})},e.prototype._clearInternal=function(){for(var e=0,t=0,r=this.keys;t<r.length;t++){var n=r[t];this.removeByKey(n)&&e++}return e},e.prototype.contains=function(e){var n=this;return!(!e||!this.getCount())&&KeyValueExtract_1.extractKeyValue(e,function(e,t){var r=n.getValue(e);return Compare_1.areEqual(t,r)})},e.prototype._removeInternal=function(e){var n=this;return e?KeyValueExtract_1.extractKeyValue(e,function(e,t){var r=n.getValue(e);return Compare_1.areEqual(t,r)&&n.removeByKey(e)?1:0}):0},Object.defineProperty(e.prototype,"keys",{get:function(){return this.getKeys()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"values",{get:function(){return this.getValues()},enumerable:!0,configurable:!0}),e.prototype.addByKeyValue=function(e,t){if(t===VOID0)throw new InvalidOperationException_1.default("Cannot add 'undefined' as a value.");if(this.containsKey(e)){var r=new InvalidOperationException_1.default("Adding a key/value when the key already exists.");throw r.data.key=e,r.data.value=t,r}return this.setValue(e,t)},e.prototype.getAssuredValue=function(e){var t=this.getValue(e);if(t===VOID0)throw new KeyNotFoundException_1.default("Key '"+e+"' not found.");return t},e.prototype.tryGetValue=function(e,t){var r=this.getValue(e);return r!==VOID0&&(t(r),!0)},e.prototype.setValue=function(e,t){var r=this;r.assertModifiable();var n=!1,o=r.getValue(e);return!Compare_1.areEqual(t,o)&&r._setValueInternal(e,t)&&(n=!0,r._onValueModified(e,t,o)),r._signalModification(n),n},e.prototype.containsKey=function(e){return!!this._getEntry(e)},e.prototype.containsValue=function(e){for(var t=this.getEnumerator();t.moveNext();)if(Compare_1.areEqual(t.current,e,!0))return t.dispose(),!0;return!1},e.prototype.removeByKey=function(e){return this.setValue(e,VOID0)},e.prototype.removeByValue=function(e){for(var t=this,r=0,n=0,o=t.getKeys();n<o.length;n++){var a=o[n];Compare_1.areEqual(t.getValue(a),e,!0)&&(t.removeByKey(a),r++)}return r},e.prototype.importEntries=function(e){return t.prototype.importEntries.call(this,e)},e.prototype._importEntries=function(e){var r=this;if(!e)return 0;var n=0;return Enumerator_1.forEach(e,function(e){return KeyValueExtract_1.extractKeyValue(e,function(e,t){r._setValueInternal(e,t)&&n++})}),n},e.prototype.getEnumerator=function(){var n=this;n.throwIfDisposed();var o,a,i,u=0;return new EnumeratorBase_1.FiniteEnumeratorBase(function(){n.throwIfDisposed(),o=n._version,a=n.getKeys(),i=a.length},function(e){for(n.throwIfDisposed(),n.assertVersion(o);u<i;){var t=a[u++],r=n.getValue(t);if(r!==VOID0)return e.yieldReturn({key:t,value:r})}return e.yieldBreak()})},e}(CollectionBase_1.default);exports.DictionaryBase=DictionaryBase,exports.default=DictionaryBase;
//# sourceMappingURL=DictionaryBase.js.map