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.

116 lines (115 loc) 3.75 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 abstractlist_1 = require("./abstractlist"); var ArrayList = /** @class */ (function (_super) { __extends(ArrayList, _super); function ArrayList(c) { var _this = _super.call(this) || this; _this.m_Elements = new Array(); if (c !== undefined) { //TODO to be converted to c.toArray() var cItr = c.iterator(); while (cItr.hasNext()) { _this.add(cItr.next()); } } return _this; } ArrayList.prototype.size = function () { return this.m_Elements.length; }; ArrayList.prototype.isEmpty = function () { return this.m_Elements.length === 0; }; ArrayList.prototype.contains = function (e) { return this.indexOf(e) >= 0; }; ArrayList.prototype.indexOf = function (e) { if (e === null) { for (var i = 0; i < this.m_Elements.length; i++) { if (this.m_Elements[i] === null) { return i; } } } else { for (var i = 0; i < this.m_Elements.length; i++) { var eAny = e; if (eAny.equals(this.m_Elements[i])) { return i; } } } return -1; }; ArrayList.prototype.lastIndexOf = function (e) { if (e === null) { for (var i = this.m_Elements.length - 1; i >= 0; i--) { if (this.m_Elements[i] === null) { return i; } } } else { var eAny = e; for (var i = this.m_Elements.length - 1; i >= 0; i--) { if (eAny.equals(this.m_Elements[i])) { return i; } } } return -1; }; ArrayList.prototype.get = function (index) { this.rangeCheck(index); return this.m_Elements[index]; }; ArrayList.prototype.setAt = function (index, e) { this.rangeCheck(index); var oldValue = this.m_Elements[index]; this.m_Elements[index] = e; return oldValue; }; ArrayList.prototype.add = function (value) { this.m_Elements.push(value); return true; }; ArrayList.prototype.addAt = function (index, e) { this.rangeCheckForAdd(index); this.m_Elements.splice(index, 0, e); }; ArrayList.prototype.remove = function (e) { var index = this.indexOf(e); if (index < 0) { return false; } this.m_Elements.splice(index, 1); }; ArrayList.prototype.removeAt = function (index) { this.rangeCheck(index); var e = this.m_Elements[index]; this.m_Elements.splice(index, 1); return e; }; ArrayList.prototype.sort = function (cmp) { this.m_Elements.sort(cmp.compare); }; ArrayList.prototype.clear = function () { this.m_Elements = new Array(); }; return ArrayList; }(abstractlist_1.AbstractList)); exports.ArrayList = ArrayList;