/** * If the buffer is full, the least recently added element is discarded so * that a new element can be inserted. * * @param element the element to add * @return true, always */ public boolean add(Object element) { if (isFull()) { remove(); } return super.add(element); }
/** * If the buffer is full, the least recently added element is discarded so * that a new element can be inserted. * * @param element the element to add * @return true, always */ public boolean add(Object element) { if (isFull()) { remove(); } return super.add(element); }
/** * Tests that the removal operation actually removes the first element. */ public void testCircularFifoBufferRemove() { resetFull(); int size = confirmed.size(); for (int i = 0; i < size; i++) { Object o1 = ((CircularFifoBuffer) collection).remove(); Object o2 = ((ArrayList) confirmed).remove(0); assertEquals("Removed objects should be equal", o1, o2); verify(); } try { ((CircularFifoBuffer) collection).remove(); fail("Empty buffer should raise Underflow."); } catch (BufferUnderflowException e) { // expected } }
public void testRemoveError1() throws Exception { // based on bug 33071 CircularFifoBuffer fifo = new CircularFifoBuffer(5); fifo.add("1"); fifo.add("2"); fifo.add("3"); fifo.add("4"); fifo.add("5"); assertEquals("[1, 2, 3, 4, 5]", fifo.toString()); fifo.remove("3"); assertEquals("[1, 2, 4, 5]", fifo.toString()); fifo.remove("4"); assertEquals("[1, 2, 5]", fifo.toString()); }
public void testRemoveError2() throws Exception { // based on bug 33071 CircularFifoBuffer fifo = new CircularFifoBuffer(5); fifo.add("1"); fifo.add("2"); fifo.add("3"); fifo.add("4"); fifo.add("5"); fifo.add("6"); assertEquals(5, fifo.size()); assertEquals("[2, 3, 4, 5, 6]", fifo.toString()); fifo.remove("3"); assertEquals("[2, 4, 5, 6]", fifo.toString()); fifo.remove("4"); assertEquals("[2, 5, 6]", fifo.toString()); }
public void testRemoveError3() throws Exception { // based on bug 33071 CircularFifoBuffer fifo = new CircularFifoBuffer(5); fifo.add("1"); fifo.add("2"); fifo.add("3"); fifo.add("4"); fifo.add("5"); assertEquals("[1, 2, 3, 4, 5]", fifo.toString()); fifo.remove("3"); assertEquals("[1, 2, 4, 5]", fifo.toString()); fifo.add("6"); fifo.add("7"); assertEquals("[2, 4, 5, 6, 7]", fifo.toString()); fifo.remove("4"); assertEquals("[2, 5, 6, 7]", fifo.toString()); }
public void testRemoveError5() throws Exception { // based on bug 33071 CircularFifoBuffer fifo = new CircularFifoBuffer(5); fifo.add("1"); fifo.add("2"); fifo.add("3"); fifo.add("4"); fifo.add("5"); // end=0 fifo.add("6"); // end=1 fifo.add("7"); // end=2 assertEquals("[3, 4, 5, 6, 7]", fifo.toString()); fifo.remove("5"); // remove element at last pos in array assertEquals("[3, 4, 6, 7]", fifo.toString()); }
public void testRemoveError7() throws Exception { // based on bug 33071 CircularFifoBuffer fifo = new CircularFifoBuffer(5); fifo.add("1"); fifo.add("2"); fifo.add("3"); fifo.add("4"); fifo.add("5"); // end=0 fifo.add("6"); // end=1 fifo.add("7"); // end=2 assertEquals("[3, 4, 5, 6, 7]", fifo.toString()); fifo.remove("7"); // remove element at position one in array assertEquals("[3, 4, 5, 6]", fifo.toString()); }
public void testRemoveError4() throws Exception { // based on bug 33071 CircularFifoBuffer fifo = new CircularFifoBuffer(5); fifo.add("1"); fifo.add("2"); fifo.add("3"); fifo.add("4"); fifo.add("5"); // end=0 fifo.add("6"); // end=1 fifo.add("7"); // end=2 assertEquals("[3, 4, 5, 6, 7]", fifo.toString()); fifo.remove("4"); // remove element in middle of array, after start assertEquals("[3, 5, 6, 7]", fifo.toString()); }
public void testRemoveError6() throws Exception { // based on bug 33071 CircularFifoBuffer fifo = new CircularFifoBuffer(5); fifo.add("1"); fifo.add("2"); fifo.add("3"); fifo.add("4"); fifo.add("5"); // end=0 fifo.add("6"); // end=1 fifo.add("7"); // end=2 assertEquals("[3, 4, 5, 6, 7]", fifo.toString()); fifo.remove("6"); // remove element at position zero in array assertEquals("[3, 4, 5, 7]", fifo.toString()); }
public void testRemoveError9() throws Exception { // based on bug 33071 CircularFifoBuffer fifo = new CircularFifoBuffer(5); fifo.add("1"); fifo.add("2"); fifo.add("3"); fifo.add("4"); fifo.add("5"); // end=0 fifo.add("6"); // end=1 fifo.add("7"); // end=2 fifo.add("8"); // end=3 assertEquals("[4, 5, 6, 7, 8]", fifo.toString()); fifo.remove("8"); // remove element at position two in array assertEquals("[4, 5, 6, 7]", fifo.toString()); }
public void testRemoveError8() throws Exception { // based on bug 33071 CircularFifoBuffer fifo = new CircularFifoBuffer(5); fifo.add("1"); fifo.add("2"); fifo.add("3"); fifo.add("4"); fifo.add("5"); // end=0 fifo.add("6"); // end=1 fifo.add("7"); // end=2 fifo.add("8"); // end=3 assertEquals("[4, 5, 6, 7, 8]", fifo.toString()); fifo.remove("7"); // remove element at position one in array, need to shift 8 assertEquals("[4, 5, 6, 8]", fifo.toString()); }
public LogEvent remove() { return (LogEvent) buffer.remove(); }
/** * If the buffer is full, the least recently added element is discarded so * that a new element can be inserted. * * @param element the element to add * @return true, always */ public boolean add(Object element) { if (isFull()) { remove(); } return super.add(element); }
/** * If the buffer is full, the least recently added element is discarded so * that a new element can be inserted. * * @param element the element to add * @return true, always */ public boolean add(Object element) { if (isFull()) { remove(); } return super.add(element); }
/** * If the buffer is full, the least recently added element is discarded so * that a new element can be inserted. * * @param element the element to add * @return true, always */ public boolean add(Object element) { if (isFull()) { remove(); } return super.add(element); }
/** * If the buffer is full, the least recently added element is discarded so * that a new element can be inserted. * * @param element the element to add * @return true, always */ public boolean add(Object element) { if (isFull()) { remove(); } return super.add(element); }
/** * If the buffer is full, the least recently added element is discarded so * that a new element can be inserted. * * @param element the element to add * @return true, always */ public boolean add(Object element) { if (isFull()) { remove(); } return super.add(element); }
private void addToLastUnfinishedTimerDataList(MonitorData mdata) { // We should remove the oldest entry if (lastUnfinishedTimerDataList.isFull()) lastUnfinishedTimerDataList.remove(lastUnfinishedTimerDataList.get()); lastUnfinishedTimerDataList.add(mdata); }
private void addToTimerDataList(MonitorData mdata) { // We should remove the oldest entry if (lastTimerDataList.isFull()) lastTimerDataList.remove(lastTimerDataList.get()); lastTimerDataList.add(mdata); }