class DeltaFriendlyOldBlobSizeLimiter implements RecommendationModifier {

  @Override
  public List<QualifiedRecommendation> getModifiedRecommendations(
      File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) {

    List<QualifiedRecommendation> sorted = sortRecommendations(originalRecommendations);

    List<QualifiedRecommendation> result = new ArrayList<>(sorted.size());
    long bytesRemaining = maxSizeBytes - oldFile.length();
    for (QualifiedRecommendation originalRecommendation : sorted) {
      if (!originalRecommendation.getRecommendation().uncompressOldEntry) {
        // Keep the original recommendation, no need to track size since it won't be uncompressed.
        result.add(originalRecommendation);
      } else {
        long extraBytesConsumed =
            originalRecommendation.getOldEntry().getUncompressedSize()
                - originalRecommendation.getOldEntry().getCompressedSize();
        if (bytesRemaining - extraBytesConsumed >= 0) {
          // Keep the original recommendation, but also subtract from the remaining space.
          result.add(originalRecommendation);
          bytesRemaining -= extraBytesConsumed;
        } else {
          // Update the recommendation to prevent uncompressing this tuple.
          result.add(
              new QualifiedRecommendation(
                  originalRecommendation.getOldEntry(),
                  originalRecommendation.getNewEntry(),
                  Recommendation.UNCOMPRESS_NEITHER,
                  RecommendationReason.RESOURCE_CONSTRAINED));
        }
      }
    }
    return result;
  }

  public  DeltaFriendlyOldBlobSizeLimiter(long maxSizeBytes);

}