class EnvironmentRamCalculator {

  public long calculate(@Nullable Environment environment) throws ServerException {
    if (environment == null) {
      return 0;
    }
    try {
      return getInternalEnvironment(environment)
              .getMachines()
              .values()
              .stream()
              .mapToLong(
                  m -> parseMemoryAttributeValue(m.getAttributes().get(MEMORY_LIMIT_ATTRIBUTE)))
              .sum()
          / BYTES_TO_MEGABYTES_DIVIDER;
    } catch (InfrastructureException | ValidationException | NotFoundException ex) {
      throw new ServerException(ex.getMessage(), ex);
    }
  }

  @Inject public  EnvironmentRamCalculator(Map<String, InternalEnvironmentFactory> environmentFactories);

}