OrderedMapIterator and LRUMap

2007-07-13 Thread Hayden James

From the javadoc of LRUMap:


The orderedMapIterator() method provides direct access to a bidirectional
iterator. The iterators from the other views can also be cast to
OrderedIterator if required.

I was wondering how to actually do this.  If I have the following code:

Original code:

LRUMap map = new LRUMap();

I would get a key from this map via an OrderedIterator
OrderedIterator iter = map.orderedMapIterator();

while(iter.hasPrevious())
{
  Long id = (Long) iter.previous();
}

New code:

Now if I use synchronizedMap, which forces me to use the Map interface like:
Map map = Collections.synchronizedMap(new LRUMap());

which iterator from which function do I cast in order to get the same
behavior as above?
OrderedMapIterator iter = (OrderedMapIterator) map.entrySet().iterator();
or maybe
OrderedMapIterator iter = (OrderedMapIterator) map.keySet().iterator();

or perhaps something completely different.  The documentation is a little
vague on how to accomplish this.

Thanks.


Re: OrderedMapIterator and LRUMap

2007-07-13 Thread Stephen Colebourne

Hayden James wrote:
Now if I use synchronizedMap, which forces me to use the Map interface 
like:

Map map = Collections.synchronizedMap(new LRUMap());

which iterator from which function do I cast in order to get the same
behavior as above?
OrderedMapIterator iter = (OrderedMapIterator) map.entrySet().iterator();
or maybe
OrderedMapIterator iter = (OrderedMapIterator) map.keySet().iterator();

or perhaps something completely different.  The documentation is a little
vague on how to accomplish this.


Once you wrap the LRUMap in a synchronized map there is no way to obtain 
the ordered iterator.


Stephen

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