commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ha ryon <>
Subject Re: [commons-collections]: how to do reverse iteration in TreeBidiMap
Date Wed, 30 Mar 2005 15:21:37 GMT
I think previous() is not about to get the collection in the reverse
order, it's about to be able to backtrack an iteration. Means, you did
10 next() and you realise you have went one step too far, then you do
previous(). As you said, previous() doesn't start at the end.

I think you have to use something along what matthew proposed.
I would check whether the inversed bidimap keeps the original map
order or whether it orders on the values. If it orders on the values
you would simply do :
OrderedBidiMap inv = bidiMap.inverseOrderedBidiMap();
Iterator it = inv.values().iterator();
while (it.hasNext()) {
 // take the 10 firsts.
if it is not ordered on the values, then 
TreeSet sorted = new TreeSet(yourcomparator); // design a comparator
that would make the greatest the smallest :), or use a collection and
use sort/reverse as Matthew proposed
sorted.addAll( bidiMap.values() );
sorted.iterator(); // then take the 10 firsts.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message