コード例 #1
0
        private TreeNode<string> BuildExpressionNode()
        {
            var expressionNode = new TreeNode<string>("<expression>");

            expressionNode.AddChildNode(BuildFirstPrimaryIdNode());
            expressionNode.AddChildNode(BuildAddOpNode());
            expressionNode.AddChildNode(BuildPrimaryExpression());

            return expressionNode;
        }
コード例 #2
0
        private TreeNode <string> BuildExpressionNode()
        {
            var expressionNode = new TreeNode <string>("<expression>");

            expressionNode.AddChildNode(BuildFirstPrimaryIdNode());
            expressionNode.AddChildNode(BuildAddOpNode());
            expressionNode.AddChildNode(BuildPrimaryExpression());

            return(expressionNode);
        }
コード例 #3
0
ファイル: NArrayTreeTest.cs プロジェクト: ngoccie/NArrayTree
        public void TestCount()
        {
            // Arrange
            TreeNode <string> root   = new TreeNode <string>("Fruit");
            Tree <string>     tree   = new Tree <string>(root);
            TreeNode <string> child1 = root.AddChildNode("jackfruit");
            TreeNode <string> child2 = root.AddChildNode("dragonfruit");
            TreeNode <string> child3 = root.AddChildNode("papaya");
            // Act
            int numNodes = tree.Count();

            // Assert
            Assert.That(numNodes == 4);
        }
コード例 #4
0
        public void AddChildNodesToTree()
        {
            TreeNode treeNode = new TreeNode("Root");
            VFSNode  node1    = new VFSNode();

            node1.VFSPath = "3DDATA\\ELDEON\\TEST1.DDS";
            VFSNode node2 = new VFSNode();

            node2.VFSPath = "3DDATA\\ELDEON\\TEST2.DDS";
            treeNode.AddChildNode(node1);
            treeNode.AddChildNode(node2);

            Assert.IsTrue(treeNode.FirstNode.Nodes.Count == 2);
        }
コード例 #5
0
ファイル: NArrayTreeTest.cs プロジェクト: ngoccie/NArrayTree
        public void TestLeafCount()
        {
            // Arrange
            TreeNode <string> root    = new TreeNode <string>("Drinks");
            Tree <string>     tree    = new Tree <string>(root);
            TreeNode <string> child1  = root.AddChildNode("greenTea");
            TreeNode <string> child2  = root.AddChildNode("bubbletea");
            TreeNode <string> child3  = root.AddChildNode("smoothie");
            TreeNode <string> child11 = child1.AddChildNode("iced");
            // Act
            int numLeafs = tree.LeafCount();

            // Assert
            Assert.That(numLeafs == 3);
        }
コード例 #6
0
        public static TreeModel GenerateTreeModel()
        {
            var rootNode = new TreeNode(1, "Test Building", GetImageUrl());
            int index    = 2;

            for (int loopFloor = 1; loopFloor <= 10; loopFloor++)
            {
                var floorNode = new TreeNode(index, "Floor " + loopFloor, GetImageUrl());
                rootNode.AddChildNode(floorNode);
                index++;
                for (int loopArea = 1; loopArea <= 10; loopArea++)
                {
                    var areaNode = new TreeNode(index, "Area " + loopArea, GetImageUrl());
                    floorNode.AddChildNode(areaNode);
                    index++;
                    for (int loopItem = 1; loopItem <= 10; loopItem++)
                    {
                        var itemNode = new TreeNode(index, "Item " + loopArea + " - Extra Information " + loopItem, GetImageUrl());
                        areaNode.AddChildNode(itemNode);
                        index++;
                    }
                }
            }

            return(new TreeModel(rootNode));
        }
コード例 #7
0
ファイル: LoadVFSFiles.cs プロジェクト: Avo18/RoseOnlineVFS
        private Task <TreeNode[]> LoadVFSFilesInTreeview(CancellationToken token = default)
        {
            List <TreeNode> treeNodes = new List <TreeNode>();

            return(Task.Run(() =>
            {
                //List<MergeVFSTree> listMerges = new List<MergeVFSTree>();
                foreach (var model in _vfsReadFacade.VFSModel)
                {
                    treeViewLoadedStatusLabel.Text = string.Intern("Loading: ") + model.VFSRoot;
                    //MergeVFSTree merge = new MergeVFSTree(new RoseOnline.Streaming.VFS.Collection.VFSTree<string>(model.VFSRoot));
                    var rootNode = new TreeNode(model.VFSRoot);
                    foreach (var path in model.VFSNodes)
                    {
                        rootNode.AddChildNode(path);
                        //merge.Merge(path);
                        Invoke(new EventHandle(() => treeViewLoadingProgressBar.Value += 1));
                    }

                    treeNodes.Add(rootNode);
                    //listMerges.Add(merge);
                }
                CheckProgressbarSuccessfullyLoaded();
                return treeNodes.ToArray();
            }, token));
        }
コード例 #8
0
        private TreeNode<string> BuildPrimaryExpression()
        {
            var firstPrimary = new TreeNode<string>("<expression>");
            var terminalPrimary = new TreeNode<string>("<primary>");
            terminalPrimary.AddTerminalChild("IdX");
            firstPrimary.AddChildNode(terminalPrimary);

            return firstPrimary;
        }
コード例 #9
0
ファイル: NArrayTreeTest.cs プロジェクト: ngoccie/NArrayTree
        public void TestSum2Leafs()
        {
            //Arrange
            TreeNode <int> root   = new TreeNode <int>(7);
            TreeNode <int> nodeB  = root.AddChildNode(8);
            TreeNode <int> nodeC  = root.AddChildNode(9);
            TreeNode <int> nodeB1 = nodeB.AddChildNode(88);
            TreeNode <int> nodeB2 = nodeB.AddChildNode(888);
            //Act
            List <int> sumList = root.SumToLeafs();

            // Assert
            Assert.Multiple(() =>
            {
                Assert.That(sumList.Count() == 3);
                Assert.Contains(16, sumList);
            });
        }
コード例 #10
0
 private TreeNode<string> BuildStatementNode()
 {
     var statementNode = new TreeNode<string>("<statement>");
     statementNode.AddTerminalChild("Id");
     statementNode.AddTerminalChild(":=");
     statementNode.AddChildNode(BuildExpressionNode());
     statementNode.AddTerminalChild(";");
     return statementNode;
 }
コード例 #11
0
        private TreeNode <string> BuildPrimaryExpression()
        {
            var firstPrimary    = new TreeNode <string>("<expression>");
            var terminalPrimary = new TreeNode <string>("<primary>");

            terminalPrimary.AddTerminalChild("IdX");
            firstPrimary.AddChildNode(terminalPrimary);

            return(firstPrimary);
        }
コード例 #12
0
        private TreeNode <string> BuildStatementNode()
        {
            var statementNode = new TreeNode <string>("<statement>");

            statementNode.AddTerminalChild("Id");
            statementNode.AddTerminalChild(":=");
            statementNode.AddChildNode(BuildExpressionNode());
            statementNode.AddTerminalChild(";");
            return(statementNode);
        }
コード例 #13
0
ファイル: TreeUtils.cs プロジェクト: nicetester/ZKWeb-1
        /// <summary>
        /// Transform tree<br/>
        /// If the given node isn't root node, it will lose it's parent<br/>
        /// 转换树<br/>
        /// 如果传入的节点不是根节点, 会失去它的所有上级节点<br/>
        /// </summary>
        /// <typeparam name="T">Original type</typeparam>
        /// <typeparam name="U">Target type</typeparam>
        /// <param name="node">The node</param>
        /// <param name="convertor">Method for convert value from original to target</param>
        /// <returns></returns>
        /// <example>
        /// <code language="cs">
        /// var elements = new List&lt;TestData&gt;() {
        ///     new TestData(1, 0, "A"),
        ///     new TestData(2, 1, "AA"),
        ///     new TestData(3, 1, "AB"),
        ///     new TestData(4, 0, "B"),
        ///     new TestData(5, 4, "BA"),
        ///     new TestData(6, 4, "BB"),
        ///     new TestData(7, 6, "BBB"),
        /// };
        /// var elementsMapping = elements.ToDictionary(e =&gt; e.Id, e =&gt; e);
        /// var tree = TreeUtils.CreateTree(elements,
        ///     e =&gt; e, e =&gt; elementsMapping.GetOrDefault(e.ParentId));
        /// var newTree = TreeUtils.Transform(TestData.GetTestTree(), d =&gt; d?.Name);
        /// </code>
        /// </example>
        public static ITreeNode <U> Transform <T, U>(ITreeNode <T> node, Func <T, U> convertor)
        {
            var unode = new TreeNode <U>(convertor(node.Value));

            foreach (var childNode in node.Childs)
            {
                unode.AddChildNode(Transform(childNode, convertor));
            }
            return(unode);
        }
コード例 #14
0
ファイル: NArrayTreeTest.cs プロジェクト: ngoccie/NArrayTree
        public void TestRemoveNode()
        {
            //Arrange
            TreeNode <string> root  = new TreeNode <string>("Desserts");
            TreeNode <string> nodeB = root.AddChildNode("muffin");
            TreeNode <string> nodeC = root.AddChildNode("cupcake");

            //Act
            root.RemoveNode(nodeB);
            List <string> listNodes = new List <string>();

            foreach (TreeNode <string> j in root)
            {
                listNodes.Add(j.Value);
            }
            //Assert
            Assert.Multiple(() =>
            {
                Assert.That(listNodes.Count() == 2);
                Assert.Contains("Desserts", listNodes);
            });
        }
コード例 #15
0
ファイル: NArrayTreeTest.cs プロジェクト: ngoccie/NArrayTree
        public void TestAddChildNode()
        {
            // Arrange
            TreeNode <int> root = new TreeNode <int>(3);

            root.AddChildNode(5);
            root.AddChildNode(4);
            // Act
            List <TreeNode <int> > childNode   = root.Children;
            List <int>             childValues = new List <int>();

            foreach (TreeNode <int> node in root.Children)
            {
                childValues.Add(node.Value);
            }
            // Assert
            Assert.Multiple(() =>
            {
                Assert.That(childValues.Count() == 2);
                Assert.Contains(5, childValues);
            });
        }
コード例 #16
0
        public void AddSequence(IEnumerable <T> sequence)
        {
            TreeNode <T> current = _root;

            foreach (T item in sequence)
            {
                TreeNode <T> next = current.GetChild(item);
                if (next == null)
                {
                    current = current.AddChildNode(item);
                }
                else
                {
                    current = next;
                }
            }
        }
コード例 #17
0
    private static void ReadNodes(int numberOfPairs, out Dictionary <int, TreeNode> nodes, out List <TreeNode> childNodes)
    {
        nodes      = new Dictionary <int, TreeNode>();
        childNodes = new List <TreeNode>();
        Console.WriteLine("Please enter the pairs:");
        for (int i = 0; i < numberOfPairs; i++)
        {
            Console.WriteLine("{0}: ", i);
            int parentValue;
            int childValue;
            ReadPairData(out parentValue, out childValue);

            TreeNode childNode  = GetNodeObject(childValue, ref nodes);
            TreeNode parentNode = GetNodeObject(parentValue, ref nodes);

            parentNode.AddChildNode(childNode);
            if (!childNodes.Contains(childNode))
            {
                childNodes.Add(childNode);
            }
        }
    }