build(deps-dev): apply updates
[e-mobility-charging-stations-simulator.git] / src / charging-station / SharedLRUCache.ts
index d2d638690fdb755ead4c5f5b68842cf22ba53b4c..9fd940795bbe33788589c528e74b058672a202a1 100644 (file)
@@ -1,24 +1,24 @@
-import LRUCache from 'mnemonist/lru-map-with-delete';
+import LRUCache from 'mnemonist/lru-map-with-delete.js';
 
-import { Bootstrap } from './internal';
+import { Bootstrap } from './Bootstrap';
 import type { ChargingStationConfiguration, ChargingStationTemplate } from '../types';
-import { Utils } from '../utils/Utils';
+import { isEmptyObject, isNotEmptyArray, isNotEmptyString, isNullOrUndefined } 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 class SharedLRUCache {
   private static instance: SharedLRUCache | null = null;
-  private readonly lruCache: LRUCache<string, CacheableType>;
+  private readonly lruCache: LRUCache<string, CacheValueType>;
 
   private constructor() {
-    this.lruCache = new LRUCache<string, CacheableType>(
+    this.lruCache = new LRUCache<string, CacheValueType>(
       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
+        chargingStationConfiguration,
       );
     }
   }
 
   public getChargingStationConfiguration(
-    chargingStationConfigurationHash: string
+    chargingStationConfigurationHash: string,
   ): ChargingStationConfiguration {
     return this.get(
-      this.getChargingStationConfigurationKey(chargingStationConfigurationHash)
+      this.getChargingStationConfigurationKey(chargingStationConfigurationHash),
     ) as ChargingStationConfiguration;
   }
 
@@ -63,13 +63,13 @@ export class SharedLRUCache {
   public setChargingStationTemplate(chargingStationTemplate: ChargingStationTemplate): void {
     this.set(
       this.getChargingStationTemplateKey(chargingStationTemplate.templateHash),
-      chargingStationTemplate
+      chargingStationTemplate,
     );
   }
 
   public getChargingStationTemplate(chargingStationTemplateHash: string): ChargingStationTemplate {
     return this.get(
-      this.getChargingStationTemplateKey(chargingStationTemplateHash)
+      this.getChargingStationTemplateKey(chargingStationTemplateHash),
     ) as ChargingStationTemplate;
   }
 
@@ -82,22 +82,22 @@ export 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);
   }
 
@@ -106,15 +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?.configurationHash) === false &&
-      Utils.isNotEmptyArray(chargingStationConfiguration?.configurationKey) === true &&
-      Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) === 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
     );
   }
 }