public static Map<Long, HostRoleCommand> convertToTaskIdCommandMap(Collection<HostRoleCommand> commands) {
    if (commands == null || commands.isEmpty()) {
      return Collections.emptyMap();
    }

    Map<Long, HostRoleCommand> result = new HashMap<>();
    for (HostRoleCommand command : commands) {
      result.put(command.getTaskId(), command);
    }
    return result;
  }
Converts a collection of commands to {@code}Map{@code} from command.taskId to command.
ambari-server/src/main/java/org/apache/ambari/server/utils/CommandUtils.java