@Test(expected = IllegalStateException.class) public void fullQueue() { for (int i = 0; i < MAX_CAPACITY + 1; i++) { toTest.enqueue("X"); } }
@Override public void enqueue(final DATA value) { if (top < 0) { top = 0; bottom = 0; storage[0] = value; } else { final int bottomToBe = (bottom + 1) % storage.length; if (bottomToBe == top) { throw new IllegalStateException("Queue is full."); } bottom = bottomToBe; storage[bottom] = value; } }
ArrayQueue implements Queue<DATA> { @Override public void enqueue(final DATA value) { if (top < 0) { top = 0; bottom = 0; storage[0] = value; } else { final int bottomToBe = (bottom + 1) % storage.length; if (bottomToBe == top) { throw new IllegalStateException("Queue is full."); } bottom = bottomToBe; storage[bottom] = value; } } }
ArrayQueue implements Queue<DATA> { @Override public void enqueue(final DATA value) { if (top < 0) { top = 0; bottom = 0; storage[0] = value; } else { final int bottomToBe = (bottom + 1) % storage.length; if (bottomToBe == top) { throw new IllegalStateException("Queue is full."); } bottom = bottomToBe; storage[bottom] = value; } } ArrayQueue(final int capacity); }
ArrayQueue implements Queue<DATA> { @Override public void enqueue(final DATA value) { if (top < 0) { top = 0; bottom = 0; storage[0] = value; } else { final int bottomToBe = (bottom + 1) % storage.length; if (bottomToBe == top) { throw new IllegalStateException("Queue is full."); } bottom = bottomToBe; storage[bottom] = value; } } ArrayQueue(final int capacity); @Override void enqueue(final DATA value); @Override DATA dequeue(); @Override boolean isEmpty(); }
ArrayQueue implements Queue<DATA> { @Override public void enqueue(final DATA value) { if (top < 0) { top = 0; bottom = 0; storage[0] = value; } else { final int bottomToBe = (bottom + 1) % storage.length; if (bottomToBe == top) { throw new IllegalStateException("Queue is full."); } bottom = bottomToBe; storage[bottom] = value; } } ArrayQueue(final int capacity); @Override void enqueue(final DATA value); @Override DATA dequeue(); @Override boolean isEmpty();  }