@Test public void testRemove() { final int capacity = 5; final ICircularBuffer<String> buffer = CircularBuffer.create(capacity); buffer.add("1"); buffer.add("2"); buffer.add("3"); buffer.add("4"); buffer.add("5"); buffer.add("6"); assertBufferHasStringValues(buffer, "2", "3", "4", "5", "6"); Assert.assertEquals(5, buffer.size()); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(4, buffer.size()); assertBufferHasStringValues(buffer, "2", "3", "4", "5", null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(3, buffer.size()); assertBufferHasStringValues(buffer, "2", "3", "4", null, null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(2, buffer.size()); assertBufferHasStringValues(buffer, "2", "3", null, null, null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(1, buffer.size()); assertBufferHasStringValues(buffer, "2", null, null, null, null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(0, buffer.size()); assertBufferHasStringValues(buffer, null, null, null, null, null); Assert.assertFalse(buffer.removeLast()); Assert.assertEquals(0, buffer.size()); assertBufferHasStringValues(buffer, null, null, null, null, null); buffer.add("A"); buffer.add("B"); buffer.add("C"); assertBufferHasStringValues(buffer, "A", "B", "C", null, null); Assert.assertEquals(3, buffer.size()); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(2, buffer.size()); assertBufferHasStringValues(buffer, "A", "B", null, null, null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(1, buffer.size()); assertBufferHasStringValues(buffer, "A", null, null, null, null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(0, buffer.size()); assertBufferHasStringValues(buffer, null, null, null, null, null); Assert.assertFalse(buffer.removeLast()); Assert.assertEquals(0, buffer.size()); assertBufferHasStringValues(buffer, null, null, null, null, null); buffer.add("A1"); buffer.add("B1"); buffer.add("C1"); buffer.add("D1"); buffer.add("E1"); assertBufferHasStringValues(buffer, "A1", "B1", "C1", "D1", "E1"); Assert.assertEquals(5, buffer.size()); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(4, buffer.size()); assertBufferHasStringValues(buffer, "A1", "B1", "C1", "D1", null); buffer.add("E2"); Assert.assertEquals(5, buffer.size()); assertBufferHasStringValues(buffer, "A1", "B1", "C1", "D1", "E2"); buffer.add("E2"); buffer.add("F2"); buffer.add("G2"); buffer.add("H2"); buffer.add("I2"); Assert.assertEquals(5, buffer.size()); assertBufferHasStringValues(buffer, "E2", "F2", "G2", "H2", "I2"); buffer.add("J2"); buffer.add("K2"); buffer.add("L2"); buffer.add("M2"); buffer.add("N2"); Assert.assertEquals(5, buffer.size()); assertBufferHasStringValues(buffer, "J2", "K2", "L2", "M2", "N2"); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(4, buffer.size()); assertBufferHasStringValues(buffer, "J2", "K2", "L2", "M2", null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(3, buffer.size()); assertBufferHasStringValues(buffer, "J2", "K2", "L2", null, null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(2, buffer.size()); assertBufferHasStringValues(buffer, "J2", "K2", null, null, null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(1, buffer.size()); assertBufferHasStringValues(buffer, "J2", null, null, null, null); Assert.assertTrue(buffer.removeLast()); Assert.assertEquals(0, buffer.size()); assertBufferHasStringValues(buffer, null, null, null, null, null); Assert.assertFalse(buffer.removeLast()); Assert.assertEquals(0, buffer.size()); assertBufferHasStringValues(buffer, null, null, null, null, null); }
public static <ELEMENT_TYPE> ICircularBuffer<ELEMENT_TYPE> create(final int capacity) { return new CircularBufferImpl<ELEMENT_TYPE>(capacity); }
CircularBuffer { public static <ELEMENT_TYPE> ICircularBuffer<ELEMENT_TYPE> create(final int capacity) { return new CircularBufferImpl<ELEMENT_TYPE>(capacity); } }
CircularBuffer { public static <ELEMENT_TYPE> ICircularBuffer<ELEMENT_TYPE> create(final int capacity) { return new CircularBufferImpl<ELEMENT_TYPE>(capacity); } private  CircularBuffer(); }
CircularBuffer { public static <ELEMENT_TYPE> ICircularBuffer<ELEMENT_TYPE> create(final int capacity) { return new CircularBufferImpl<ELEMENT_TYPE>(capacity); } private  CircularBuffer(); static ICircularBuffer<ELEMENT_TYPE> create(final int capacity); }
CircularBuffer { public static <ELEMENT_TYPE> ICircularBuffer<ELEMENT_TYPE> create(final int capacity) { return new CircularBufferImpl<ELEMENT_TYPE>(capacity); } private  CircularBuffer(); static ICircularBuffer<ELEMENT_TYPE> create(final int capacity);  }