http://java.sun.com/j2se/1.4.2/docs/api/java/util/LinkedHashMap.html
On Mon, Mar 29, 2010 at 6:33 AM, Steve Siebert <[email protected]> wrote: > I'm in need of a doubly-linked HashMap that exposes index mappings as > well as the key-value pair. An API that exposes a mix of LinkedList > and HashMap methods. I started with LinkedHashMap but quickly > realized I needed to do something like: > > DoubleLinkedHashMap<String, String> dlHash = new > DoubleLinkedHashMap<String, String>(); > //......load the hashmap........ > int index = dlHash.getLastKey(); > try { > String nextKey = dlHash.getKey(index+1); > //....blah, blah, blah > } > catch (IndexOutOfBoundsException ex) > { > //...more blah > } > > This is a rough API and exposes some possible convenience methods > (because things like getLastKey() and getKey() should live organically > on the return of keySet()), but I was going for simplicity =). > > Anyway, I hacked out a collection class to satisfy this requirement > for the project (a HashMap backed with a LinkedList encapsulated in > the DoubleLinkedHashMap class), but if anyone knows a similar > implementation within a common collections library, I would happily > make a drop-in replacement (just seems like I'm not the only one that > would need this eventually). I of course checked the Java Collections > Framework and did a bit of searching within the Google Collections > library without luck. > > Thanks! > > Steve > > -- > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > > -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
