Ejemplo n.º 1
0
 /// <summary>
 /// Adds a <see cref="ValueNode"/> to the expression tree.
 /// </summary>
 /// <param name="node">The <see cref="ValueNode"/> to add to the expression tree.</param>
 public void AddNode(ValueNode node)
 {
     if (_activeNode == null)
     {
         // If first node
         Root = node;
     }
     else
     {
         _activeNode.AddChild(node);
     }
 }
Ejemplo n.º 2
0
        /// <inheritdoc/>
        public override void InsertChild(BranchNode node)
        {
            ExpNode lastChild = Children[ChildCount - 1];

            Children.RemoveAt(ChildCount - 1);
            node.AddChild(lastChild);
            AddChild(node);
        }
Ejemplo n.º 3
0
        public void TestNodeChildren()
        {
            var       branch     = new BranchNode("Branch");
            const int NUM_LEAVES = 4;

            for (int i = 0; i < NUM_LEAVES; i++)
            {
                branch.AddChild(new LeafNode("Leaf " + i));
            }

            Assert.AreEqual(NUM_LEAVES, branch.GetChildren().Count);
            Assert.AreEqual("Leaf 1", branch.GetChildren()[1].GetContent());
        }
Ejemplo n.º 4
0
        public void BindTo(BranchNode parentNode)
        {
            if (trans != null && ((BranchNode)trans.Parent) != null)
            {
                ((BranchNode)trans.Parent).RemoveChild(trans);

                Console.WriteLine("Contained?" + ((BranchNode)trans.Parent).Children.Contains(trans));
            }

            if (parentNode != null)
            {
                parentNode.AddChild(trans);
            }
        }
Ejemplo n.º 5
0
        public void Add(string key, T value)
        {
            if (string.IsNullOrEmpty(key))
            {
                return;
            }
            BranchNode n = root;
            int        i = 0;

            for (; i < key.Length; i++)
            {
                n = n.AddChild(key[i]);
            }
            n.AddLeaf(value);
        }
Ejemplo n.º 6
0
        /// <inheritdoc/>
        public override void InsertChild(BranchNode node)
        {
            ExpNode newGrandChild;

            if (RightChild != null)
            {
                newGrandChild = RightChild;
                RightChild    = null;
            }
            else
            {
                // newGrandChild will be null if LeftChild is null.
                newGrandChild = LeftChild;
                LeftChild     = null;
            }

            if (newGrandChild != null)
            {
                node.AddChild(newGrandChild);
            }

            AddChild(node);
        }