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