wangzhibo
2026-05-09 53418655c061ac26f66058253f39200aced1ab1d
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
/*
 * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
 * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
 */
 
/**
 * @private
 */
export class EnumMap {
    constructor(){
        this._map = {};
    }
 
    putAll(otherMap){
        for(const key in otherMap._map){
            this._map[key] = otherMap._map[key];
        }
        return this;
    }
 
    containsKey(key){
        // eslint-disable-next-line no-prototype-builtins
        return (this._map.hasOwnProperty(key.name())) && (this.get(key) !== undefined);
    }
 
    get(key) {
        return this._map[key.name()];
    }
 
    put(key, val) {
        return this.set(key, val);
    }
 
    set(key, val) {
        this._map[key.name()] = val;
        return this;
    }
 
    retainAll(keyList){
        const map = {};
        for(let i=0; i<keyList.length; i++){
            const key = keyList[i].name();
            map[key] = this._map[key];
        }
        this._map = map;
        return this;
    }
 
    /**
     * due to the bad performance of delete we just set the key entry to undefined.
     *
     * this might lead to issues with "null" entries. Calling clear in the end might solve the issue
     * @param key
     * @returns {*}
     */
    remove(key){
        const keyName = key.name();
        const val = this._map[keyName];
        this._map[keyName] = undefined;
        return val;
    }
 
    keySet(){
        return this._map;
    }
 
    clear(){
        this._map = {};
    }
}