import { ArrayList } from './ArrayList';
import { Entry } from './Map';
var HashMap = (function () {
    function HashMap() {
        this.keyList = new ArrayList();
        this.hashMap = new Object();
    }
    HashMap.prototype.size = function () {
        return this.entrySet().length;
    };
    HashMap.prototype.isEmpty = function () {
        return this.size() === 0;
    };
    HashMap.prototype.containsKey = function (key) {
        return this.keySet().contains(key);
    };
    HashMap.prototype.containsValue = function (value) {
        return this.values().contains(value);
    };
    HashMap.prototype.put = function (key, value) {
        if (!this.keySet().contains(key)) {
            this.keySet().push(key);
        }
        return this.hashMap[key] = value;
    };
    HashMap.prototype.remove = function (key, testValue) {
        var v;
        if (this.containsKey(key)) {
            v = this.get(key);
            if (testValue === null || testValue === undefined || testValue === v) {
                this.keyList.removeAll([key]);
                this.hashMap[key] = undefined;
                delete this.hashMap[key];
            }
        }
        return v;
    };
    HashMap.prototype.keySet = function () {
        return this.keyList;
    };
    HashMap.prototype.values = function () {
        var _this = this;
        return this.keySet().map(function (k) { return _this.get(k); });
    };
    HashMap.prototype.entrySet = function () {
        var _this = this;
        return this.keySet().map(function (k) { return new Entry([k, _this.get(k)]); });
    };
    HashMap.prototype.get = function (key) {
        return this.hashMap[key];
    };
    HashMap.prototype.getOrDefault = function (key, defaultValue) {
        return this.containsKey(key) ? this.get(key) : defaultValue;
    };
    HashMap.prototype.putAll = function (m) {
        var _this = this;
        m.forEach(function (k, v) { return _this.put(k, v); });
    };
    HashMap.prototype.removeAll = function (l) {
        var _this = this;
        l.forEach(function (e) { return _this.remove(e.getKey(), e.getValue()); });
    };
    HashMap.prototype.clear = function () {
        var _this = this;
        this.keySet().forEach(function (k) { return _this.remove(k); });
        this.keyList.clear();
    };
    HashMap.prototype.forEach = function (action) {
        this.entrySet().forEach(function (entry) {
            action(entry.getKey(), entry.getValue());
        });
    };
    HashMap.prototype.map = function (action) {
        return this.entrySet().map(function (entry) {
            return action(entry.getKey(), entry.getValue());
        });
    };
    return HashMap;
}());
export { HashMap };
//# sourceMappingURL=HashMap.js.map