UNPKG

@regionorebrolan/extensions

Version:
118 lines 4.33 kB
"use strict"; 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 __()); }; })(); var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var ReadCollection_1 = __importDefault(require("./ReadCollection")); var Utility_1 = __importDefault(require("../Utility")); var QueryValueSet = /** @class */ (function (_super) { __extends(QueryValueSet, _super); // Constructors function QueryValueSet(comparer) { var _this = _super.call(this) || this; if (Utility_1.default.isNullOrUndefined(comparer)) throw new Error("The comparer can not be null or undefined."); _this._comparer = comparer; return _this; } Object.defineProperty(QueryValueSet.prototype, "comparer", { // Properties get: function () { return this._comparer; }, enumerable: false, configurable: true }); // Methods QueryValueSet.prototype.add = function (items) { var _this = this; var added = 0; if (!(items instanceof Array)) items = [items]; items.forEach(function (item) { if (!_this.contains(item)) { _this.items.push(item); added++; } }); this.items.sort(function (first, second) { return _this.comparer.compare(first, second); }); return added; }; QueryValueSet.prototype.clear = function () { this.items.length = 0; }; QueryValueSet.prototype.contains = function (item) { var e_1, _a; try { for (var _b = __values(this.items), _c = _b.next(); !_c.done; _c = _b.next()) { var value = _c.value; if (this.comparer.equals(item, value)) return true; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } return false; }; QueryValueSet.prototype.remove = function (items) { var _this = this; var removed = 0; if (!(items instanceof Array)) items = [items]; items.forEach(function (item) { for (var i = _this.count - 1; i >= 0; i--) { if (_this.comparer.equals(item, _this.items[i])) { _this.removeAt(i); removed++; continue; } } }); return removed; }; QueryValueSet.prototype.removeAt = function (index) { this.items.splice(index, 1); }; QueryValueSet.prototype.set = function (items) { this.clear(); return this.add(items); }; QueryValueSet.prototype.toString = function () { return this.items.join(QueryValueSet.valueSeparator); }; QueryValueSet.valueSeparator = ","; return QueryValueSet; }(ReadCollection_1.default)); exports.default = QueryValueSet; //# sourceMappingURL=QueryValueSet.js.map