commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hayden James" <>
Subject OrderedMapIterator and LRUMap
Date Fri, 13 Jul 2007 19:42:04 GMT
>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();

   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.


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message