all files / collections/ dictionary.js

90.57% Statements 48/53
100% Branches 6/6
90.91% Functions 10/11
90.57% Lines 48/53
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   437× 437× 437×   6434× 6434× 712×   5722×   2103× 2103× 2103× 2103× 2103× 2103×       2103×               173× 173× 173× 673× 673×   173×   156× 156× 156× 418× 418×   156×   2720× 2720× 533×     2187×   2720×     308×        
define(["require", "exports", "./utils"], function (require, exports, utils_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Dictionary = (function () {
        function Dictionary(toStringFunction) {
            this.table = {};
            this.nElements = 0;
            this.toStr = toStringFunction || utils_1.defaultToString;
        }
        Dictionary.prototype.getValue = function (key) {
            var pair = this.table['$' + this.toStr(key)];
            if (typeof pair === 'undefined') {
                return undefined;
            }
            return pair.value;
        };
        Dictionary.prototype.setValue = function (key, value) {
            var ret;
            var k = '$' + this.toStr(key);
            var previousElement = this.table[k];
            this.nElements++;
            ret = undefined;
            this.table[k] = {
                key: key,
                value: value
            };
            return ret;
        };
        Dictionary.prototype.remove = function (key) {
            var k = '$' + this.toStr(key);
            var previousElement = this.table[k];
            delete this.table[k];
            this.nElements--;
            return previousElement.value;
        };
        Dictionary.prototype.keys = function () {
            var keysArray = [];
            var namesOfKeys = Object.keys(this.table);
            for (var index1 = 0; index1 < namesOfKeys.length; index1++) {
                var pair1 = this.table[namesOfKeys[index1]];
                keysArray.push(pair1.key);
            }
            return keysArray;
        };
        Dictionary.prototype.values = function () {
            var valuesArray = [];
            var namesOfValues = Object.keys(this.table);
            for (var index2 = 0; index2 < namesOfValues.length; index2++) {
                var pair2 = this.table[namesOfValues[index2]];
                valuesArray.push(pair2.value);
            }
            return valuesArray;
        };
        Dictionary.prototype.containsKey = function (key) {
            var retutnValue = true;
            if (typeof this.getValue(key) === 'undefined') {
                retutnValue = true;
            }
            else {
                retutnValue = false;
            }
            return !retutnValue;
        };
        Dictionary.prototype.clear = function () {
            this.table = {};
            this.nElements = 0;
        };
        Dictionary.prototype.size = function () {
            return this.nElements;
        };
        return Dictionary;
    }());
    exports.Dictionary = Dictionary;
});