RandomAccessQueue { public synchronized List<T> consume(int start, int end) { List<T> rets = get(start, end); int upperBound = Math.min(end, size - 1); head = (end + 1) % capacity; size -= upperBound + 1; return rets; } RandomAccessQueue(Class<T> t, int capacity); synchronized List<T> get(int start, int end); synchronized T get(int index); synchronized void add(T t); synchronized List<T> consume(int start, int end); synchronized int getHead(); synchronized int getSize(); synchronized void clear();  }
@Test public void testConsume() { mQueue.clear(); for (int i = 0; i < 4; i++) { mQueue.add(i); } List<Integer> rets = mQueue.consume(1, 2); Assert.assertEquals(1, mQueue.getSize()); Assert.assertEquals(3, mQueue.getHead()); }