public void remove() { if (lastReturnedIndex == -1) throw new IllegalStateException(); // First element can be removed quickly if (lastReturnedIndex == m_start) { BoundedFifoBuffer.this.remove(); lastReturnedIndex = -1; return; } // Other elements require us to shift the subsequent elements int i = lastReturnedIndex + 1; while (i != m_end) { if (i >= maxElements) { m_elements[i - 1] = m_elements[0]; i = 0; } else { m_elements[i - 1] = m_elements[i]; i++; } } lastReturnedIndex = -1; m_end = decrement(m_end); m_elements[m_end] = null; m_full = false; index = decrement(index); }
public void remove() { if (lastReturnedIndex == -1) throw new IllegalStateException(); // First element can be removed quickly if (lastReturnedIndex == m_start) { BoundedFifoBuffer.this.remove(); lastReturnedIndex = -1; return; } // Other elements require us to shift the subsequent elements int i = lastReturnedIndex + 1; while (i != m_end) { if (i >= maxElements) { m_elements[i - 1] = m_elements[0]; i = 0; } else { m_elements[i - 1] = m_elements[i]; i++; } } lastReturnedIndex = -1; m_end = decrement(m_end); m_elements[m_end] = null; m_full = false; index = decrement(index); }
/** * Tests that the removal operation actually removes the first element. */ public void testBoundedFifoBufferRemove() { resetFull(); int size = confirmed.size(); for (int i = 0; i < size; i++) { Object o1 = ((BoundedFifoBuffer)collection).remove(); Object o2 = ((ArrayList)confirmed).remove(0); assertEquals("Removed objects should be equal", o1, o2); verify(); } try { ((BoundedFifoBuffer)collection).remove(); fail("Empty buffer should raise Underflow."); } catch (BufferUnderflowException e) { // expected } }
/** * Tests is full */ public void testIsFull() { resetFull(); assertEquals(true, ((BoundedCollection) collection).isFull()); ((BoundedFifoBuffer) collection).remove(); assertEquals(false, ((BoundedCollection) collection).isFull()); ((BoundedFifoBuffer) collection).add("jj"); assertEquals(true, ((BoundedCollection) collection).isFull()); }
/** * Tests max size */ public void testMaxSize() { resetFull(); assertEquals(getFullElements().length, ((BoundedCollection) collection).maxSize()); ((BoundedFifoBuffer) collection).remove(); assertEquals(getFullElements().length, ((BoundedCollection) collection).maxSize()); ((BoundedFifoBuffer) collection).add("jj"); assertEquals(getFullElements().length, ((BoundedCollection) collection).maxSize()); }
public void remove() { if (lastReturnedIndex == -1) throw new IllegalStateException(); // First element can be removed quickly if (lastReturnedIndex == m_start) { BoundedFifoBuffer.this.remove(); lastReturnedIndex = -1; return; } // Other elements require us to shift the subsequent elements int i = lastReturnedIndex + 1; while (i != m_end) { if (i >= maxElements) { m_elements[i - 1] = m_elements[0]; i = 0; } else { m_elements[i - 1] = m_elements[i]; i++; } } lastReturnedIndex = -1; m_end = decrement(m_end); m_elements[m_end] = null; m_full = false; index = decrement(index); }
public void remove() { if (lastReturnedIndex == -1) throw new IllegalStateException(); // First element can be removed quickly if (lastReturnedIndex == m_start) { BoundedFifoBuffer.this.remove(); lastReturnedIndex = -1; return; } // Other elements require us to shift the subsequent elements int i = lastReturnedIndex + 1; while (i != m_end) { if (i >= maxElements) { m_elements[i - 1] = m_elements[0]; i = 0; } else { m_elements[i - 1] = m_elements[i]; i++; } } lastReturnedIndex = -1; m_end = decrement(m_end); m_elements[m_end] = null; m_full = false; index = decrement(index); }
public void remove() { if (lastReturnedIndex == -1) throw new IllegalStateException(); // First element can be removed quickly if (lastReturnedIndex == m_start) { BoundedFifoBuffer.this.remove(); lastReturnedIndex = -1; return; } // Other elements require us to shift the subsequent elements int i = lastReturnedIndex + 1; while (i != m_end) { if (i >= maxElements) { m_elements[i - 1] = m_elements[0]; i = 0; } else { m_elements[i - 1] = m_elements[i]; i++; } } lastReturnedIndex = -1; m_end = decrement(m_end); m_elements[m_end] = null; m_full = false; index = decrement(index); }
public void remove() { if (lastReturnedIndex == -1) throw new IllegalStateException(); // First element can be removed quickly if (lastReturnedIndex == m_start) { BoundedFifoBuffer.this.remove(); lastReturnedIndex = -1; return; } // Other elements require us to shift the subsequent elements int i = lastReturnedIndex + 1; while (i != m_end) { if (i >= maxElements) { m_elements[i - 1] = m_elements[0]; i = 0; } else { m_elements[i - 1] = m_elements[i]; i++; } } lastReturnedIndex = -1; m_end = decrement(m_end); m_elements[m_end] = null; m_full = false; index = decrement(index); }
public void remove() { if (lastReturnedIndex == -1) throw new IllegalStateException(); // First element can be removed quickly if (lastReturnedIndex == m_start) { BoundedFifoBuffer.this.remove(); lastReturnedIndex = -1; return; } // Other elements require us to shift the subsequent elements int i = lastReturnedIndex + 1; while (i != m_end) { if (i >= maxElements) { m_elements[i - 1] = m_elements[0]; i = 0; } else { m_elements[i - 1] = m_elements[i]; i++; } } lastReturnedIndex = -1; m_end = decrement(m_end); m_elements[m_end] = null; m_full = false; index = decrement(index); }