class CalculatedStatus {

  public static CalculatedStatus statusFromStageEntities(Collection<StageEntity> stages) {
    Collection<HostRoleStatus> stageStatuses = new HashSet<>();
    Collection<HostRoleCommandEntity> tasks = new HashSet<>();

    for (StageEntity stage : stages) {
      // get all the tasks for the stage
      Collection<HostRoleCommandEntity> stageTasks = stage.getHostRoleCommands();

      // calculate the stage status from the task status counts
      HostRoleStatus stageStatus =
          calculateSummaryStatus(calculateTaskEntityStatusCounts(stageTasks), stageTasks.size(), stage.isSkippable());

      stageStatuses.add(stageStatus);

      // keep track of all of the tasks for all stages
      tasks.addAll(stageTasks);
    }

    // calculate the overall status from the stage statuses
    HostRoleStatus status = calculateSummaryStatusOfUpgrade(calculateStatusCounts(stageStatuses), stageStatuses.size());

    // calculate the progress from the task status counts
    double progressPercent = calculateProgressPercent(calculateTaskEntityStatusCounts(tasks), tasks.size());

    return new CalculatedStatus(status, progressPercent);
  }

  private  CalculatedStatus(HostRoleStatus status, double percent);
  private  CalculatedStatus(HostRoleStatus status, HostRoleStatus displayStatus, double percent);

}