lik/ts/lik.tree.ts

142 lines
3.5 KiB
TypeScript
Raw Permalink Normal View History

2018-07-15 14:04:27 +00:00
import * as plugins from './lik.plugins';
2017-11-20 08:26:13 +00:00
export class Tree<T> {
symbolTree: any;
constructor() {
this.symbolTree = new plugins.symbolTree();
2017-11-20 08:26:13 +00:00
}
2018-08-31 15:24:35 +00:00
// =======================================
// Functions that map to the functionality of symbol-tree
// =======================================
2017-11-20 08:26:13 +00:00
/**
*
* @param objectArg
2017-11-20 08:26:13 +00:00
*/
initialize(objectArg: T): T {
return this.symbolTree.initialize(objectArg);
2017-11-20 08:26:13 +00:00
}
hasChildren(objectArg: T): boolean {
return this.symbolTree.hasChildren(objectArg);
2017-11-20 08:26:13 +00:00
}
firstChild(objectArg: T): T {
return this.symbolTree.firstChild(objectArg);
2017-11-20 08:26:13 +00:00
}
lastChild(objectArg: T): T {
return this.symbolTree.lastChild(objectArg);
2017-11-20 08:26:13 +00:00
}
previousSibling(objectArg: T): T {
return this.symbolTree.previousSibling(objectArg);
2017-11-20 08:26:13 +00:00
}
nextSibling(objectArg: T): T {
return this.symbolTree.nextSibling(objectArg);
2017-11-20 08:26:13 +00:00
}
parent(objectArg: T): T {
return this.symbolTree.parent(objectArg);
2017-11-20 08:26:13 +00:00
}
lastInclusiveDescendant(objectArg: T): T {
return this.symbolTree.lastInclusiveDescendant(objectArg);
2017-11-20 08:26:13 +00:00
}
preceding(objectArg: T, optionsArg?: any): T {
return this.symbolTree.preceding(objectArg, optionsArg);
2017-11-20 08:26:13 +00:00
}
following(object: T, optionsArg: any) {
return this.symbolTree.following(object, optionsArg);
2017-11-20 08:26:13 +00:00
}
childrenToArray(parentArg: T, optionsArg: any): T[] {
2018-07-15 14:04:27 +00:00
return this.symbolTree.childrenToArray(parentArg, optionsArg);
2017-11-20 08:26:13 +00:00
}
ancestorsToArray(objectArg: T, optionsArg: any): T[] {
return this.symbolTree.ancestorsToArray(objectArg, optionsArg);
2017-11-20 08:26:13 +00:00
}
treeToArray(rootArg, optionsArg: any): T[] {
return this.symbolTree.treeToArray(rootArg, optionsArg);
2017-11-20 08:26:13 +00:00
}
childrenIterator(parentArg: T, optionsArg): T {
return this.symbolTree.childrenIterator(parentArg, optionsArg);
2017-11-20 08:26:13 +00:00
}
previousSiblingsIterator(objectArg): T {
return this.symbolTree.previousSiblingsIterator(objectArg);
2017-11-20 08:26:13 +00:00
}
nextSiblingsIterator(objectArg: T) {
return this.symbolTree.nextSiblingsIterator();
2017-11-20 08:26:13 +00:00
}
ancestorsIterator(objectArg) {
this.symbolTree.ancestorsIterator();
2017-11-20 08:26:13 +00:00
}
2018-08-31 15:24:35 +00:00
treeIterator(rootArg: T, optionsArg): Iterable<T> {
return this.symbolTree.treeIterator(rootArg);
2017-11-20 08:26:13 +00:00
}
index(childArg: T): number {
return this.symbolTree.index(childArg);
2017-11-20 08:26:13 +00:00
}
childrenCount(parentArg: T): number {
return this.symbolTree.childrenCount(parentArg);
2017-11-20 08:26:13 +00:00
}
compareTreePosition(leftArg: T, rightArg: T): number {
return this.compareTreePosition(leftArg, rightArg);
2017-11-20 08:26:13 +00:00
}
remove(removeObjectArg: T): T {
return this.symbolTree.remove(removeObjectArg);
2017-11-20 08:26:13 +00:00
}
insertBefore(referenceObjectArg: T, newObjectArg: T): T {
return this.symbolTree.insertBefore(referenceObjectArg, newObjectArg);
2017-11-20 08:26:13 +00:00
}
insertAfter(referenceObject: T, newObjectArg: T) {
return this.symbolTree.insertAfter(referenceObject, newObjectArg);
2017-11-20 08:26:13 +00:00
}
prependChild(referenceObjectArg: T, newObjectArg: T): T {
return this.symbolTree.prependChild(referenceObjectArg, newObjectArg);
2017-11-20 08:26:13 +00:00
}
appendChild(referenceObjectArg, newObjectArg) {
return this.symbolTree.appendChild(referenceObjectArg, newObjectArg);
2017-11-20 08:26:13 +00:00
}
2018-08-31 15:24:35 +00:00
// ===========================================
// Functionionality that extends symbol-tree
// ===========================================
/**
* returns a branch of the tree as JSON
* can be user
*/
toJsonWithHierachy(rootElement) {
const treeIterable = this.treeIterator(rootElement, {});
for (const treeItem of treeIterable) {
console.log(treeItem);
}
}
/**
* builds a tree from a JSON with hierachy
* @param rootElement
*/
fromJsonWithHierachy(rootElement) {}
}