コード例 #1
0
        public MultiTreeNode <TValue, TConnectionWay> AddChild(TValue value, TConnectionWay connectionWay)
        {
            var node = root.FindOrCreateNode(value);

            node.SetParent(this);
            ChildrenList.Add(node);
            ConnectionWays.Add(connectionWay);
            return(node);
        }
コード例 #2
0
        public override void RemoveChild(TValue value)
        {
            int index;
            var nodeToRemove = root.GetNode(value);
            var removed      = false;

            while ((index = ChildrenList.IndexOf(nodeToRemove)) != -1)
            {
                ChildrenList.RemoveAt(index);
                ConnectionWays.RemoveAt(index);
                removed = true;
            }
            if (!removed)
            {
                throw new InvalidOperationException(string.Format("Node '{0}' does not have child '{1}'.", Value, value));
            }
            root.GarbageCollect();
        }
コード例 #3
0
        public void RemoveChild(TConnectionWay connectionWay, Func <TValue, bool> tester = null)
        {
            var connectionWayIndices = ConnectionWays.IndicesOf(connectionWay);
            var removed = false;

            foreach (var index in connectionWayIndices.OrderByDescending(x => x))
            {
                if (tester != null && !tester(ChildrenList[index].Value))
                {
                    root.GarbageCollect();
                    return;
                }

                ChildrenList.RemoveAt(index);
                ConnectionWays.RemoveAt(index);
                removed = true;
            }
            if (!removed)
            {
                throw new InvalidOperationException(string.Format("Node '{0}' does not have child connected by '{1}'.", Value, connectionWay));
            }
            root.GarbageCollect();
        }