X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FCircularArray.ts;h=ba3eba19231ab7b7dff4eef88e27461ecc29c7f5;hb=1e924543e08745cfa9642dca53d303390d391f00;hp=434a8f49b57439a127a56d568ec6f570765d9073;hpb=b6633b4c519a0aa579ed9c0653fa78fe99f6487b;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/CircularArray.ts b/src/utils/CircularArray.ts index 434a8f49..ba3eba19 100644 --- a/src/utils/CircularArray.ts +++ b/src/utils/CircularArray.ts @@ -1,11 +1,11 @@ -import Constants from './Constants'; export default class CircularArray extends Array { public size: number; + private readonly maximumCircularArraySize = 2000; - constructor(size: number = Constants.MAXIMUM_MEASUREMENTS_NUMBER) { + constructor(size?: number) { super(); - this.size = size; + this.size = size && size <= this.maximumCircularArraySize ? size : this.maximumCircularArraySize; } push(...items: T[]): number { @@ -21,4 +21,16 @@ export default class CircularArray extends Array { } return super.unshift(...items); } + + concat(...items: (T | ConcatArray)[]): T[] { + if (this.length + items.length > this.size) { + super.splice(0, (this.length + items.length) - this.size); + } + return super.concat(items as T[]); + } + + splice(start: number, deleteCount?: number, ...items: T[]): T[] { + this.push(...items); + return super.splice(start, deleteCount); + } }