core-cde
Version:
201 lines • 6.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkedListModified = void 0;
const tslib_1 = require("tslib");
const LinkedList_1 = (0, tslib_1.__importDefault)(require("typescript-dotnet-commonjs/System/Collections/LinkedList"));
class LinkedListModified {
constructor() {
this._list = new LinkedList_1.default();
}
set(index, value) {
const node = this._list.getNodeAt(index);
node.value = value;
return;
}
// public transfer(curIndex: number, insertIndex: number) {
// if (curIndex === null || insertIndex === null) { throw new EmptyParametersError('transfer'); }
// const node = this._list.getNodeAt(curIndex);
// const positionNode = this._list.getNodeAt(insertIndex);
// if (!node || !positionNode) { throw new ElementNotFoundError('transfer'); }
// const tmp = node.value;
// this._list.removeAt(curIndex);
// (curIndex > insertIndex) ?
// this._list.addBefore(positionNode, tmp) :
// this._list.addAfter(positionNode, tmp)
// }
insert(index, value) {
if (index === null || index === undefined) {
return this._list.addLast(value);
}
if (index < 0) {
return this._list.addFirst(value);
}
const node = this._list.getNodeAt(index);
return this._list.addAfter(node, value);
}
removeAt(index) {
this._list.removeAt(index);
return;
}
add(entry) {
this._list.add(entry);
return this;
}
addBefor(before, entry) {
return this._list.addBefore(before, entry);
}
addAfter(after, entry) {
return this._list.addAfter(after, entry);
}
addFirst(entry) {
return this._list.addFirst(entry);
}
removeNode(node) {
return this._list.removeNode(node);
}
remove(entry, max) {
return this._list.remove(entry);
}
clear() {
return this._list.clear();
}
get last() {
return this._list.last;
}
get first() {
return this._list.first.value;
}
importEntries(entries) {
throw new Error('Method not implemented.');
}
toArray() {
return this._list.toArray();
}
get count() {
return this._list.count;
}
get isReadOnly() {
return this._list.isReadOnly;
}
contains(entry) {
throw new Error('Method not implemented.');
}
copyTo(target, index) {
throw new Error('Method not implemented.');
}
getEnumerator() {
throw new Error('Method not implemented.');
}
getNodeById(id) {
if (!id) {
return null;
}
let next = this._list.first;
while (next && next.value['id'] !== id) {
next = next.next || null;
}
return next;
}
getNodeByIndex(index) {
return this._list.getNodeAt(index);
}
get(index) {
return this._list.getValueAt(index);
}
indexOf(item) {
return this._list.toArray().indexOf(item);
}
}
exports.LinkedListModified = LinkedListModified;
// export class LinqList<T> {
// public values: LinqItem<T>[] = [];
// public $event: EventEmitter = new EventEmitter;
// public push(item: LinqItem<T>): number {
// const prevItem = this.values[this.values.length - 1];
// if (prevItem) {
// this.changeLinksPrev(prevItem, item);
// }
// this.$event.emit('changeType', item);
// return this.values.push(item);
// }
// public insert(position: number, item: LinqItem<T>) {
// const res = this.values.splice(position, 0, item);
// // if (res.length === 0) { throw new ElementNotFoundError('insert'); }
// const list = new LinkedList<T>();
// const [prevItem, nextItem] = [this.values[position - 1], this.values[position + 1]];
// if (prevItem) {
// this.changeLinksPrev(prevItem, item);
// }
// if (nextItem) {
// this.changeLinksNext(nextItem, item);
// }
// this.$event.emit('changeType', item);
// }
// public remove(index: number, actually = true) {
// const [prevItem, nextItem] = [this.values[index - 1], this.values[index + 1]];
// if (actually) {
// const res = this.values.splice(index, 1);
// if (res.length === 0) { throw new ElementNotFoundError('remove'); }
// }
// if (prevItem) {
// this.changeLinksPrev(prevItem, nextItem);
// }
// if (nextItem) {
// this.changeLinksNext(nextItem, prevItem);
// }
// }
// public get length(): number {
// return this.values.length;
// }
// public find(predicate: (value: LinqItem<T>, index: number, obj: LinqItem<T>[]) => unknown): LinqItem<T> | undefined {
// return this.values.find(predicate);
// }
// public findIndex(id: string): number {
// return this.values.findIndex(val => val.id === id)
// }
// public map(callbackfn: (value: LinqItem<T>, index: number, array: LinqItem<T>[]) => LinqItem<T>): LinqItem<T>[] {
// return this.values.map(callbackfn);
// }
// public get(index: number): LinqItem<T> {
// return this.values[index];
// }
// /**
// * Получить списко без ссылок
// * @returns списко без ссылок
// */
// public getDataWithoutLinks(): LinqItem<T>[] {
// return this.values.map(val => {
// return new Object({
// ...val,
// next: undefined,
// prev: undefined,
// $eventChangeState: undefined,
// $event: undefined,
// active: undefined,
// idNex: undefined,
// idPrev: undefined,
// })
// });
// }
// private changeLinksPrev(prevItem: LinqItem<T>, item: LinqItem<T>) {
// if (prevItem) {
// prevItem.next = item;
// prevItem.idNex = item?.id || null;
// }
// if (item) {
// item.prev = prevItem;
// item.idPrev = prevItem?.id || null;
// }
// }
// private changeLinksNext(nextItem: LinqItem<T>, item: LinqItem<T>) {
// if (nextItem) {
// nextItem.prev = item;
// nextItem.idPrev = item?.id || null;
// }
// if (item) {
// item.next = nextItem;
// item.idNex = nextItem?.id || null;
// }
// }
// }
//# sourceMappingURL=LinqList.js.map