A DESCRIPTION OF THE PROBLEM :
The intent in the implementation is to keep the largest buffers in the cache by sorting the array in descending order. However the comparator does not do this and the cache always ends up empty.
```
return Integer.compare(getCapacity(br1), getCapacity(br2));
```
Should be:
```
return Integer.compare(getCapacity(br2), getCapacity(br1));
```
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Copy-paste the class and add the code.
---------- BEGIN SOURCE ----------
```
static void main() {
var buffers = List.of(
getBuffer(4096L),
getBuffer(8192L),
getBuffer(16384L)
);
buffers.forEach(ImageBufferCache::releaseBuffer);
System.out.println(Arrays.toString(CACHE.get()));
}
```
---------- END SOURCE ----------
FREQUENCY :
ALWAYS
The intent in the implementation is to keep the largest buffers in the cache by sorting the array in descending order. However the comparator does not do this and the cache always ends up empty.
```
return Integer.compare(getCapacity(br1), getCapacity(br2));
```
Should be:
```
return Integer.compare(getCapacity(br2), getCapacity(br1));
```
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Copy-paste the class and add the code.
---------- BEGIN SOURCE ----------
```
static void main() {
var buffers = List.of(
getBuffer(4096L),
getBuffer(8192L),
getBuffer(16384L)
);
buffers.forEach(ImageBufferCache::releaseBuffer);
System.out.println(Arrays.toString(CACHE.get()));
}
```
---------- END SOURCE ----------
FREQUENCY :
ALWAYS