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   493593× 493593×     69859×           369395×           18527×         1324357×   1324356× 1324356× 1320533× 1320533×   1324356×   44987810×   44987808× 44987808× 354579×     44633229×     777×   776× 776×     775×     1877×   1876× 1876×     1875× 1875× 1875×     95956154×   95956153× 95956153× 52181335×   43774818×   395526× 395526×   341033× 341033× 341033×        
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;
});