Is there a Java map implementation that returns the most recently contained key
I'm looking for a map implementation that returns the value associated with the requested key, or if it doesn't exist, the closest value, a higher or lower request (and the actual key, possibly as a map. Entry)
For example, if the map contains the following string key / value pairs: Alpha: Aye, beta: bee, Charlie: CEE, Delta: Dee, and you request "next higher" for "Canada", you will retrieve Charlie: CEE
Of course, if you ask Charlie's next higher or lower, you'll get Charlie back: CEE
It should use a comparator so that if it contains numeric keys 1,2,3 and I request next higher for 1.4, it will return key 2
Solution
Using navigablemap:
In particular, use a floorentry or ceilingentry or combination
Treemap is an instance of navigablemap, so you can use it: http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html