@Test public void testMaxLimit() { DeltaFriendlyOldBlobSizeLimiter limiter = new DeltaFriendlyOldBlobSizeLimiter(Long.MAX_VALUE); assertEquivalence(ALL_RECS, limiter.getModifiedRecommendations(tempFile, tempFile, ALL_RECS)); }
@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) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; }
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) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } }
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) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } DeltaFriendlyOldBlobSizeLimiter(long maxSizeBytes); }
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) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } DeltaFriendlyOldBlobSizeLimiter(long maxSizeBytes); @Override List<QualifiedRecommendation> getModifiedRecommendations(
      File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations); }
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) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } DeltaFriendlyOldBlobSizeLimiter(long maxSizeBytes); @Override List<QualifiedRecommendation> getModifiedRecommendations(
      File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations);  }