/*!
 * @author electricessence / https://github.com/electricessence/
 * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
 */
!function(e){if("object"==typeof module&&"object"==typeof module.exports){var t=e(require,exports);void 0!==t&&(module.exports=t)}else"function"==typeof define&&define.amd&&define(["require","exports","../../Compare","../Enumeration/EnumeratorBase","../../Exceptions/ArgumentNullException","../../Exceptions/InvalidOperationException","../../KeyValueExtract","../Enumeration/Enumerator"],e)}(function(e,t){"use strict";var n=e("../../Compare"),r=e("../Enumeration/EnumeratorBase"),o=e("../../Exceptions/ArgumentNullException"),u=e("../../Exceptions/InvalidOperationException"),a=e("../../KeyValueExtract"),i=e("../Enumeration/Enumerator"),p=void 0,c=function(){function e(){this._updateRecursion=0}return Object.defineProperty(e.prototype,"isUpdating",{get:function(){return 0!=this._updateRecursion},enumerable:!0,configurable:!0}),e.prototype._onValueUpdate=function(e,t,r){if(!n.areEqual(t,r,!0)){var o=this;o.onValueChanged&&o.onValueChanged(e,t,r),0==o._updateRecursion&&o._onUpdated()}},e.prototype._onUpdated=function(){var e=this;e.onUpdated&&e.onUpdated()},e.prototype.handleUpdate=function(e){var t,n=this;if(e){n._updateRecursion++;try{t=e()}finally{n._updateRecursion--}}else t=0==n._updateRecursion;return t&&0==n._updateRecursion&&n._onUpdated(),t},Object.defineProperty(e.prototype,"isReadOnly",{get:function(){return!1},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"count",{get:function(){return this.getCount()},enumerable:!0,configurable:!0}),e.prototype.add=function(e){var t=this;if(!e)throw new o["default"]("item","Dictionaries must use a valid key/value pair. '"+e+"' is not allowed.");a["default"](e,function(e,n){return t.addByKeyValue(e,n)})},e.prototype.clear=function(){var e=this,t=e.keys,n=t.length;return n&&e.handleUpdate(function(){return t.forEach(function(t){e.removeByKey(t)}),!0}),0!=e.count&&console.warn("Dictionary clear() results in mismatched count."),n},e.prototype.contains=function(e){var t=this;return e&&this.getCount()?a["default"](e,function(e,r){var o=t.getValue(e);return n.areEqual(r,o)}):!1},e.prototype.copyTo=function(e,t){if(void 0===t&&(t=0),!e)throw new o["default"]("array");for(var n=this.getEnumerator();n.moveNext();)e[t++]=n.current;return e},e.prototype.toArray=function(){return this.copyTo([],0)},e.prototype.remove=function(e){var t=this;return e?a["default"](e,function(e,r){var o=t.getValue(e);return n.areEqual(r,o)&&t.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){var n=this;if(n.containsKey(e)){var r=new u["default"]("Adding a key/value when the key already exists.");throw r.data.key=e,r.data.value=t,r}n.setValue(e,t)},e.prototype.containsKey=function(e){return!!this._getEntry(e)},e.prototype.containsValue=function(e){for(var t=this.getEnumerator(),r=n.areEqual;t.moveNext();)if(r(t.current,e,!0))return t.dispose(),!0;return!1},e.prototype.removeByKey=function(e){return this.setValue(e,p)},e.prototype.removeByValue=function(e){var t=this,r=0,o=n.areEqual;return t.keys.forEach(function(n){o(t.getValue(n),e,!0)&&(t.removeByKey(n),++r)}),r},e.prototype.importPairs=function(e){var t=this;return e?t.handleUpdate(function(){var n=!1;return i.forEach(e,function(e){return a["default"](e,function(e,r){t.setValue(e,r),n=!0})}),n}):!1},e.prototype.getEnumerator=function(){var e,t,n=this,o=0;return new r["default"](function(){e=n.keys,t=e.length},function(r){for(;t>o;){var u=e[o++],a=n.getValue(u);if(a!==p)return r.yieldReturn({key:u,value:a})}return r.yieldBreak()})},e}();Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=c});
//# sourceMappingURL=DictionaryBase.js.map
