all files / src/ chain-state.ts

92.31% Statements 24/26
80% Branches 8/10
100% Functions 5/5
95.24% Lines 20/21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36       149×     149× 269× 149×                   379×    
import * as Collections from "typescript-collections";
 
export class ChainState<T> {
    public readonly items: T[];
 
    constructor(items: Collections.Queue<T>) {
        Iif (!items) {
            throw new ReferenceError("Items cannot be null.");
        }
        const arr: T[] = new Array();
        items.forEach(i => { arr.push(i); return true; });
        this.items = arr;
    }
 
    equals(other: ChainState<T>): boolean {
        Iif (!other) { return false; }
        if (this.items.length !== other.items.length) {
            return false;
        }
 
        for (let x = 0; x < this.items.length; x++) {
            const left = this.items[x], right = other.items[x];
            if (left === right) { continue; }
            if (Collections.util.makeString(left) !== Collections.util.makeString(right)) {
                return false;
            }
        }
 
        return true;
    }
 
    toString(): string {
        return Collections.util.makeString(this.items);
    }
};