-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneToOneSimpleMap.mjs
76 lines (76 loc) · 2.51 KB
/
OneToOneSimpleMap.mjs
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
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/**
* @file
* This is generated code. Do not edit.
*
* Generator: https://github.com/ajvincent/composite-collection/
* Template: OneToOne/Map
* @license MPL-2.0
* @author Alexander J. Vincent <[email protected]>
* @copyright © 2021-2022 Alexander J. Vincent
*/
class OneToOneSimpleMap extends WeakMap {
/**
* Bind two values together.
*
* @param {object} value_1 The value.
* @param {object} value_2 The value.
* @public
*/
bindOneToOne(value_1, value_2) {
const __hasValue1__ = this.has(value_1);
const __hasValue2__ = this.has(value_2);
if (__hasValue1__ && (this.get(value_2) !== value_1))
throw new Error("value_1 mismatch!");
if (__hasValue2__ && (this.get(value_1) !== value_2))
throw new Error("value_2 mismatch!");
if (!this.isValidValue(value_1))
throw new Error("value_1 is not a valid value!");
if (!this.isValidValue(value_2))
throw new Error("value_2 is not a valid value!");
if (!__hasValue1__)
super.set(value_1, value_2);
if (!__hasValue2__)
super.set(value_2, value_1);
}
/**
* Determine if a target value is an identity in this map.
*
* @param {object} value The value.
* @param {boolean} allowNotDefined If true, treat the absence of the value as an identity.
* @returns {boolean} True if the target value exists.
* @public
*/
hasIdentity(value, allowNotDefined) {
if (!this.has(value)) {
return Boolean(allowNotDefined);
}
// Beyond this point we should return true.
const __other__ = this.get(value);
return this.get(__other__) === value;
}
/**
* Determine if a value is valid.
*
* @param {*} value The value.
* @returns {boolean} True if the value is valid.
* @public
*/
isValidValue(value) {
return Object(value) === value;
}
set(key, value) {
void (key);
void (value);
throw new Error("Not implemented, use .bindOneToOne(value_1, value_2);");
}
[Symbol.toStringTag] = "OneToOneSimpleMap";
}
Object.freeze(OneToOneSimpleMap);
Object.freeze(OneToOneSimpleMap.prototype);
export default OneToOneSimpleMap;
//# sourceMappingURL=OneToOneSimpleMap.mjs.map