diff --git a/packages/utils/src/Domain/Uuid/UuidMap.ts b/packages/utils/src/Domain/Uuid/UuidMap.ts index 2c2c93a61..dea1c8916 100644 --- a/packages/utils/src/Domain/Uuid/UuidMap.ts +++ b/packages/utils/src/Domain/Uuid/UuidMap.ts @@ -6,39 +6,39 @@ import { addIfUnique, removeFromArray } from '../Utils/Utils' */ export class UuidMap { /** uuid to uuids that we have a relationship with */ - private directMap: Partial> = {} + private directMap: Map = new Map() /** uuid to uuids that have a relationship with us */ - private inverseMap: Partial> = {} + private inverseMap: Map = new Map() public get directMapSize(): number { - return Object.keys(this.directMap).length + return this.directMap.size } public get inverseMapSize(): number { - return Object.keys(this.inverseMap).length + return this.inverseMap.size } public makeCopy(): UuidMap { const copy = new UuidMap() - copy.directMap = Object.assign({}, this.directMap) - copy.inverseMap = Object.assign({}, this.inverseMap) + copy.directMap = new Map(this.directMap) + copy.inverseMap = new Map(this.inverseMap) return copy } public existsInDirectMap(uuid: string): boolean { - return uuid in this.directMap + return this.directMap.has(uuid) } public existsInInverseMap(uuid: string): boolean { - return uuid in this.inverseMap + return this.inverseMap.has(uuid) } public getDirectRelationships(uuid: string): string[] { - return this.directMap[uuid] || [] + return this.directMap.get(uuid) || [] } public getInverseRelationships(uuid: string): string[] { - return this.inverseMap[uuid] || [] + return this.inverseMap.get(uuid) || [] } public establishRelationship(uuidA: string, uuidB: string): void { @@ -52,8 +52,8 @@ export class UuidMap { } public setAllRelationships(uuid: string, relationships: string[]): void { - const previousDirect = this.directMap[uuid] || [] - this.directMap[uuid] = relationships + const previousDirect = this.directMap.get(uuid) || [] + this.directMap.set(uuid, relationships) /** Remove all previous values in case relationships have changed * The updated references will be added afterwards. @@ -70,41 +70,41 @@ export class UuidMap { public removeFromMap(uuid: string): void { /** Items that we reference */ - const directReferences = this.directMap[uuid] || [] + const directReferences = this.directMap.get(uuid) || [] for (const directReference of directReferences) { - removeFromArray(this.inverseMap[directReference] || [], uuid) + removeFromArray(this.inverseMap.get(directReference) || [], uuid) } - delete this.directMap[uuid] + this.directMap.delete(uuid) /** Items that are referencing us */ - const inverseReferences = this.inverseMap[uuid] || [] + const inverseReferences = this.inverseMap.get(uuid) || [] for (const inverseReference of inverseReferences) { - removeFromArray(this.directMap[inverseReference] || [], uuid) + removeFromArray(this.directMap.get(inverseReference) || [], uuid) } - delete this.inverseMap[uuid] + this.inverseMap.delete(uuid) } private establishDirectRelationship(uuidA: string, uuidB: string): void { - const index = this.directMap[uuidA] || [] + const index = this.directMap.get(uuidA) || [] addIfUnique(index, uuidB) - this.directMap[uuidA] = index + this.directMap.set(uuidA, index) } private establishInverseRelationship(uuidA: string, uuidB: string): void { - const inverseIndex = this.inverseMap[uuidB] || [] + const inverseIndex = this.inverseMap.get(uuidB) || [] addIfUnique(inverseIndex, uuidA) - this.inverseMap[uuidB] = inverseIndex + this.inverseMap.set(uuidB, inverseIndex) } private deestablishDirectRelationship(uuidA: string, uuidB: string): void { - const index = this.directMap[uuidA] || [] + const index = this.directMap.get(uuidA) || [] removeFromArray(index, uuidB) - this.directMap[uuidA] = index + this.directMap.set(uuidA, index) } private deestablishInverseRelationship(uuidA: string, uuidB: string): void { - const inverseIndex = this.inverseMap[uuidB] || [] + const inverseIndex = this.inverseMap.get(uuidB) || [] removeFromArray(inverseIndex, uuidA) - this.inverseMap[uuidB] = inverseIndex + this.inverseMap.set(uuidB, inverseIndex) } }