1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 86× 86× 86× 1× 3205× 1× 1× 1× 116× 116× 270× 270× 116× 1× 1× 86× 86× 86× 86× 289× 289× 289× 289× 86× 86× 86× 289× 289× 289× 289× 86× 86× 86× 1× 1× 1× 1× 66× 66× 66× 66× 66× 66× 1× 1× 1× 1× 3081× 3081× 3081× 3081× 9× 3072× 3072× 3081× 3053× 28× 28× 3081× 3081× 3081× 3081× 3081× 1× 3487× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 3488× 3488× 3488× 3487× 3488× 3334× 3334× 3334× 3334× 3334× 1× 3334× 3333× 154× 3488× 1× 1× 36× 36× 36× 36× 36× 298× 265× 265× 265× 33× 1× 1× 1× 1× 3489× 3489× 3489× 1× 1× | /*! * @author electricessence / https://github.com/electricessence/ * Licensing: MIT https://github.com/electricessence/TypeScript.NET/blob/master/LICENSE.md */ (function (factory) { Eif (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); Iif (v !== undefined) module.exports = v; } else if (typeof define === 'function' && define.amd) { define(["require", "exports", "../Text/Utility", "../Exceptions/InvalidOperationException", "../Exceptions/ArgumentException", "../Exceptions/ArgumentNullException", "./Enumeration/EnumeratorBase"], factory); } })(function (require, exports) { "use strict"; var TextUtility = require("../Text/Utility"); var InvalidOperationException_1 = require("../Exceptions/InvalidOperationException"); var ArgumentException_1 = require("../Exceptions/ArgumentException"); var ArgumentNullException_1 = require("../Exceptions/ArgumentNullException"); var EnumeratorBase_1 = require("./Enumeration/EnumeratorBase"); var LinkedNodeList = (function () { function LinkedNodeList() { this._first = null; this._last = null; this.unsafeCount = 0; } Object.defineProperty(LinkedNodeList.prototype, "first", { get: function () { return this._first; }, enumerable: true, configurable: true }); Object.defineProperty(LinkedNodeList.prototype, "last", { get: function () { return this._last; }, enumerable: true, configurable: true }); Object.defineProperty(LinkedNodeList.prototype, "count", { get: function () { var next = this._first, i = 0; while (next) { i++; next = next.next; } return i; }, enumerable: true, configurable: true }); LinkedNodeList.prototype.forEach = function (action) { var current = null, next = this.first, index = 0; do { current = next; next = current && current.next; } while (current && action(current, index++) !== false); return index; }; LinkedNodeList.prototype.map = function (selector) { if (!selector) throw new ArgumentNullException_1.ArgumentNullException('selector'); var result = []; this.forEach(function (node) { result.push(selector(node)); }); return result; }; LinkedNodeList.prototype.clear = function () { var _ = this, n, cF = 0, cL = 0; n = _._first; _._first = null; while (n) { cF++; var current = n; n = n.next; current.next = null; } n = _._last; _._last = null; while (n) { cL++; var current = n; n = n.previous; current.previous = null; } Iif (cF !== cL) console.warn('LinkedNodeList: Forward versus reverse count does not match when clearing. Forward: ' + cF + ", Reverse: " + cL); _.unsafeCount = 0; return cF; }; LinkedNodeList.prototype.dispose = function () { this.clear(); }; LinkedNodeList.prototype.contains = function (node) { return this.indexOf(node) != -1; }; LinkedNodeList.prototype.getNodeAt = function (index) { if (index < 0) return null; var next = this._first, i = 0; while (next && index < i++) { next = next.next; } return next; }; LinkedNodeList.prototype.find = function (condition) { var node = null; this.forEach(function (n, i) { Eif (condition(n, i)) { node = n; return false; } }); return node; }; LinkedNodeList.prototype.indexOf = function (node) { if (node && (node.previous || node.next)) { var index = 0; var c, n = this._first; do { c = n; if (c === node) return index; index++; } while ((n = c && c.next)); } return -1; }; LinkedNodeList.prototype.removeFirst = function () { return this.removeNode(this._first); }; LinkedNodeList.prototype.removeLast = function () { return this.removeNode(this._last); }; LinkedNodeList.prototype.removeNode = function (node) { Iif (node == null) throw new ArgumentNullException_1.ArgumentNullException('node'); var _ = this; var prev = node.previous, next = node.next, a = false, b = false; if (prev) prev.next = next; else Eif (_._first == node) _._first = next; else a = true; if (next) next.previous = prev; else Eif (_._last == node) _._last = prev; else b = true; Iif (a !== b) { throw new ArgumentException_1.ArgumentException('node', TextUtility.format("Provided node is has no {0} reference but is not the {1} node!", a ? "previous" : "next", a ? "first" : "last")); } var removed = !a && !b; Eif (removed) _.unsafeCount--; return removed; }; LinkedNodeList.prototype.addNode = function (node) { this.addNodeAfter(node); }; LinkedNodeList.prototype.addNodeBefore = function (node, before) { assertValidDetached(node); var _ = this; Iif (!before) { before = _._first; } Eif (before) { var prev = before.previous; node.previous = prev; node.next = before; before.previous = node; Eif (prev) prev.next = node; Iif (before == _._first) _._last = node; } else { _._first = _._last = node; } _.unsafeCount++; }; LinkedNodeList.prototype.addNodeAfter = function (node, after) { assertValidDetached(node); var _ = this; if (!after) { after = _._last; } if (after) { var next = after.next; node.next = next; node.previous = after; after.next = node; if (next) next.previous = node; if (after == _._last) _._last = node; } else { _._first = _._last = node; } _.unsafeCount++; }; LinkedNodeList.prototype.replace = function (node, replacement) { if (node == null) throw new ArgumentNullException_1.ArgumentNullException('node'); assertValidDetached(replacement, 'replacement'); var _ = this; replacement.previous = node.previous; replacement.next = node.next; if (node.previous) node.previous.next = replacement; if (node.next) node.next.previous = replacement; if (node == _._first) _._first = replacement; if (node == _._last) _._last = replacement; }; LinkedNodeList.valueEnumeratorFrom = function (list) { Iif (!list) throw new ArgumentNullException_1.ArgumentNullException('list'); var _ = this, current, next; return new EnumeratorBase_1.EnumeratorBase(function () { current = null; next = list.first; }, function (yielder) { if (next) { current = next; next = current && current.next; return yielder.yieldReturn(current.value); } return yielder.yieldBreak(); }); }; LinkedNodeList.copyValues = function (list, array, index) { if (index === void 0) { index = 0; } if (list && list.first) { if (!array) throw new ArgumentNullException_1.ArgumentNullException('array'); list.forEach(function (node, i) { array[index + i] = node.value; }); } return array; }; return LinkedNodeList; }()); exports.LinkedNodeList = LinkedNodeList; function assertValidDetached(node, propName) { Eif (propName === void 0) { propName = 'node'; } Iif (node == null) throw new ArgumentNullException_1.ArgumentNullException(propName); Iif (node.next || node.previous) throw new InvalidOperationException_1.InvalidOperationException("Cannot add a node to a LinkedNodeList that is already linked."); } Object.defineProperty(exports, "__esModule", { value: true }); exports.default = LinkedNodeList; }); //# sourceMappingURL=LinkedNodeList.js.map |