- splice(start: number, deleteCount?: number, ...items: T[]): T[] {
- this.push(...items);
- return super.splice(start, deleteCount);
+ public splice(start: number, deleteCount?: number, ...items: T[]): T[] {
+ let itemsRemoved: T[];
+ if (arguments.length >= 3 && typeof deleteCount !== 'undefined') {
+ itemsRemoved = super.splice(start, deleteCount);
+ // FIXME: that makes the items insert not in place
+ this.push(...items);
+ } else if (arguments.length === 2) {
+ itemsRemoved = super.splice(start, deleteCount);
+ } else {
+ itemsRemoved = super.splice(start);
+ }
+ return itemsRemoved;
+ }
+
+ public resize(size: number): void {
+ this.checkSize(size);
+ if (size === 0) {
+ this.length = 0;
+ } else if (size < this.size) {
+ for (let i = size; i < this.size; i++) {
+ super.pop();
+ }
+ }
+ this.size = size;
+ }
+
+ public empty(): boolean {
+ return this.length === 0;
+ }
+
+ public full(): boolean {
+ return this.length === this.size;
+ }
+
+ private checkSize(size: number) {
+ if (size < 0) {
+ throw new RangeError('Invalid circular array size');
+ }