In apache common collections what is the difference between:
Ok, the first deletes oldest Entries when full, the other deletes entries in the same order, as the came in. But isn't it the same?
CircularFifoBuffer extends BoundedFifoBuffer. It only overrides single method - add:
public boolean add(Object element) {
if (isFull()) {
remove();
}
return super.add(element);
}
So the only difference is that BoundedFifoBuffer throws exception when it's full and you try to add new element while CircularFifoBuffer removes oldest element.
say you put n items in a buffer with index 1,2,3--n
Now in both CircularFifoBuffer & BoundedFifoBuffer the space is full.
In bounded buffer since the nth element is full, It will say the whole buffer is full.
In CircularFifoBuffer, If the buffer is full, the least recently added element is discarded so that a new element can be inserted. So if nth element is full it would put the next element in the 1st index.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With