@Test public void testLimit_EdgeUnderSmallest() { long limit = REC_A_100K.getNewEntry().getUncompressedSize() - 1; TotalRecompressionLimiter limiter = new TotalRecompressionLimiter(limit); List<QualifiedRecommendation> expected = new ArrayList<QualifiedRecommendation>(); expected.addAll(suppressed(REC_A_100K, REC_B_200K, REC_C_300K, REC_D_400K)); expected.addAll(ALL_IGNORED_RECS); assertEquivalence(expected, limiter.getModifiedRecommendations(OLD_FILE, NEW_FILE, ALL_RECS)); }
@Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = new ArrayList<QualifiedRecommendation>(originalRecommendations); Collections.sort(sorted, COMPARATOR); Collections.reverse(sorted); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long recompressibleBytesRemaining = maxBytesToRecompress; for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressNewEntry) { result.add(originalRecommendation); } else { long bytesToRecompress = originalRecommendation.getNewEntry().getUncompressedSize(); if (recompressibleBytesRemaining - bytesToRecompress >= 0) { result.add(originalRecommendation); recompressibleBytesRemaining -= bytesToRecompress; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; }
TotalRecompressionLimiter implements RecommendationModifier { @Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = new ArrayList<QualifiedRecommendation>(originalRecommendations); Collections.sort(sorted, COMPARATOR); Collections.reverse(sorted); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long recompressibleBytesRemaining = maxBytesToRecompress; for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressNewEntry) { result.add(originalRecommendation); } else { long bytesToRecompress = originalRecommendation.getNewEntry().getUncompressedSize(); if (recompressibleBytesRemaining - bytesToRecompress >= 0) { result.add(originalRecommendation); recompressibleBytesRemaining -= bytesToRecompress; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } }
TotalRecompressionLimiter implements RecommendationModifier { @Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = new ArrayList<QualifiedRecommendation>(originalRecommendations); Collections.sort(sorted, COMPARATOR); Collections.reverse(sorted); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long recompressibleBytesRemaining = maxBytesToRecompress; for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressNewEntry) { result.add(originalRecommendation); } else { long bytesToRecompress = originalRecommendation.getNewEntry().getUncompressedSize(); if (recompressibleBytesRemaining - bytesToRecompress >= 0) { result.add(originalRecommendation); recompressibleBytesRemaining -= bytesToRecompress; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } TotalRecompressionLimiter(long maxBytesToRecompress); }
TotalRecompressionLimiter implements RecommendationModifier { @Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = new ArrayList<QualifiedRecommendation>(originalRecommendations); Collections.sort(sorted, COMPARATOR); Collections.reverse(sorted); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long recompressibleBytesRemaining = maxBytesToRecompress; for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressNewEntry) { result.add(originalRecommendation); } else { long bytesToRecompress = originalRecommendation.getNewEntry().getUncompressedSize(); if (recompressibleBytesRemaining - bytesToRecompress >= 0) { result.add(originalRecommendation); recompressibleBytesRemaining -= bytesToRecompress; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } TotalRecompressionLimiter(long maxBytesToRecompress); @Override List<QualifiedRecommendation> getModifiedRecommendations(
      File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations); }
TotalRecompressionLimiter implements RecommendationModifier { @Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = new ArrayList<QualifiedRecommendation>(originalRecommendations); Collections.sort(sorted, COMPARATOR); Collections.reverse(sorted); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long recompressibleBytesRemaining = maxBytesToRecompress; for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressNewEntry) { result.add(originalRecommendation); } else { long bytesToRecompress = originalRecommendation.getNewEntry().getUncompressedSize(); if (recompressibleBytesRemaining - bytesToRecompress >= 0) { result.add(originalRecommendation); recompressibleBytesRemaining -= bytesToRecompress; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } TotalRecompressionLimiter(long maxBytesToRecompress); @Override List<QualifiedRecommendation> getModifiedRecommendations(
      File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations);  }