UNPKG

ts-collection

Version:

This is re-write of the java collection classes in typescript. There is some tweak as typescript templates are not as equivalent as Java.

74 lines (73 loc) 2.59 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var abstractcollection_1 = require("./abstractcollection"); var illegalstateexception_1 = require("../lang/illegalstateexception"); var nosuchelementexception_1 = require("./nosuchelementexception"); var nullpointerexception_1 = require("../lang/nullpointerexception"); var illegalargumentexception_1 = require("../lang/illegalargumentexception"); var AbstractQueue = /** @class */ (function (_super) { __extends(AbstractQueue, _super); function AbstractQueue() { return _super.call(this) || this; } AbstractQueue.prototype.enqueue = function (e) { if (this.offer(e)) { return true; } else { throw new illegalstateexception_1.IllegalStateException('queue full'); } }; AbstractQueue.prototype.dequeue = function () { var x = this.poll(); if (x !== null) { return x; } else { throw new nosuchelementexception_1.NoSuchElementException(); } }; AbstractQueue.prototype.element = function () { var x = this.peek(); if (x !== null) { return x; } else { throw new nosuchelementexception_1.NoSuchElementException(); } }; AbstractQueue.prototype.clear = function () { while (this.poll() !== null) ; }; AbstractQueue.prototype.addAll = function (c) { if (c === null) { throw new nullpointerexception_1.NullPointerException(); } if (c === this) { throw new illegalargumentexception_1.IllegalArgumentException(); } var modified = false; var itr = c.iterator(); while (itr.hasNext()) { this.enqueue(itr.next()); modified = true; } return modified; }; return AbstractQueue; }(abstractcollection_1.AbstractCollection)); exports.AbstractQueue = AbstractQueue;