this.numberOfChargingStationTemplates = 0;
this.numberOfChargingStations = 0;
const stationTemplateUrls = Configuration.getStationTemplateUrls();
- if (!Utils.isEmptyArray(stationTemplateUrls)) {
+ if (Utils.isNotEmptyArray(stationTemplateUrls)) {
this.numberOfChargingStationTemplates = stationTemplateUrls.length;
stationTemplateUrls.forEach((stationTemplateUrl) => {
this.numberOfChargingStations += stationTemplateUrl.numberOfStations ?? 0;
};
public hasAuthorizedTags(): boolean {
- return !Utils.isEmptyArray(
+ return Utils.isNotEmptyArray(
this.authorizedTagsCache.getAuthorizedTags(
ChargingStationUtils.getAuthorizationFile(this.stationInfo)
)
this.getAutomaticTransactionGeneratorConfigurationFromTemplate(),
this
);
- if (!Utils.isEmptyArray(connectorIds)) {
+ if (Utils.isNotEmptyArray(connectorIds)) {
for (const connectorId of connectorIds) {
this.automaticTransactionGenerator?.startConnector(connectorId);
}
}
public stopAutomaticTransactionGenerator(connectorIds?: number[]): void {
- if (!Utils.isEmptyArray(connectorIds)) {
+ if (Utils.isNotEmptyArray(connectorIds)) {
for (const connectorId of connectorIds) {
this.automaticTransactionGenerator?.stopConnector(connectorId);
}
);
stationInfo.ocppVersion = stationTemplate?.ocppVersion ?? OCPPVersion.VERSION_16;
ChargingStationUtils.createSerialNumber(stationTemplate, stationInfo);
- if (!Utils.isEmptyArray(stationTemplate?.power)) {
+ if (Utils.isNotEmptyArray(stationTemplate?.power)) {
stationTemplate.power = stationTemplate.power as number[];
const powerArrayRandomIndex = Math.floor(Utils.secureRandom() * stationTemplate.power.length);
stationInfo.maximumPower =
private getConfiguredSupervisionUrl(): URL {
const supervisionUrls = this.stationInfo?.supervisionUrls ?? Configuration.getSupervisionUrls();
- if (!Utils.isEmptyArray(supervisionUrls)) {
+ if (Utils.isNotEmptyArray(supervisionUrls)) {
switch (Configuration.getSupervisionUrlDistribution()) {
case SupervisionUrlDistribution.ROUND_ROBIN:
// FIXME
public static getConfiguredNumberOfConnectors(stationTemplate: ChargingStationTemplate): number {
let configuredMaxConnectors: number;
- if (Utils.isEmptyArray(stationTemplate.numberOfConnectors) === false) {
+ if (Utils.isNotEmptyArray(stationTemplate.numberOfConnectors) === true) {
const numberOfConnectors = stationTemplate.numberOfConnectors as number[];
configuredMaxConnectors =
numberOfConnectors[Math.floor(Utils.secureRandom() * numberOfConnectors.length)];
.chargingProfiles.sort((a, b) => b.stackLevel - a.stackLevel)
);
}
- if (!Utils.isEmptyArray(chargingProfiles)) {
+ if (Utils.isNotEmptyArray(chargingProfiles)) {
const result = ChargingStationUtils.getLimitFromChargingProfiles(
chargingProfiles,
chargingStation.logPrefix()
Utils.isNullOrUndefined(chargingStationConfiguration?.configurationKey) === false &&
Utils.isNullOrUndefined(chargingStationConfiguration?.stationInfo) === false &&
Utils.isNullOrUndefined(chargingStationConfiguration?.configurationHash) === false &&
- Utils.isEmptyArray(chargingStationConfiguration?.configurationKey) === false &&
+ Utils.isNotEmptyArray(chargingStationConfiguration?.configurationKey) === true &&
Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) === false &&
Utils.isNotEmptyString(chargingStationConfiguration?.configurationHash) === true
);
const connectorStatus = chargingStation.getConnectorStatus(commandPayload.connectorId);
if (
!Utils.isNullOrUndefined(commandPayload.connectorId) &&
- !Utils.isEmptyArray(connectorStatus?.chargingProfiles)
+ Utils.isNotEmptyArray(connectorStatus?.chargingProfiles)
) {
connectorStatus.chargingProfiles = [];
logger.debug(
let clearedCP = false;
for (const connectorId of chargingStation.connectors.keys()) {
if (
- !Utils.isEmptyArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)
+ Utils.isNotEmptyArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)
) {
chargingStation
.getConnectorStatus(connectorId)
chargingStation.getConnectorStatus(connectorId).chargingProfiles = [];
}
let cpReplaced = false;
- if (!Utils.isEmptyArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)) {
+ if (Utils.isNotEmptyArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles)) {
chargingStation
.getConnectorStatus(connectorId)
?.chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => {
chargingStation.getConnectorStatus(connectorId)?.MeterValues;
for (
let index = 0;
- Utils.isEmptyArray(sampledValueTemplates) === false && index < sampledValueTemplates.length;
+ Utils.isNotEmptyArray(sampledValueTemplates) === true && index < sampledValueTemplates.length;
index++
) {
if (
procedureName: BroadcastChannelProcedureName,
payload: BroadcastChannelRequestPayload
): void {
- if (!Utils.isEmptyArray(payload.hashIds)) {
+ if (Utils.isNotEmptyArray(payload.hashIds)) {
payload.hashIds = payload.hashIds
.map((hashId) => {
if (this.uiServer.chargingStations.has(hashId) === true) {
})
.filter((hashId) => hashId !== undefined);
}
- const expectedNumberOfResponses = !Utils.isEmptyArray(payload.hashIds)
+ const expectedNumberOfResponses = Utils.isNotEmptyArray(payload.hashIds)
? payload.hashIds.length
: this.uiServer.chargingStations.size;
this.uiServiceWorkerBroadcastChannel.sendRequest([uuid, procedureName, payload]);
}
public static isEmptyArray(object: unknown | unknown[]): boolean {
- if (!Array.isArray(object)) {
+ if (Array.isArray(object) && object.length === 0) {
return true;
}
- if (object.length > 0) {
- return false;
+ return false;
+ }
+
+ public static isNotEmptyArray(object: unknown | unknown[]): boolean {
+ if (Array.isArray(object) && object.length > 0) {
+ return true;
}
- return true;
+ return false;
}
public static isEmptyObject(obj: object): boolean {
it('Verify isEmptyArray()', () => {
expect(Utils.isEmptyArray([])).toBe(true);
expect(Utils.isEmptyArray([1, 2])).toBe(false);
- expect(Utils.isEmptyArray(undefined)).toBe(true);
- expect(Utils.isEmptyArray(null)).toBe(true);
- expect(Utils.isEmptyArray('')).toBe(true);
- expect(Utils.isEmptyArray('test')).toBe(true);
- expect(Utils.isEmptyArray(0)).toBe(true);
- expect(Utils.isEmptyArray({})).toBe(true);
- expect(Utils.isEmptyArray(new Map())).toBe(true);
- expect(Utils.isEmptyArray(new Set())).toBe(true);
- expect(Utils.isEmptyArray(new WeakMap())).toBe(true);
- expect(Utils.isEmptyArray(new WeakSet())).toBe(true);
+ expect(Utils.isEmptyArray(['1', '2'])).toBe(false);
+ expect(Utils.isEmptyArray(undefined)).toBe(false);
+ expect(Utils.isEmptyArray(null)).toBe(false);
+ expect(Utils.isEmptyArray('')).toBe(false);
+ expect(Utils.isEmptyArray('test')).toBe(false);
+ expect(Utils.isEmptyArray(0)).toBe(false);
+ expect(Utils.isEmptyArray({})).toBe(false);
+ expect(Utils.isEmptyArray(new Map())).toBe(false);
+ expect(Utils.isEmptyArray(new Set())).toBe(false);
+ expect(Utils.isEmptyArray(new WeakMap())).toBe(false);
+ expect(Utils.isEmptyArray(new WeakSet())).toBe(false);
+ });
+
+ it('Verify isNotEmptyArray()', () => {
+ expect(Utils.isNotEmptyArray([])).toBe(false);
+ expect(Utils.isNotEmptyArray([1, 2])).toBe(true);
+ expect(Utils.isNotEmptyArray(['1', '2'])).toBe(true);
+ expect(Utils.isNotEmptyArray(undefined)).toBe(false);
+ expect(Utils.isNotEmptyArray(null)).toBe(false);
+ expect(Utils.isNotEmptyArray('')).toBe(false);
+ expect(Utils.isNotEmptyArray('test')).toBe(false);
+ expect(Utils.isNotEmptyArray(0)).toBe(false);
+ expect(Utils.isNotEmptyArray({})).toBe(false);
+ expect(Utils.isNotEmptyArray(new Map())).toBe(false);
+ expect(Utils.isNotEmptyArray(new Set())).toBe(false);
+ expect(Utils.isNotEmptyArray(new WeakMap())).toBe(false);
+ expect(Utils.isNotEmptyArray(new WeakSet())).toBe(false);
});
it('Verify isEmptyObject()', () => {