ITreeTableEntry ITreeTable.GetPreviousEntry(ITreeTableEntry current)
 {
     return(GetPreviousEntry((GenericTreeTableWithSummaryEntry <V>)current));
 }
Пример #2
0
 ITreeTableEntry ITreeTable.GetNextEntry(ITreeTableEntry current)
 {
     return(GetNextEntry((GenericTreeTableEntry <V>)current));
 }
 ITreeTableEntry ITreeTable.GetPreviousEntry(ITreeTableEntry current)
 {
     return(GetPreviousEntry((GenericTreeTableWithCounterEntry <V, C>)current));
 }
        /// <summary>
        /// Returns the previous entry in the collection for which the specific counter is not empty.
        /// A cookie defines the type of counter.
        /// </summary>
        /// <param name="current">The current.</param>
        /// <param name="cookie">The cookie.</param>
        /// <returns></returns>
        public ITreeTableEntry GetPreviousNotEmptyCounterEntry(ITreeTableEntry current, int cookie)
        {
            ITreeTableBranch parent = current.Parent;
            ITreeTableNode   next;

            if (parent == null)
            {
                next = null;
                return(null);
            }
            else
            {
                next = current;
                // walk up until we find a branch that has visible entries
                do
                {
                    if (Object.ReferenceEquals(next, parent.Right))
                    {
                        next = parent.Left;
                    }
                    else
                    {
                        ITreeTableBranch parentParent = parent.Parent;
                        Debug.Assert(parentParent != parent);
                        if (parentParent == null)
                        {
                            return(null);
                        }
                        else
                        {
                            while (Object.ReferenceEquals(parentParent.Left, parent)
                                   // TODO: this second statement is a workaround
                                   // for something that most likely went wrong when
                                   // adding the node or when doing a rotation ...
                                   || Object.ReferenceEquals(parentParent.Left, next)
                                   )
                            {
                                parent       = parentParent;
                                parentParent = parentParent.Parent;
                                if (parentParent == null)
                                {
                                    return(null);
                                }
                            }

                            //Debug.Assert(next != parentParent.Right);
                            if (next == parentParent.Left)
                            {
                                throw new Exception();
                                //return null;
                            }
                            else
                            {
                                next = parentParent.Left;
                            }
                        }
                    }
                }while (next != null && ((ITreeTableCounterNode)next).GetCounterTotal().IsEmpty(cookie));

                // walk down to most left leaf that has visible entries
                while (!next.IsEntry())
                {
                    var branch = (ITreeTableBranch)next;
                    next = !((ITreeTableCounterNode)branch.Right).GetCounterTotal().IsEmpty(cookie) ? branch.Right : branch.Left;
                }
            }
            return(next as ITreeTableEntry);
        }