I want to sort my list of Task object by two criterion. First it is sorted by leftEntryTime and then by timeNeededToBeProcessed.
Can someone help me?
So far I did sorting by leftEntryTime but how I can sort it by timeNeededToBeProcessed in the same Comparator class?
Task(int procesID, int neededTime, int waitingTime, int leftEntryTime) {
this.procesID = procesID;
this.timeNeededToBeProcessed = neededTime;
this.waitingTime = waitingTime;
this.leftEntryTime = leftEntryTime;
}
This is my Comparator:
import java.util.Comparator;
public class TimeEntryComparator implements Comparator<Task> {
@Override
public int compare(Task o1, Task o2) {
int entryTime;
int taskTime = o1.getLeftEntryTime()- o2.getLeftEntryTime();
if (taskTime > 0){
return 1;
}
if (taskTime < 0) {
return -1;
}
return 0;
}
}
then I sort it by:
Collections.sort(list, new TimeEntryComparator());
public int compare(Task o1, Task o2) { return (o1.getLeftEntryTime() - o2.getLeftEntryTime()); }leftEntryTimeandtimeNeededToBeProcessed?