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.
99 lines (98 loc) • 3.67 kB
JavaScript
;
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 nosuchelementexception_1 = require("./nosuchelementexception");
var indexoutofboundsexception_1 = require("./indexoutofboundsexception");
var AbstractSequentialList = /** @class */ (function (_super) {
__extends(AbstractSequentialList, _super);
function AbstractSequentialList() {
return _super !== null && _super.apply(this, arguments) || this;
}
AbstractSequentialList.prototype.getAt = function (index) {
try {
return this.listIteratorFrom(index).next();
}
catch (ex) {
if (ex instanceof nosuchelementexception_1.NoSuchElementException) {
throw new indexoutofboundsexception_1.IndexOutOfBoundsException('Index: ' + index);
}
else {
throw ex;
}
}
};
AbstractSequentialList.prototype.set = function (index, element) {
try {
var e = this.listIteratorFrom(index);
var oldVal = e.next();
e.set(element);
return oldVal;
}
catch (ex) {
if (ex instanceof nosuchelementexception_1.NoSuchElementException) {
throw new indexoutofboundsexception_1.IndexOutOfBoundsException('Index: ' + index);
}
else {
throw ex;
}
}
};
AbstractSequentialList.prototype.addAt = function (index, element) {
try {
this.listIteratorFrom(index).add(element);
}
catch (ex) {
if (ex instanceof nosuchelementexception_1.NoSuchElementException) {
ex = new indexoutofboundsexception_1.IndexOutOfBoundsException('Index: ' + index);
}
throw ex;
}
};
AbstractSequentialList.prototype.removeAt = function (index) {
try {
var e = this.listIteratorFrom(index);
var out = e.next();
e.remove();
return out;
}
catch (ex) {
if (ex instanceof nosuchelementexception_1.NoSuchElementException) {
ex = new indexoutofboundsexception_1.IndexOutOfBoundsException('Index: ' + index);
}
throw ex;
}
};
AbstractSequentialList.prototype.addAllFrom = function (index, c) {
try {
var modified = false;
var e1 = this.listIteratorFrom(index);
var e2 = c.iterator();
while (e2.hasNext()) {
e1.add(e2.next());
modified = true;
}
return modified;
}
catch (ex) {
if (ex instanceof nosuchelementexception_1.NoSuchElementException) {
ex = new indexoutofboundsexception_1.IndexOutOfBoundsException('Index: ' + index);
}
throw ex;
}
};
return AbstractSequentialList;
}(abstractlist_1.AbstractList));
exports.AbstractSequentialList = AbstractSequentialList;