implement comparable
@@ -23,6 +23,7 @@ import org.apache.jackrabbit.oak.commons.Buffer;
import org.apache.jackrabbit.oak.segment.spi.monitor.IOMonitor;
import org.apache.jackrabbit.oak.segment.spi.persistence.persistentcache.AbstractPersistentCache;
import org.apache.jackrabbit.oak.segment.spi.persistence.persistentcache.SegmentCacheStats;
+import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,12 +64,6 @@ public class PersistentDiskCache extends AbstractPersistentCache {
final AtomicLong evictionCount = new AtomicLong();
- private static final Comparator<SegmentCacheEntry> sortedByAccessTime = (segmentCacheEntry1, segmentCacheEntry2) -> {
- FileTime lastAccessFile1 = segmentCacheEntry1.getLastAccessTime();
- FileTime lastAccessFile2 = segmentCacheEntry2.getLastAccessTime();
- return lastAccessFile1.compareTo(lastAccessFile2);
- };
-
public PersistentDiskCache(File directory, int cacheMaxSizeMB, IOMonitor diskCacheIOMonitor) {
this.directory = directory;
this.maxCacheSizeBytes = cacheMaxSizeMB * 1024L * 1024L;
@@ -198,7 +193,7 @@ public class PersistentDiskCache extends AbstractPersistentCache {
return new SegmentCacheEntry(path, FileTime.fromMillis(Long.MAX_VALUE));
}
})
- .sorted(sortedByAccessTime);
+ .sorted(Comparator.naturalOrder());
StreamConsumer.forEach(segmentCacheEntryStream, (segmentCacheEntry, breaker) -> {
@@ -217,7 +212,7 @@ public class PersistentDiskCache extends AbstractPersistentCache {
}
}
- private static class SegmentCacheEntry {
+ private static class SegmentCacheEntry implements Comparable<SegmentCacheEntry>{
private Path path;
private FileTime lastAccessTime;
@@ -233,6 +228,11 @@ public class PersistentDiskCache extends AbstractPersistentCache {
public FileTime getLastAccessTime() {
return lastAccessTime;
}
+
+ @Override
+ public int compareTo(@NotNull SegmentCacheEntry segmentCacheEntry) {
+ return this.lastAccessTime.compareTo(segmentCacheEntry.lastAccessTime);
+ }
}
static class StreamConsumer {
