@Test public void testPollOrder() { RingBuffer<String> test = new RingBuffer<String>(1000); for (int i = 0; i < 1000; i++) { test.add(String.format("Offer: %s", i)); } for (int i = 0; i < 1000; i++) { String element = test.poll(); assertEquals(String.format("Offer: %s", i), element); } }
@Override public T poll() { if (size == 0) { return null; } T item = items[head]; items[head] = null; size--; head = (head + 1) % items.length; return item; }
RingBuffer extends AbstractQueue<T> { @Override public T poll() { if (size == 0) { return null; } T item = items[head]; items[head] = null; size--; head = (head + 1) % items.length; return item; } }
RingBuffer extends AbstractQueue<T> { @Override public T poll() { if (size == 0) { return null; } T item = items[head]; items[head] = null; size--; head = (head + 1) % items.length; return item; } @SuppressWarnings("unchecked")  RingBuffer(int capacity); }
RingBuffer extends AbstractQueue<T> { @Override public T poll() { if (size == 0) { return null; } T item = items[head]; items[head] = null; size--; head = (head + 1) % items.length; return item; } @SuppressWarnings("unchecked")  RingBuffer(int capacity); @Override Iterator<T> iterator(); @Override boolean offer(T value); @Override T peek(); @Override T poll(); @Override int size(); @Override String toString(); }
RingBuffer extends AbstractQueue<T> { @Override public T poll() { if (size == 0) { return null; } T item = items[head]; items[head] = null; size--; head = (head + 1) % items.length; return item; } @SuppressWarnings("unchecked")  RingBuffer(int capacity); @Override Iterator<T> iterator(); @Override boolean offer(T value); @Override T peek(); @Override T poll(); @Override int size(); @Override String toString();  }