UNPKG

nowjs-core

Version:

NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence

81 lines (80 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../linq/index"); const Collection_1 = require("./Collection"); const List_1 = require("./List"); class Queue { constructor(enumerable) { this.arr = []; if (enumerable && enumerable[Symbol.iterator]) { for (const x of enumerable) { this.enqueue(x); } } } isEmpty() { return this.size === 0; } contains(item) { return (this.arr.findIndex(xx => { return xx === item; }) >= 0); } get size() { return this.arr.length; } clear() { this.arr = []; return true; } enqueue(...rest) { if (rest instanceof Array) { for (const xx of rest) { this.arr.push(xx); } return true; } else { this.arr.push(rest); return true; } } dequeue() { return this.arr.shift(); } peek() { if (this.arr.length > 0) return this.arr[0]; else return null; } toArray() { const array = []; for (const xx of this) { array.push(xx); } return array; } toCollection() { return new Collection_1.Collection(this); } toList() { return new List_1.List(this); } toSet() { return new Set(this); } linq() { return new index_1.Enumerable(this); } plinq() { return new index_1.ParallelEnumerable(this); } [Symbol.iterator]() { return this.arr[Symbol.iterator](); } clone() { return new Queue(this); } } exports.Queue = Queue;