UNPKG

ern-api-gen

Version:

Electrode Native API generator

98 lines 2.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const FakeHashSet_1 = require("./FakeHashSet"); class FakeHashMap { constructor(...args) { this.value = {}; for (const [k, v] of args) { this.value[k] = v; } } static toEntry(key) { const self = this; return { getValue() { return self[key]; }, getKey() { return key; }, }; } [Symbol.iterator]() { const { value } = this; const it = Object.keys(value)[Symbol.iterator](); return { next() { const n = it.next(); if (!n.done) { n.value = [n.value, value[n.value]]; } return n; }, }; } put(key, value) { return (this.value[key] = value); } putAll(all) { if (Symbol.iterator in all) { for (const [key, value] of all) { this.value[key] = value; } } else { for (const key of Object.keys(all)) { this.value[key] = all[key]; } } } entrySet() { return new FakeHashSet_1.FakeHashSet(...Object.keys(this.value).map(FakeHashMap.toEntry, this.value)); } keySet() { return new FakeHashSet_1.FakeHashSet(...Object.keys(this.value)); } isEmpty() { return this.size === 0; } remove(key) { return delete this.value[key]; } clear() { this.value = {}; } values() { const values = []; for (const [k, v] of this) { values.push(v); } return values; } containsValue(value) { for (const key of Object.keys(this.value)) { if (this.value[key] === value) { return true; } } return false; } containsKey(value) { return value in this.value; } get(key) { return this.value[key]; } get size() { return Object.keys(this.value).length; } toJSON() { return this.value; } } exports.FakeHashMap = FakeHashMap; function newHashMap(...args) { return new FakeHashMap(...args); } exports.default = newHashMap; //# sourceMappingURL=fakeMap.js.map