return new EmptyEnumeration();
}
if ( isGreaterThan )
{
return new TupleEnumeration( key,
set.tailSet( val ).iterator() );
}
else
{
// Get all values from the smallest upto val and put them into
// a list. They will be in ascending order so we need to reverse
// the list after adding val which is not included in headSet.
SortedSet headset = set.headSet( val );
ArrayList list = new ArrayList( set.size() + 1 );
list.addAll( headset );
// Add largest value (val) if it is in the set. TreeSet.headSet
// does not get val if val is in the set. So we add it now to
// the end of the list. List is now ascending from smallest to
// val
if ( set.contains( val ) )
{
list.add( val );
}
// Reverse the list now we have descending values from val to the
// smallest value that key has. Return tuple cursor over list.
Collections.reverse( list );
return new TupleEnumeration( key, list.iterator() );
}
}