public static Map<IdUrlPair, List<AppResult>> groupJobs(List<AppResult> results, GroupBy groupBy) {
    Map<String, List<AppResult>> groupMap = new LinkedHashMap<String, List<AppResult>>();
    Map<String, String> idUrlMap = new HashMap<String, String>();

    for (AppResult result : results) {
      String idField = null;
      String urlField = null;
      switch (groupBy) {
        case JOB_EXECUTION_ID:
          idField = result.jobExecId;
          urlField = result.jobExecUrl;
          break;
        case JOB_DEFINITION_ID:
          idField = result.jobDefId;
          urlField = result.jobDefUrl;
          break;
        case FLOW_EXECUTION_ID:
          idField = result.flowExecId;
          urlField = result.flowExecUrl;
          break;
      }
      if (!idUrlMap.containsKey(idField)) {
        idUrlMap.put(idField, urlField);
      }

      if (groupMap.containsKey(idField)) {
        groupMap.get(idField).add(result);
      } else {
        List<AppResult> list = new ArrayList<AppResult>();
        list.add(result);
        groupMap.put(idField, list);
      }
    }

    // Construct the final result map with the key as a (id, url) pair.
    Map<IdUrlPair, List<AppResult>> resultMap = new LinkedHashMap<IdUrlPair, List<AppResult>>();
    for (Map.Entry<String, List<AppResult>> entry : groupMap.entrySet()) {
      String key = entry.getKey();
      List<AppResult> value = entry.getValue();
      resultMap.put(new IdUrlPair(key, idUrlMap.get(key)), value);
    }

    return resultMap;
  }
Grouping a list of AppResult by GroupBy enum.

@param results The list of jobs of type AppResult to be grouped.
@param groupBy The field by which the results have to be grouped.
@return A map with the grouped field as the key and the list of jobs as the value.
app/controllers/ControllerUtil.java