public K prev()

in mavibot/src/main/java/org/apache/directory/mavibot/btree/KeyCursor.java [416:458]


    public K prev() throws EndOfFileExceededException, IOException
    {
        // First check that we have elements in the BTree
        if ( ( stack == null ) || ( stack.length == 0 ) )
        {
            throw new NoSuchElementException( "No more keys present" );
        }

        ParentPos<K, K> parentPos = stack[depth];

        if ( ( parentPos.page == null ) || ( parentPos.pos == BEFORE_FIRST ) )
        {
            // This is the end : no more keys
            throw new NoSuchElementException( "No more keys present" );
        }

        // Deal with the AfterLast case
        if ( parentPos.pos == AFTER_LAST )
        {
            parentPos.pos = parentPos.page.getNbElems() - 1;
        }
        else
        {
            if ( parentPos.pos == 0 )
            {
                parentPos = findPrevParentPos();
                
                if ( ( parentPos == null ) || ( parentPos.page == null ) )
                {
                    // This is the end : no more keys
                    throw new NoSuchElementException( "No more keys present" );
                }
            }
            else
            {
                parentPos.pos--;
            }
        }

        AbstractPage<K, K> leaf = ( AbstractPage<K, K> ) ( parentPos.page );

        return leaf.getKey( parentPos.pos );
    }