X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FSharedLRUCache.ts;h=d55f358e18809b19e65972287330047440c3ab8b;hb=6a4032b5d8f3cbaa18d3beddcdfe9d335c1cba90;hp=0d7a9dccec5fc04fbe19c4cbba386151d3af0265;hpb=d4d65733e925dcc1b152eef88f3f03e6f25037c3;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index 0d7a9dcc..d55f358e 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -1,8 +1,8 @@ -import { LRUMapWithDelete as LRUCache } from 'mnemonist'; +import LRUCache from 'mnemonist/lru-map-with-delete.js'; import { Bootstrap } from './Bootstrap'; import type { ChargingStationConfiguration, ChargingStationTemplate } from '../types'; -import { Utils } from '../utils'; +import { isEmptyObject, isNotEmptyArray, isNotEmptyString, isNullOrUndefined } from '../utils'; enum CacheType { chargingStationTemplate = 'chargingStationTemplate', @@ -18,7 +18,7 @@ export class SharedLRUCache { private constructor() { this.lruCache = new LRUCache( Bootstrap.getInstance().numberOfChargingStationTemplates + - Bootstrap.getInstance().numberOfChargingStations + Bootstrap.getInstance().numberOfChargingStations, ); } @@ -34,21 +34,21 @@ export class SharedLRUCache { } public setChargingStationConfiguration( - chargingStationConfiguration: ChargingStationConfiguration + chargingStationConfiguration: ChargingStationConfiguration, ): void { if (this.isChargingStationConfigurationCacheable(chargingStationConfiguration)) { this.set( - this.getChargingStationConfigurationKey(chargingStationConfiguration.configurationHash), - chargingStationConfiguration + this.getChargingStationConfigurationKey(chargingStationConfiguration.configurationHash!), + chargingStationConfiguration, ); } } public getChargingStationConfiguration( - chargingStationConfigurationHash: string + chargingStationConfigurationHash: string, ): ChargingStationConfiguration { return this.get( - this.getChargingStationConfigurationKey(chargingStationConfigurationHash) + this.getChargingStationConfigurationKey(chargingStationConfigurationHash), ) as ChargingStationConfiguration; } @@ -62,14 +62,14 @@ export class SharedLRUCache { public setChargingStationTemplate(chargingStationTemplate: ChargingStationTemplate): void { this.set( - this.getChargingStationTemplateKey(chargingStationTemplate.templateHash), - chargingStationTemplate + this.getChargingStationTemplateKey(chargingStationTemplate.templateHash!), + chargingStationTemplate, ); } public getChargingStationTemplate(chargingStationTemplateHash: string): ChargingStationTemplate { return this.get( - this.getChargingStationTemplateKey(chargingStationTemplateHash) + this.getChargingStationTemplateKey(chargingStationTemplateHash), ) as ChargingStationTemplate; } @@ -106,18 +106,17 @@ export class SharedLRUCache { } private isChargingStationConfigurationCacheable( - chargingStationConfiguration: ChargingStationConfiguration + chargingStationConfiguration: ChargingStationConfiguration, ): boolean { return ( - Utils.isNullOrUndefined(chargingStationConfiguration?.configurationKey) === false && - Utils.isNullOrUndefined(chargingStationConfiguration?.stationInfo) === false && - Utils.isNullOrUndefined(chargingStationConfiguration?.automaticTransactionGenerator) === - false && - Utils.isNullOrUndefined(chargingStationConfiguration?.configurationHash) === false && - Utils.isNotEmptyArray(chargingStationConfiguration?.configurationKey) === true && - Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) === false && - Utils.isEmptyObject(chargingStationConfiguration?.automaticTransactionGenerator) === false && - Utils.isNotEmptyString(chargingStationConfiguration?.configurationHash) === true + isNullOrUndefined(chargingStationConfiguration?.configurationKey) === false && + isNullOrUndefined(chargingStationConfiguration?.stationInfo) === false && + isNullOrUndefined(chargingStationConfiguration?.automaticTransactionGenerator) === false && + isNullOrUndefined(chargingStationConfiguration?.configurationHash) === false && + isNotEmptyArray(chargingStationConfiguration?.configurationKey) === true && + isEmptyObject(chargingStationConfiguration.stationInfo!) === false && + isEmptyObject(chargingStationConfiguration.automaticTransactionGenerator!) === false && + isNotEmptyString(chargingStationConfiguration?.configurationHash) === true ); } }