I am new to Guava API and trying to sort keys MultiMapin reverse order or descending value. I run Mapas follows:
ListMultimap<Date, Map<String, String>> listMultimap = MultimapBuilder.treeKeys().arrayListValues().build();
This sorts the keys in ascending order. For instance:.
List multi map iteration: key -->Fri Jan 01 00:00:00 PST 2016 values -->[{test2=testval2}, {test3=testval3}]
List multi map iteration: key -->Sun Jan 01 00:00:00 PST 2017 values -->[{test1=testval1}]
List multi map iteration: key -->Mon Jan 01 00:00:00 PST 2018 values -->[{test0=testval0}]
List multi map iteration: key -->Tue Jan 01 00:00:00 PST 2019 values -->[{test4=testval4}]
I tried creating a custom Date Comparatorusing TreeMultiMap, but could not find a way to do this. This is not syntactically correct, but simply trying to demonstrate the idea.
static final Comparator<Date> DESC_ORDER = new Comparator<Date>() {
public int compare(Date e1, Date e2) {
return e2.compareTo(e1);
}
};
SortedSetMultimap<Date, Map<String, String>> treeMultimap = TreeMultimap.create(DESC_ORDER);
Any pointers would be appreciated.
source
share