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.
63 lines (62 loc) • 2.64 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var nullpointerexception_1 = require("../lang/nullpointerexception");
var concurrentmodificationexception_1 = require("./concurrentmodificationexception");
var illegalstateexception_1 = require("../lang/illegalstateexception");
var AbstractRedBlackTreeIterator = /** @class */ (function () {
function AbstractRedBlackTreeIterator(firstNode, rbTree) {
this.rbTree = rbTree;
this.m_NextNode = null;
this.m_LastRetruned = null;
this.m_ExpectedModCount = 0;
this.m_NextNode = firstNode;
this.m_ExpectedModCount = rbTree.modCount;
this.m_LastRetruned = null;
}
AbstractRedBlackTreeIterator.prototype.hasNext = function () {
return this.m_NextNode !== null;
};
AbstractRedBlackTreeIterator.prototype.next = function () {
return null;
};
AbstractRedBlackTreeIterator.prototype.nextNode = function () {
var e = this.m_NextNode;
if (e === null) {
throw new nullpointerexception_1.NullPointerException();
}
if (this.rbTree.modCount !== this.m_ExpectedModCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
this.m_NextNode = this.rbTree.successor(e);
this.m_LastRetruned = e;
return e;
};
AbstractRedBlackTreeIterator.prototype.prevNode = function () {
var e = this.m_NextNode;
if (e === null) {
throw new nullpointerexception_1.NullPointerException();
}
if (this.rbTree.modCount !== this.m_ExpectedModCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
this.m_NextNode = this.rbTree.predecessor(e);
this.m_LastRetruned = e;
return e;
};
AbstractRedBlackTreeIterator.prototype.remove = function () {
if (this.m_LastRetruned === null) {
throw new illegalstateexception_1.IllegalStateException();
}
if (this.rbTree.modCount !== this.m_ExpectedModCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
if (this.m_LastRetruned.left !== null && this.m_LastRetruned.right !== null) {
this.m_NextNode = this.m_LastRetruned;
}
this.rbTree.deleteEntry(this.m_LastRetruned);
this.m_ExpectedModCount = this.rbTree.modCount;
this.m_LastRetruned = null;
};
return AbstractRedBlackTreeIterator;
}());
exports.AbstractRedBlackTreeIterator = AbstractRedBlackTreeIterator;