There are a couple of ways in Guava to create a sorted immutable multiMap. One way is to first create a ListMultiMap with the keys as a tree and then turn it into an immutable multiMap.
Using a ListMultiMap we can have duplicate values for the same key:
ListMultimap<Integer, String> mutableMap = MultimapBuilder.treeKeys().arrayListValues().build();
return ImmutableListMultimap.copyOf(mutableMap);
Using a TreeMap we won't have duplicate values for the same key:
TreeMultimap<Integer, String> mutableMap = TreeMultimap.create(Ordering.natural(), Ordering.arbitrary());
return ImmutableListMultimap.copyOf(mutableMap);
The problem is that in both cases the immutable interface is generic and doesn't give a way to access the keys in a sorted manner so that we could have e.g. tailMap and headMap which are found in Java's NavigationalMap.
Is there a way to have an immutable sorted multi map in Guava that gives access to tailMap and headMap? Or do I need to just manually build an ImmutableSortedMap<Integer, ImmutableList<String>> to get this functionality?