blob: 912504ded7122dd41b34cad8ffa26e232778640c (
plain)
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
71
72
73
74
75
76
77
78
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;
|