all files / TypeScript.NET/source/System/Collections/Dictionaries/ OrderedStringKeyDictionary.js

62.12% Statements 41/66
50% Branches 20/40
62.5% Functions 10/16
63.33% Lines 38/60
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                        36× 36×         36× 36× 18× 18× 18× 36×                                                     36×        
/*!
 * @author electricessence / https://github.com/electricessence/
 * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md
 */
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
(function (factory) {
    Eif (typeof module === 'object' && typeof module.exports === 'object') {
        var v = factory(require, exports); Iif (v !== undefined) module.exports = v;
    }
    else if (typeof define === 'function' && define.amd) {
        define(["require", "exports", "../Array/Utility", "./StringKeyDictionary", "../../Exceptions/ArgumentOutOfRangeException"], factory);
    }
})(function (require, exports) {
    "use strict";
    var ArrayUtility = require("../Array/Utility");
    var StringKeyDictionary_1 = require("./StringKeyDictionary");
    var ArgumentOutOfRangeException_1 = require("../../Exceptions/ArgumentOutOfRangeException");
    var VOID0 = void 0;
    var OrderedStringKeyDictionary = (function (_super) {
        __extends(OrderedStringKeyDictionary, _super);
        function OrderedStringKeyDictionary() {
            _super.call(this);
            this._order = [];
        }
        OrderedStringKeyDictionary.prototype.indexOfKey = function (key) {
            var o = this._order;
            return o.length ? o.indexOf(key, 0) : -1;
        };
        OrderedStringKeyDictionary.prototype.getValueByIndex = function (index) {
            var o = this._order;
            return index < o.length ? this.getValue(o[index]) : VOID0;
        };
        OrderedStringKeyDictionary.prototype.setValue = function (key, value, keepIndex) {
            var _ = this, exists = _.indexOfKey(key) != -1;
            if (!exists && (value !== VOID0 || keepIndex))
                _._order.push(key);
            else Eif (exists && value === VOID0 && !keepIndex)
                ArrayUtility.remove(_._order, key);
            return _super.prototype.setValue.call(this, key, value);
        };
        OrderedStringKeyDictionary.prototype.setByIndex = function (index, value) {
            var _ = this, order = _._order;
            if (index < 0)
                throw new ArgumentOutOfRangeException_1.ArgumentOutOfRangeException('index', index, 'Is less than zero.');
            if (index >= order.length)
                throw new ArgumentOutOfRangeException_1.ArgumentOutOfRangeException('index', index, 'Is greater than the count.');
            return _.setValue(order[index], value);
        };
        OrderedStringKeyDictionary.prototype.importValues = function (values) {
            var _ = this;
            return _.handleUpdate(function () {
                var changed = false;
                for (var i = 0; i < values.length; i++) {
                    if (_.setByIndex(i, values[i]))
                        changed = true;
                }
                return changed;
            });
        };
        OrderedStringKeyDictionary.prototype.setValues = function () {
            var values = [];
            for (var _i = 0; _i < arguments.length; _i++) {
                values[_i - 0] = arguments[_i];
            }
            return this.importValues(values);
        };
        OrderedStringKeyDictionary.prototype.removeByIndex = function (index) {
            return this.setByIndex(index, VOID0);
        };
        OrderedStringKeyDictionary.prototype.getKeys = function () {
            var _ = this, o = _._order;
            return o.length && o.filter(function (key) { return _.containsKey(key); }) || [];
        };
        return OrderedStringKeyDictionary;
    }(StringKeyDictionary_1.StringKeyDictionary));
    exports.OrderedStringKeyDictionary = OrderedStringKeyDictionary;
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.default = OrderedStringKeyDictionary;
});
//# sourceMappingURL=OrderedStringKeyDictionary.js.map