X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FSharedLRUCache.ts;h=1243d6aebe4409d40dda5439bf01ced413ab594c;hb=12f26d4a81773cf8ede8bad4255e36aadf10bce0;hp=db5269f5317e83508014ec374d36396f5a6ff856;hpb=d1c99c59787e98b3954760fbc208a5dfbc3d8f57;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/SharedLRUCache.ts b/src/charging-station/SharedLRUCache.ts index db5269f5..1243d6ae 100644 --- a/src/charging-station/SharedLRUCache.ts +++ b/src/charging-station/SharedLRUCache.ts @@ -1,25 +1,24 @@ -import LRUCache from 'mnemonist/lru-map-with-delete'; +import LRUCache from 'mnemonist/lru-map-with-delete.js'; -import { Bootstrap } from '../internal'; -import type { ChargingStationConfiguration } from '../types/ChargingStationConfiguration'; -import type { ChargingStationTemplate } from '../types/ChargingStationTemplate'; -import Utils from '../utils/Utils'; +import { Bootstrap } from './internal'; +import type { ChargingStationConfiguration, ChargingStationTemplate } from '../types'; +import { Utils } from '../utils'; enum CacheType { - CHARGING_STATION_TEMPLATE = 'chargingStationTemplate', - CHARGING_STATION_CONFIGURATION = 'chargingStationConfiguration', + chargingStationTemplate = 'chargingStationTemplate', + chargingStationConfiguration = 'chargingStationConfiguration', } -type CacheableType = ChargingStationTemplate | ChargingStationConfiguration; +type CacheValueType = ChargingStationTemplate | ChargingStationConfiguration; -export default class SharedLRUCache { +export class SharedLRUCache { private static instance: SharedLRUCache | null = null; - private readonly lruCache: LRUCache; + private readonly lruCache: LRUCache; private constructor() { - this.lruCache = new LRUCache( - Bootstrap.getInstance().numberOfChargingStations + - Bootstrap.getInstance().numberOfChargingStationTemplates + this.lruCache = new LRUCache( + Bootstrap.getInstance().numberOfChargingStationTemplates + + Bootstrap.getInstance().numberOfChargingStations ); } @@ -83,22 +82,22 @@ export default class SharedLRUCache { } private getChargingStationConfigurationKey(hash: string): string { - return `${CacheType.CHARGING_STATION_CONFIGURATION}${hash}`; + return `${CacheType.chargingStationConfiguration}${hash}`; } private getChargingStationTemplateKey(hash: string): string { - return `${CacheType.CHARGING_STATION_TEMPLATE}${hash}`; + return `${CacheType.chargingStationTemplate}${hash}`; } private has(key: string): boolean { return this.lruCache.has(key); } - private get(key: string): CacheableType | undefined { + private get(key: string): CacheValueType | undefined { return this.lruCache.get(key); } - private set(key: string, value: CacheableType): void { + private set(key: string, value: CacheValueType): void { this.lruCache.set(key, value); } @@ -112,10 +111,13 @@ export default class SharedLRUCache { return ( Utils.isNullOrUndefined(chargingStationConfiguration?.configurationKey) === false && Utils.isNullOrUndefined(chargingStationConfiguration?.stationInfo) === false && + Utils.isNullOrUndefined(chargingStationConfiguration?.automaticTransactionGenerator) === + false && Utils.isNullOrUndefined(chargingStationConfiguration?.configurationHash) === false && - Utils.isEmptyArray(chargingStationConfiguration?.configurationKey) === false && + Utils.isNotEmptyArray(chargingStationConfiguration?.configurationKey) === true && Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) === false && - Utils.isEmptyString(chargingStationConfiguration?.configurationHash) === false + Utils.isEmptyObject(chargingStationConfiguration?.automaticTransactionGenerator) === false && + Utils.isNotEmptyString(chargingStationConfiguration?.configurationHash) === true ); } }