@Test public void testAdd() { final int capacity = 100; final ICircularBuffer<Integer> buffer = CircularBuffer.create(capacity); for (int i = 0; i < capacity; i++) { final Integer element = Integer.valueOf(i); buffer.add(element); Assert.assertEquals(i + 1, buffer.size()); Assert.assertEquals(element, buffer.get(i)); } Assert.assertEquals(capacity, buffer.size()); for (int i = 0; i < 2 * capacity; i++) { final Integer previousElement = Integer.valueOf(capacity + (i - 1)); final Integer element = Integer.valueOf(capacity + i); Assert.assertEquals(previousElement, buffer.get(buffer.capacity() - 1)); buffer.add(element); Assert.assertEquals(capacity, buffer.size()); Assert.assertEquals(element, buffer.get(buffer.capacity() - 1)); Assert.assertEquals(previousElement, buffer.get(buffer.capacity() - 2)); } }
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);  }