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.
97 lines (96 loc) • 3.79 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var nosuchelementexception_1 = require("../nosuchelementexception");
var concurrentmodificationexception_1 = require("../concurrentmodificationexception");
var illegalstateexception_1 = require("../../lang/illegalstateexception");
var RedBlackTree_1 = require("../RedBlackTree");
var SubMapIterator = /** @class */ (function () {
function SubMapIterator(map, first, fence) {
this.map = map;
this.m_LastRetruned = null;
this.m_NextNode = null;
this.m_FenceKeyNode = null;
this.m_Unbounded = false;
this.m_rbTree = null;
this.expectedModCount = this.map.modCount;
this.m_LastRetruned = null;
this.m_NextNode = first;
this.m_Unbounded = true;
this.m_FenceKeyNode = null;
if (fence !== null) {
this.m_FenceKeyNode = fence;
this.m_Unbounded = false;
}
this.m_rbTree = map.m_RedBlackTree;
}
SubMapIterator.prototype.hasNext = function () {
if (this.m_NextNode === null) {
return false;
}
else {
if (this.m_FenceKeyNode === this.m_NextNode) {
return false;
}
else {
return true;
}
}
};
SubMapIterator.prototype.next = function () {
return null;
};
SubMapIterator.prototype.iterator = function () {
return null;
};
SubMapIterator.prototype.nextEntry = function () {
var e = this.m_NextNode;
if (e === null || e === this.m_FenceKeyNode) {
throw new nosuchelementexception_1.NoSuchElementException();
}
if (this.expectedModCount !== this.map.modCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
this.m_NextNode = this.m_rbTree.successor(e);
this.m_LastRetruned = e;
return RedBlackTree_1.RedBlackTree.entryOrNull(e);
};
SubMapIterator.prototype.prevEntry = function () {
var e = this.m_NextNode;
if (e === null || e === this.m_FenceKeyNode) {
throw new nosuchelementexception_1.NoSuchElementException();
}
if (this.expectedModCount !== this.map.modCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
this.m_NextNode = this.m_rbTree.predecessor(e);
this.m_LastRetruned = e;
return RedBlackTree_1.RedBlackTree.entryOrNull(e);
};
SubMapIterator.prototype.removeAscending = function () {
if (this.m_LastRetruned === null) {
throw new illegalstateexception_1.IllegalStateException();
}
if (this.expectedModCount !== this.map.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.map.modCount;
};
SubMapIterator.prototype.removeDescending = function () {
if (this.m_LastRetruned === null) {
throw new illegalstateexception_1.IllegalStateException();
}
if (this.expectedModCount !== this.map.modCount) {
throw new concurrentmodificationexception_1.ConcurrentModificationException();
}
this.m_rbTree.deleteEntry(this.m_LastRetruned);
this.m_LastRetruned = null;
this.expectedModCount = this.map.modCount;
};
return SubMapIterator;
}());
exports.SubMapIterator = SubMapIterator;