public static long getTotalWaittime(List<AppResult> mrJobsList) {
    long totalWaittime = 0;

    if (mrJobsList.size() == 1) {
      return mrJobsList.get(0).totalDelay;
    }

    List<AppResult> finishedTimesSorted = new ArrayList<AppResult>(mrJobsList);

    // sort the jobs in reverse order of finished times.
    Collections.sort(finishedTimesSorted, new Comparator<AppResult>() {
      @Override
      public int compare(AppResult a, AppResult b) {
        return (int) (b.finishTime - a.finishTime);
      }
    });

    // add delay of the lastfinished job
    totalWaittime += finishedTimesSorted.get(0).totalDelay;

    for (int i = 1; i < finishedTimesSorted.size(); i++) {
      if (finishedTimesSorted.get(i).finishTime < finishedTimesSorted.get(i-1).startTime) {
        // add delay between the finishtime of current job and start time of just previous finished job
        totalWaittime += finishedTimesSorted.get(i-1).startTime - finishedTimesSorted.get(i).finishTime;
        // add delay in the current job
        totalWaittime += finishedTimesSorted.get(i).totalDelay;
      }
    }
    return totalWaittime;
  }
Returns the total waittime of the job list. The total waittime is calculated by first finding
the longest trail of non overlapping jobs which includes the last finished job. Then we add the delay for
all the jobs in the trail and the difference in start and finish time between subsequent jobs of the
trail.
@param mrJobsList The job list
@return The total wait time of the joblist
app/com/linkedin/drelephant/util/Utils.java