summaryrefslogtreecommitdiff
path: root/src/node_modules/inversify/lib/container/lookup.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
committerMinteck <contact@minteck.org>2021-12-21 16:52:28 +0100
commit46e43f4bde4a35785b4997b81e86cd19f046b69b (patch)
treec53c2f826f777f9d6b2d249dab556feb72a6c3a6 /src/node_modules/inversify/lib/container/lookup.js
downloadlangdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.gz
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.tar.bz2
langdetect-46e43f4bde4a35785b4997b81e86cd19f046b69b.zip
Commit
Diffstat (limited to 'src/node_modules/inversify/lib/container/lookup.js')
-rw-r--r--src/node_modules/inversify/lib/container/lookup.js79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/node_modules/inversify/lib/container/lookup.js b/src/node_modules/inversify/lib/container/lookup.js
new file mode 100644
index 0000000..912504d
--- /dev/null
+++ b/src/node_modules/inversify/lib/container/lookup.js
@@ -0,0 +1,79 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+var ERROR_MSGS = require("../constants/error_msgs");
+var Lookup = (function () {
+ function Lookup() {
+ this._map = new Map();
+ }
+ Lookup.prototype.getMap = function () {
+ return this._map;
+ };
+ Lookup.prototype.add = function (serviceIdentifier, value) {
+ if (serviceIdentifier === null || serviceIdentifier === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ if (value === null || value === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ var entry = this._map.get(serviceIdentifier);
+ if (entry !== undefined) {
+ entry.push(value);
+ this._map.set(serviceIdentifier, entry);
+ }
+ else {
+ this._map.set(serviceIdentifier, [value]);
+ }
+ };
+ Lookup.prototype.get = function (serviceIdentifier) {
+ if (serviceIdentifier === null || serviceIdentifier === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ var entry = this._map.get(serviceIdentifier);
+ if (entry !== undefined) {
+ return entry;
+ }
+ else {
+ throw new Error(ERROR_MSGS.KEY_NOT_FOUND);
+ }
+ };
+ Lookup.prototype.remove = function (serviceIdentifier) {
+ if (serviceIdentifier === null || serviceIdentifier === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ if (!this._map.delete(serviceIdentifier)) {
+ throw new Error(ERROR_MSGS.KEY_NOT_FOUND);
+ }
+ };
+ Lookup.prototype.removeByCondition = function (condition) {
+ var _this = this;
+ this._map.forEach(function (entries, key) {
+ var updatedEntries = entries.filter(function (entry) { return !condition(entry); });
+ if (updatedEntries.length > 0) {
+ _this._map.set(key, updatedEntries);
+ }
+ else {
+ _this._map.delete(key);
+ }
+ });
+ };
+ Lookup.prototype.hasKey = function (serviceIdentifier) {
+ if (serviceIdentifier === null || serviceIdentifier === undefined) {
+ throw new Error(ERROR_MSGS.NULL_ARGUMENT);
+ }
+ return this._map.has(serviceIdentifier);
+ };
+ Lookup.prototype.clone = function () {
+ var copy = new Lookup();
+ this._map.forEach(function (value, key) {
+ value.forEach(function (b) { return copy.add(key, b.clone()); });
+ });
+ return copy;
+ };
+ Lookup.prototype.traverse = function (func) {
+ this._map.forEach(function (value, key) {
+ func(key, value);
+ });
+ };
+ return Lookup;
+}());
+exports.Lookup = Lookup;