Пример #1
0
        /** Return the next HeirarchyNode after this one at the same level in the
         * entire heirarchy.  Return null if this is the last one (or if there is
         * no parent).  This proceeds as follows: If there is no parent, return
         * null.  If there is a child after this one in the parent, return it,
         * otherwise ask the parent for the nextInHeirarchy at its level.  If
         * there is none, return null.  If the next parent has children,
         * return return its first child. Otherwise, keep asking the parent
         * for its nextInHeirarchy until one is found with children.  If none,
         * return null.
         */
        public HeirarchyNode nextInHeirarchy()
        {
            if (_parent == null)
            {
                return(null);
            }

            int nextIndex = _index + 1;

            if (nextIndex < _parent.getChildCount())
            {
                return(_parent.getChild(nextIndex));
            }

            for (HeirarchyNode nextParent = _parent.nextInHeirarchy();
                 nextParent != null; nextParent = nextParent.nextInHeirarchy())
            {
                if (nextParent.getChildCount() > 0)
                {
                    return(nextParent.getChild(0));
                }
            }

            return(null);
        }
Пример #2
0
        /** Return the previous HeirarchyNode before this one at the same level in the
         * entire heirarchy.  Return null if this is the first one (or if there is
         * no parent).  This proceeds as follows: If there is no parent, return
         * null.  If there is a child before this one in the parent, return it,
         * otherwise ask the parent for the previousInHeirarchy at its level.  If
         * there is none, return null.  If the previous parent has children,
         * return return its last child. Otherwise, keep asking the parent
         * for its previousInHeirarchy until one is found with children.  If none,
         * return null.
         */
        public HeirarchyNode previousInHeirarchy()
        {
            if (_parent == null)
            {
                return(null);
            }

            int previousIndex = _index - 1;

            if (previousIndex >= 0)
            {
                return(_parent.getChild(previousIndex));
            }

            for (HeirarchyNode previousParent = _parent.previousInHeirarchy();
                 previousParent != null;
                 previousParent = previousParent.previousInHeirarchy())
            {
                if (previousParent.getChildCount() > 0)
                {
                    return(previousParent.getChild(previousParent.getChildCount() - 1));
                }
            }

            return(null);
        }