all files / document-editor/base/ dictionary.js

100% Statements 59/59
100% Branches 28/28
100% Functions 13/13
100% Lines 59/59
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102   405699× 405699×     55290×           278607×                   1090630×   1090629× 1090629× 1090341× 1090341×   1090629×   31673287×   31673285× 31673285× 242746×     31430539×     624×   623× 623×     622×     762×   761× 761×     760× 760× 760×     66037672×   66037671× 66037671× 35452143×   30585528×   316786× 316786×   281487× 281487× 281487×        
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Dictionary = (function () {
        function Dictionary() {
            this.keysInternal = [];
            this.valuesInternal = [];
        }
        Object.defineProperty(Dictionary.prototype, "length", {
            get: function () {
                return this.keysInternal.length;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Dictionary.prototype, "keys", {
            get: function () {
                return this.keysInternal;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(Dictionary.prototype, "values", {
            get: function () {
                return this.valuesInternal;
            },
            enumerable: true,
            configurable: true
        });
        Dictionary.prototype.add = function (key, value) {
            if (ej2_base_1.isNullOrUndefined(key)) {
                throw new ReferenceError('Provided key or value is not valid.');
            }
            var index = this.keysInternal.indexOf(key);
            if (index < 0) {
                this.keysInternal.push(key);
                this.valuesInternal.push(value);
            }
            return 1;
        };
        Dictionary.prototype.get = function (key) {
            if (ej2_base_1.isNullOrUndefined(key)) {
                throw new ReferenceError('Provided key is not valid.');
            }
            var index = this.keysInternal.indexOf(key);
            if (index < 0 || index > this.keysInternal.length - 1) {
                return undefined;
            }
            else {
                return this.valuesInternal[index];
            }
        };
        Dictionary.prototype.set = function (key, value) {
            if (ej2_base_1.isNullOrUndefined(key)) {
                throw new ReferenceError('Provided key is not valid.');
            }
            var index = this.keysInternal.indexOf(key);
            if (index < 0 || index > this.keysInternal.length - 1) {
                throw new RangeError('No item with the specified key has been added.');
            }
            else {
                this.valuesInternal[index] = value;
            }
        };
        Dictionary.prototype.remove = function (key) {
            if (ej2_base_1.isNullOrUndefined(key)) {
                throw new ReferenceError('Provided key is not valid.');
            }
            var index = this.keysInternal.indexOf(key);
            if (index < 0 || index > this.keysInternal.length - 1) {
                throw new RangeError('No item with the specified key has been added.');
            }
            else {
                this.keysInternal.splice(index, 1);
                this.valuesInternal.splice(index, 1);
                return true;
            }
        };
        Dictionary.prototype.containsKey = function (key) {
            if (ej2_base_1.isNullOrUndefined(key)) {
                throw new ReferenceError('Provided key is not valid.');
            }
            var index = this.keysInternal.indexOf(key);
            if (index < 0 || index > this.keysInternal.length - 1) {
                return false;
            }
            return true;
        };
        Dictionary.prototype.clear = function () {
            this.keysInternal = [];
            this.valuesInternal = [];
        };
        Dictionary.prototype.destroy = function () {
            this.clear();
            this.keysInternal = undefined;
            this.valuesInternal = undefined;
        };
        return Dictionary;
    }());
    exports.Dictionary = Dictionary;
});