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.

123 lines (122 loc) 3.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var unsupportedoperationexception_1 = require("../lang/unsupportedoperationexception"); var nullpointerexception_1 = require("../lang/nullpointerexception"); var illegalargumentexception_1 = require("../lang/illegalargumentexception"); var AbstractCollection = /** @class */ (function () { function AbstractCollection() { } AbstractCollection.prototype.isEmpty = function () { return this.size() === 0; }; AbstractCollection.prototype.contains = function (e) { var it = this.iterator(); var eAny = e; if (eAny.equals !== undefined) { while (it.hasNext()) { if (eAny.equals(it.next())) { return true; } } } else { while (it.hasNext()) { if (e === it.next()) { return true; } } } return false; }; AbstractCollection.prototype.toArray = function () { var arr = []; var itr = this.iterator(); while (itr.hasNext()) { arr.push(itr.next()); } return arr; }; AbstractCollection.prototype.add = function (e) { throw new unsupportedoperationexception_1.UnsupportedOperationException(); }; AbstractCollection.prototype.remove = function (e) { var it = this.iterator(); var eAny = e; if (eAny.equals !== undefined) { while (it.hasNext()) { if (eAny.equals(it.next())) { it.remove(); return true; } } } else { while (it.hasNext()) { if (eAny === it.next()) { it.remove(); return true; } } } return false; }; AbstractCollection.prototype.containsAll = function (c) { var it = c.iterator(); while (it.hasNext()) { if (!this.contains(it.next())) { return false; } } return true; }; AbstractCollection.prototype.addAll = function (c) { var modified = false; var it = this.iterator(); while (it.hasNext()) { modified = modified || this.add(it.next()); } return modified; }; AbstractCollection.prototype.removeAll = function (c) { if (c === null) { throw new nullpointerexception_1.NullPointerException(); } var modified = false; var it = this.iterator(); while (it.hasNext()) { if (c.contains(it.next())) { it.remove(); modified = true; } } return modified; }; AbstractCollection.prototype.retainAll = function (c) { if (c === null) { throw new nullpointerexception_1.NullPointerException(); } var modified = false; var it = this.iterator(); while (it.hasNext()) { if (!c.contains(it.next())) { it.remove(); modified = true; } } return modified; }; AbstractCollection.prototype.clear = function () { var it = this.iterator(); while (it.hasNext()) { it.next(); it.remove(); } }; AbstractCollection.prototype.checkForObjectCompatiability = function (o) { if (typeof o.equals !== 'function') { throw new illegalargumentexception_1.IllegalArgumentException(); } }; return AbstractCollection; }()); exports.AbstractCollection = AbstractCollection;