public void Finalize() { ResetNodeConstruction(); Stack <Node> nodes = new Stack <Node>(); nodes.Push(this.Root); while (nodes.Count > 0) { Node currentNode = nodes.Pop(); if (currentNode.GetType() == typeof(KeyCollectionNode)) { KeyCollectionNode collectionNode = (KeyCollectionNode)currentNode; foreach (Node child in collectionNode.Children) { if (!collectionNode.IsRoot()) { child.Depth = (byte)(collectionNode.Depth + 1); } nodes.Push(child); } } } this.Root.Children.Add(new CapNode(this.File)); }
public void Print() { Stack <Node> nodeStack = new Stack <Node>(); nodeStack.Push(this); Node currentNode = null; while (nodeStack.Count > 0) { Node previousNode = currentNode; currentNode = nodeStack.Pop(); if (previousNode != null && previousNode.Depth > currentNode.Depth) { int depthDifference = previousNode.Depth - currentNode.Depth; for (int i = 0; i != depthDifference; i++) { for (int j = 0; j < (previousNode.Depth - 1) - i; j++) { Console.Write('\t'); } Console.WriteLine("}"); } } for (int i = 0; i < currentNode.Depth; i++) { Console.Write('\t'); } if (currentNode.GetType() == typeof(KeyCollectionNode)) { KeyCollectionNode keyCollectionNode = (KeyCollectionNode)currentNode; List <Node> reverse = new List <Node>(keyCollectionNode.Children); reverse.Reverse(); foreach (Node child in reverse) { nodeStack.Push(child); } if (!keyCollectionNode.IsRoot()) { Console.WriteLine(currentNode.GetString()); } } else { Console.WriteLine(currentNode.GetString()); } } }
public String PrintString() { StringBuilder stringBuilder = new StringBuilder(); Stack <Node> nodeStack = new Stack <Node>(); CapNode cap = new CapNode(this.FileOrigin); cap.Depth = this.Depth; if (!this.IsRoot()) { nodeStack.Push(cap); } nodeStack.Push(this); int startingDepth = this.Depth; Node currentNode = null; while (nodeStack.Count > 0) { Node previousNode = currentNode; currentNode = nodeStack.Pop(); if (previousNode != null && previousNode.Depth > currentNode.Depth) { int depthDifference = previousNode.Depth - currentNode.Depth; for (int i = 0; i != depthDifference; i++) { for (int j = startingDepth; j < (previousNode.Depth - 1) - i; j++) { stringBuilder.Append('\t'); } stringBuilder.AppendLine("}"); } } if (currentNode.GetType() == typeof(CapNode)) { continue; } for (int i = startingDepth; i < currentNode.Depth; i++) { stringBuilder.Append('\t'); } if (currentNode.GetType() == typeof(KeyCollectionNode)) { KeyCollectionNode keyCollectionNode = (KeyCollectionNode)currentNode; List <Node> reverse = new List <Node>(keyCollectionNode.Children); reverse.Reverse(); foreach (Node child in reverse) { nodeStack.Push(child); } if (!keyCollectionNode.IsRoot()) { stringBuilder.AppendLine(currentNode.GetString()); } } else { stringBuilder.AppendLine(currentNode.GetString()); } } String built = stringBuilder.ToString(); return(built); }