Reputation: 6531
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?
Upvotes: 3
Views: 1047
Reputation: 144
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.
Upvotes: 3
Reputation: 2390
When BoundedFifoBuffer s full it prevent insertion of another element. But in CircularFifoBuffer ,it removes eldest one ,once it full.
Upvotes: 2
Reputation: 15434
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.
Upvotes: 5