}
// Less than searches occur below and are not as efficient or easy.
// We need to scan up from the begining if findGreaterOrEqual failed
// or scan down if findGreaterOrEqual succeed.
TupleBrowser browser = null;
if ( null == tuple )
{
// findGreaterOrEqual failed so we create a tuple and scan from
// the lowest values up via getNext comparing each key to key
tuple = new jdbm.helper.Tuple();
browser = bt.browse();
// We should at most have to read one key. If 1st key is not
// less than or equal to key then all keys are > key
// since the keys are assorted in ascending order based on the
// comparator.
while ( browser.getNext( tuple ) )
{
if ( comparator.compareKey( tuple.getKey(), key )
<= 0 )
{
return true;
}
return false;
}
}
else
{
// findGreaterOrEqual succeeded so use the existing tuple and
// scan the down from the highest key less than key via
// getPrevious while comparing each key to key.
browser = bt.browse( tuple.getKey() );
// The above call positions the browser just before the given
// key so we need to step forward once then back. Remember this
// key represents a key greater than or equal to key.
if ( comparator.compareKey( tuple.getKey(), key ) <= 0 )
{
return true;
}
browser.getNext( tuple );
// We should at most have to read one key, but we don't short
// the search as in the search above first because the chance of
// unneccessarily looping is nil since values get smaller.
while ( browser.getPrevious( tuple ) )
{
if ( comparator.compareKey( tuple.getKey(), key )
<= 0 )
{
return true;