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.
81 lines (80 loc) • 3.55 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var RedBlackTree_1 = require("../RedBlackTree");
var nosuchelementexception_1 = require("../nosuchelementexception");
var concurrentmodificationexception_1 = require("../concurrentmodificationexception");
var illegalstateexception_1 = require("../../lang/illegalstateexception");
var SubSetIterator = /** @class */ (function () {
function SubSetIterator(treeSet, firstEntry, fence) {
this.treeSet = treeSet;
this.m_RBTree = null;
this.m_LastRetruned = null;
this.m_NextNode = null;
this.m_FenceNode = null;
this.expectedModCount = 0;
this.m_RBTree = treeSet.m_RBTree;
this.expectedModCount = this.m_RBTree.modCount;
this.m_LastRetruned = null;
this.m_FenceNode = null;
if (fence !== null) {
this.m_FenceNode = this.m_RBTree.getRedBlackTreeNode(fence);
}
this.m_NextNode = this.m_RBTree.getRedBlackTreeNode(firstEntry);
}
SubSetIterator.prototype.isBounded = function () {
return this.m_FenceNode !== null;
};
SubSetIterator.prototype.hasNext = function () {
return this.m_NextNode !== null && this.m_NextNode !== this.m_FenceNode;
};
SubSetIterator.prototype.nextEntry = function () {
var e = this.m_NextNode;
if (e === null || e === this.m_FenceNode) {
throw new nosuchelementexception_1.NoSuchElementException();
}
if (this.m_RBTree.modCount !== this.expectedModCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
this.m_NextNode = this.m_RBTree.successor(e);
this.m_LastRetruned = e;
return RedBlackTree_1.RedBlackTree.entryOrNull(e);
};
SubSetIterator.prototype.prevEntry = function () {
var e = this.m_NextNode;
if (e === null || e === this.m_FenceNode) {
throw new nosuchelementexception_1.NoSuchElementException();
}
if (this.m_RBTree.modCount !== this.expectedModCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
this.m_NextNode = this.m_RBTree.predecessor(e);
this.m_LastRetruned = e;
return RedBlackTree_1.RedBlackTree.entryOrNull(e);
};
SubSetIterator.prototype.removeAscending = function () {
if (this.m_LastRetruned === null) {
throw new illegalstateexception_1.IllegalStateException();
}
if (this.expectedModCount !== this.m_RBTree.modCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
if (this.m_LastRetruned.left !== null && this.m_LastRetruned.right !== null) {
this.m_NextNode = this.m_LastRetruned;
}
this.m_RBTree.deleteEntry(this.m_LastRetruned);
this.m_LastRetruned = null;
this.expectedModCount = this.m_RBTree.modCount;
};
SubSetIterator.prototype.removeDescending = function () {
if (this.m_LastRetruned === null) {
throw new illegalstateexception_1.IllegalStateException();
}
if (this.m_RBTree.modCount !== this.expectedModCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
this.m_RBTree.deleteEntry(this.m_LastRetruned);
this.expectedModCount = this.m_RBTree.modCount;
};
return SubSetIterator;
}());
exports.SubSetIterator = SubSetIterator;