export default class Dictionary {
    private _items: object;
    length: number;
    constructor() {
        this._items = {};
        this.length = 0;
    }
    public get container(): any {
        return this._items;
    }
    has(key: any): boolean {
        return this._items.hasOwnProperty(key);
    }

    set(key: any, val: any) {
        if (!this.has(key)) {
            this.length++;
        }
        this._items[key] = val;
    }

    delete<T=any>(key: any): T {
        let val = null;
        if (this.has(key)) {
            val = this._items[key];
            delete this._items[key];
            this.length--;
        }
        return val as T;
    }

    get<T=any>(key: any): T {
        return this.has(key) ? this._items[key] as T : null;
    }

    values(): any[] {
        let values: any[] = [];
        for (let k in this._items) {
            if (this.has(k)) {
                values.push(this._items[k]);
            }
        }
        return values;
    }

    keys(): any[] {
        let keys: any[] = [];
        for (let k in this._items) {
            if (this.has(k)) {
                keys.push(k);
            }
        }
        return keys;
    }

    clear(): void {
        this._items = {};
        this.length = 0;
    }
}