Exemplo n.º 1
0
        public m_topic checkTopicHierarchy(m_topic myTopic, m_topic myTestTopic, ref int myDepth)
        {
            //Increase counter
            myDepth++;

            //If the the test topic is a child of the root topic itself, add and return.
            if (myTestTopic.parent.Contains(myTopic.paths_identifier))
            {
                return myTopic;
            }

            //If the topic has child topics
            else if (myTopic.paths_children.Count > 0)
            {
                // For each of the child topics
                for (int i = 0; i < myTopic.paths_children.Count; i++)
                {
                    // If the topic is a match, return the topic
                    if (myTestTopic.parent.Contains(myTopic.paths_children[i].paths_identifier))
                    {
                        return myTopic.paths_children[i];
                    }
                    else
                    {
                        if (myDepth < 100000)
                        {
                            return checkTopicHierarchy(myTopic.paths_children[i], myTestTopic, ref myDepth);
                        }
                        else
                        {
                            return null;
                        }
                    }
                }
                return null;
            }
            else
            {
                return null;
            }

        }
Exemplo n.º 2
0
        public bool AddLeaf(m_topic myChildTopic)
        {
            m_topic lastLeaf = null;

            if (this.paths_children.Count > 0)
            {
                lastLeaf = this.paths_children[0];

                while (lastLeaf.paths_children.Count > 0)
                {
                    lastLeaf = lastLeaf.paths_children[0];
                }

                lastLeaf.paths_children.Add(myChildTopic);
            }
            else
            {
                this.paths_children.Add(myChildTopic);
            }

            return true;
        }
Exemplo n.º 3
0
        public bool AddChildIfParentInTree(m_topic ChildToAdd)
        {
            int count = 0;
            m_topic hitLeaf = this.checkTopicHierarchy(this, ChildToAdd, ref count);

            if (hitLeaf != null)
            {
                if (!hitLeaf.paths_children.Contains(ChildToAdd))
                {
                    hitLeaf.paths_children.Add(ChildToAdd);
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }

        }