/** * Returns the next object in the buffer. * * @return the next object in the buffer * @throws BufferUnderflowException * if this buffer is empty */ @Override public E get() { if (isEmpty()) { throw new BufferUnderflowException("The buffer is already empty"); } return buffer[head]; }
@Override public void remove() { if (lastReturnedIndex == -1) { throw new IllegalStateException(); } // First element can be removed quickly if (lastReturnedIndex == head) { UnboundedFifoBuffer.this.remove(); lastReturnedIndex = -1; return; } // Other elements require us to shift the subsequent elements int i = lastReturnedIndex + 1; while (i != tail) { if (i >= buffer.length) { buffer[i - 1] = buffer[0]; i = 0; } else { buffer[i - 1] = buffer[i]; i++; } } lastReturnedIndex = -1; tail = decrement(tail); buffer[tail] = null; index = decrement(index); }
/** * Returns true if this buffer is empty; false otherwise. * * @return true if this buffer is empty */ @Override public boolean isEmpty() { return (size() == 0); }
cluster.add(root); Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(root);
cluster.add(root); Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(root);
Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(source);
if (size() + 1 >= buffer.length) { E[] tmp = (E[]) new Object[((buffer.length - 1) * 2) + 1];
/** * Removes the next object from the buffer * * @return the removed object * @throws BufferUnderflowException * if this buffer is empty */ @Override public E remove() { if (isEmpty()) { throw new BufferUnderflowException("The buffer is already empty"); } E element = buffer[head]; if (null != element) { buffer[head] = null; head++; if (head >= buffer.length) { head = 0; } } return element; }
Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(source);
Buffer<V> queue = new UnboundedFifoBuffer<V>(); queue.add(s);