Is there an easy way to implement a Multimap that is like a TreeMultimap in the sense that the keys take a natural ordering, but also like an ArrayListMultimap in the sense that the collections are sorted in the order the values were added?
Is there an easy way to implement a Multimap that is like a TreeMultimap in the sense that the keys take a natural ordering, but also like an ArrayListMultimap in the sense that the collections are sorted in the order the values were added?
You can use MultimapBuilder to create combinations of features you need. From javadoc:
A builder for a multimap implementation that allows customization of the backing map and value collection implementations used in a particular multimap.
This can be used to easily configure multimap data structure implementations not provided explicitly in
com.google.common.collect, for example:ListMultimap<String, Integer> treeListMultimap = MultimapBuilder.treeKeys().arrayListValues().build(); SetMultimap<Integer, MyEnum> hashEnumMultimap = MultimapBuilder.hashKeys().enumSetValues(MyEnum.class).build();