Example #1
0
        public override Node Clone()
        {
            var clone = new CapNode(this.FileOrigin);

            clone.Depth = this.Depth;
            return(clone);
        }
Example #2
0
        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);
        }