/** * 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]; }
/** * 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; }