From: Jérôme Benoit Date: Sun, 21 Aug 2022 22:05:33 +0000 (+0200) Subject: Implement singleton design pattern with strict null check X-Git-Tag: v1.1.66~30 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1ca780f9d385bcf96a016ab5ba57ca0f19c94b74;p=e-mobility-charging-stations-simulator.git Implement singleton design pattern with strict null check Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AuthorizedTagsCache.ts b/src/charging-station/AuthorizedTagsCache.ts index 4142ee25..d39fbee6 100644 --- a/src/charging-station/AuthorizedTagsCache.ts +++ b/src/charging-station/AuthorizedTagsCache.ts @@ -16,7 +16,7 @@ export default class AuthorizedTagsCache { } public static getInstance(): AuthorizedTagsCache { - if (!AuthorizedTagsCache.instance) { + if (AuthorizedTagsCache.instance === null) { AuthorizedTagsCache.instance = new AuthorizedTagsCache(); } return AuthorizedTagsCache.instance; diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 23307f4c..0fa2c88d 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -60,7 +60,7 @@ export default class Bootstrap { } public static getInstance(): Bootstrap { - if (!Bootstrap.instance) { + if (Bootstrap.instance === null) { Bootstrap.instance = new Bootstrap(); } return Bootstrap.instance; diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index 697cf943..a40de802 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -20,7 +20,7 @@ export default class SharedLRUCache { } public static getInstance(): SharedLRUCache { - if (!SharedLRUCache.instance) { + if (SharedLRUCache.instance === null) { SharedLRUCache.instance = new SharedLRUCache(); } return SharedLRUCache.instance; diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 5be2629a..23d0ffdd 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -22,7 +22,7 @@ export default abstract class OCPPIncomingRequestService { } public static getInstance(this: new () => T): T { - if (!OCPPIncomingRequestService.instance) { + if (OCPPIncomingRequestService.instance === null) { OCPPIncomingRequestService.instance = new this(); } return OCPPIncomingRequestService.instance as T; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 1ae25a65..6f4e47be 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -45,7 +45,7 @@ export default abstract class OCPPRequestService { this: new (ocppResponseService: OCPPResponseService) => T, ocppResponseService: OCPPResponseService ): T { - if (!OCPPRequestService.instance) { + if (OCPPRequestService.instance === null) { OCPPRequestService.instance = new this(ocppResponseService); } return OCPPRequestService.instance as T; diff --git a/src/charging-station/ocpp/OCPPResponseService.ts b/src/charging-station/ocpp/OCPPResponseService.ts index eb49b752..624659ae 100644 --- a/src/charging-station/ocpp/OCPPResponseService.ts +++ b/src/charging-station/ocpp/OCPPResponseService.ts @@ -21,7 +21,7 @@ export default abstract class OCPPResponseService { } public static getInstance(this: new () => T): T { - if (!OCPPResponseService.instance) { + if (OCPPResponseService.instance === null) { OCPPResponseService.instance = new this(); } return OCPPResponseService.instance as T;