There is no direct way to iterate over the 10 largest
values. However you can do the following:

TreeBidiMap map;
Object last = map.lastKey();
Object oneBefore = map.previousKey(last);
Object oneBeforeThat = map.previousKey(oneBefore);

Note that these are methods directly on TreeBidiMap.


The alternative is to use a reverse comparator.
BidiMap map;
Collection coll = map.values();
Set reversed = new HashSet(coll,
Collections.reverseOrder());

Stephen

--- rinke hoekstra <[EMAIL PROTECTED]> wrote:
> Hi list, 
> 
> maybe a stupid question, or maybe I am missing
> something, but I cannot sort out how to 
> do a reverse iteration over the values of a
> TreeBidiMap, and couldn't find much about it 
> on the web.
> I want to retrieve the 10 greatest values from a
> HashMap, and thought it best to use a 
> TreeBidiMap for it.
> 
> I have this:
> 
> TreeBidiMap bidiMap = new TreeBidiMap(myHashMap);
> OrderedBidiMap invMap =
> bidiMap.inverseOrderedBidiMap(); //creates inversed
> map
> OrderedMapIterator oit =
> invMap.orderedMapIterator();
> while (oit.hasPrevious()) {
>       Float value = (Float)oit.previous();
>       .....
> }
> 
> 
> The iterator however seems to be initialized at the
> first element, so hasPrevious() is 
> usually false, and the loop isn't run. 
> 
> How to initialize the iterator at the last element,
> so you can start iterating using 
> hasPrevious()? 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to