I have a multimap which will contain bunch of keys and values in it.
private final Multimap<String, Process> processById = TreeMultimap.create();
Now for same key I can have bunch of Process
so that's why I am using multimap here. Now I need to sort Process
object in descending order of endTime
in it. For each key in the map when I iterate the List<Process>
, it should print process object in descending order of endTime
. So I implemented Comparable
interface here.
public final class Process implements Comparable<Process> {
private final String clientId;
private final long endTime;
// .. more fields
//... constructor, getters, toString methods
@Override
public int compareTo(Process o) {
// is this logic right here?
return Long.compare(this.endTime, o.endTime) * (-1);
}
}
My question is - Is this the right way to do or my logic is wrong here?
Process process = getProcess(task);
String id = task.getId();
// populate multimap here
processById.put(id, process);