class ReservationUsageCalculator {

    public ReservationUsage buildCapacityGroupUsage(String capacityGroupName) {
        ApplicationSLA capacityGroup = capacityManagementService.getApplicationSLA(capacityGroupName);
        if (capacityGroup == null) {
            return ReservationUsage.none();
        }

        List<Pair<Job, List<Task>>> jobsAndTasks = jobOperations.getJobsAndTasks();

        ResourceAccumulator accumulator = new ResourceAccumulator();
        for (Pair<Job, List<Task>> jobAndTasks : jobsAndTasks) {
            Job job = jobAndTasks.getLeft();
            if (capacityGroupName.equals(job.getJobDescriptor().getCapacityGroup())) {
                processJob(accumulator, jobAndTasks);
            }
        }

        return accumulator.toReservationUsage();
    }

    @Inject public  ReservationUsageCalculator(ReadOnlyJobOperations jobOperations,
                                      ApplicationSlaManagementService capacityManagementService);

}