The MultiValueMap class (Apache commons collections) makes it easy to work with a Map whose values are Collections. I\'m looking for a a class that makes it easy to work wit
If you've got a map:{string,map:{string,thing}}
(deliberately not using Java syntax to avoid the whole Java1.4/Java5 business) then you should also consider whether you should instead model that as map:{tuple:{string,string},thing}
. If multi-level lookups dominate, then that's a good change to make (provided you implement a good tuple
that does equals()
correctly and hashCode()
intelligently) but if you are doing a lot of inserts and deletes then it's less good.
Intelligence in hashCode probably means just coming up with a reasonable way to mix the bits from the hashCodes of the contents together. If the member values are expected to be from disjoint sets (e.g., names and occupations) then you can just XOR them together – imperfect, but cheap and fast – but if you've less control/certainty then you need to do something else as well (e.g., rotate the bits of one of the values prior to the XOR).