Monday, October 15, 2001 02:14 PM
I implemented a LRU Cache that has more or less the functionality you want. I think that you need to be a bit more specific about the req's though. For instance, what happens if you put() an entry for which the key already exists, and does an access change the order of the iteration?
If you only want to iterate over the Map.Entry Set, I'd just extend HashMap to
1: have an ArrayList of Map.Entry
2: Override put(key, val) (and any other methods or constructors needed) to test for the existence of the key, and if it isn't in the HashMap, create a new Map.Entry, add that to the ArrayList and also call the superclass put()
3: Override entrySet() to return the ArrayList.
This is off the top of my head, so no guarantees, but I think it's close.