in mavibot/src/main/java/org/apache/directory/mavibot/btree/KeyCursor.java [237:294]
public K next() throws EndOfFileExceededException, IOException
{
// First check that we have elements in the BTree
if ( ( stack == null ) || ( stack.length == 0 ) )
{
throw new NoSuchElementException( "No Key is present" );
}
ParentPos<K, K> parentPos = stack[depth];
if ( ( parentPos.page == null ) || ( parentPos.pos == AFTER_LAST ) )
{
// This is the end : no more keys
throw new NoSuchElementException( "No more keys present" );
}
if ( parentPos.pos == parentPos.page.getNbElems() )
{
// End of the leaf. We have to go back into the stack up to the
// parent, and down to the leaf
parentPos = findNextParentPos();
// we also need to check for the type of page cause
// findNextParentPos will never return a null ParentPos
if ( ( parentPos == null ) || ( parentPos.page == null ) )
{
// This is the end : no more keys
throw new NoSuchElementException( "No more keys present" );
}
}
// Deal with the BeforeFirst case
if ( parentPos.pos == BEFORE_FIRST )
{
parentPos.pos++;
}
else
{
if ( parentPos.pos == parentPos.page.getNbElems() - 1 )
{
parentPos = findNextParentPos();
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 );
}