/** * Adds the given element to this buffer. * * @param obj the element to add * @return true, always * @throws NullPointerException if the given element is null */ public boolean add(final Object obj) { if (obj == null) { throw new NullPointerException("Attempted to add null object to buffer"); } if (size() + 1 >= buffer.length) { // copy contents to a new buffer array Object[] tmp = new Object[((buffer.length - 1) * 2) + 1]; int j = 0; // move head to element zero in the new array for (int i = head; i != tail;) { tmp[j] = buffer[i]; buffer[i] = null; j++; i = increment(i); } buffer = tmp; head = 0; tail = j; } buffer[tail] = obj; tail = increment(tail); return true; }
/** * Adds the given element to this buffer. * * @param obj the element to add * @return true, always * @throws NullPointerException if the given element is null */ public boolean add(final Object obj) { if (obj == null) { throw new NullPointerException("Attempted to add null object to buffer"); } if (size() + 1 >= buffer.length) { // copy contents to a new buffer array Object[] tmp = new Object[((buffer.length - 1) * 2) + 1]; int j = 0; // move head to element zero in the new array for (int i = head; i != tail;) { tmp[j] = buffer[i]; buffer[i] = null; j++; i = increment(i); } buffer = tmp; head = 0; tail = j; } buffer[tail] = obj; tail = increment(tail); return true; }
/** * Removes the next object from the buffer * * @return the removed object * @throws BufferUnderflowException if this buffer is empty */ public Object remove() { if (isEmpty()) { throw new BufferUnderflowException("The buffer is already empty"); } Object element = buffer[head]; if (element != null) { buffer[head] = null; head = increment(head); } return element; }
/** * Removes the next object from the buffer * * @return the removed object * @throws BufferUnderflowException if this buffer is empty */ public Object remove() { if (isEmpty()) { throw new BufferUnderflowException("The buffer is already empty"); } Object element = buffer[head]; if (element != null) { buffer[head] = null; head = increment(head); } return element; }
/** * Adds the given element to this buffer. * * @param obj the element to add * @return true, always * @throws NullPointerException if the given element is null */ public boolean add(final Object obj) { if (obj == null) { throw new NullPointerException("Attempted to add null object to buffer"); } if (size() + 1 >= buffer.length) { // copy contents to a new buffer array Object[] tmp = new Object[((buffer.length - 1) * 2) + 1]; int j = 0; // move head to element zero in the new array for (int i = head; i != tail;) { tmp[j] = buffer[i]; buffer[i] = null; j++; i = increment(i); } buffer = tmp; head = 0; tail = j; } buffer[tail] = obj; tail = increment(tail); return true; }
/** * Adds the given element to this buffer. * * @param obj the element to add * @return true, always * @throws NullPointerException if the given element is null */ public boolean add(final Object obj) { if (obj == null) { throw new NullPointerException("Attempted to add null object to buffer"); } if (size() + 1 >= buffer.length) { // copy contents to a new buffer array Object[] tmp = new Object[((buffer.length - 1) * 2) + 1]; int j = 0; // move head to element zero in the new array for (int i = head; i != tail;) { tmp[j] = buffer[i]; buffer[i] = null; j++; i = increment(i); } buffer = tmp; head = 0; tail = j; } buffer[tail] = obj; tail = increment(tail); return true; }
/** * Adds the given element to this buffer. * * @param obj the element to add * @return true, always * @throws NullPointerException if the given element is null */ public boolean add(final Object obj) { if (obj == null) { throw new NullPointerException("Attempted to add null object to buffer"); } if (size() + 1 >= buffer.length) { // copy contents to a new buffer array Object[] tmp = new Object[((buffer.length - 1) * 2) + 1]; int j = 0; // move head to element zero in the new array for (int i = head; i != tail;) { tmp[j] = buffer[i]; buffer[i] = null; j++; i = increment(i); } buffer = tmp; head = 0; tail = j; } buffer[tail] = obj; tail = increment(tail); return true; }
/** * Adds the given element to this buffer. * * @param obj the element to add * @return true, always * @throws NullPointerException if the given element is null */ public boolean add(final Object obj) { if (obj == null) { throw new NullPointerException("Attempted to add null object to buffer"); } if (size() + 1 >= buffer.length) { // copy contents to a new buffer array Object[] tmp = new Object[((buffer.length - 1) * 2) + 1]; int j = 0; // move head to element zero in the new array for (int i = head; i != tail;) { tmp[j] = buffer[i]; buffer[i] = null; j++; i = increment(i); } buffer = tmp; head = 0; tail = j; } buffer[tail] = obj; tail = increment(tail); return true; }
/** * Adds the given element to this buffer. * * @param obj the element to add * @return true, always * @throws NullPointerException if the given element is null */ public boolean add(final Object obj) { if (obj == null) { throw new NullPointerException("Attempted to add null object to buffer"); } if (size() + 1 >= buffer.length) { // copy contents to a new buffer array Object[] tmp = new Object[((buffer.length - 1) * 2) + 1]; int j = 0; // move head to element zero in the new array for (int i = head; i != tail;) { tmp[j] = buffer[i]; buffer[i] = null; j++; i = increment(i); } buffer = tmp; head = 0; tail = j; } buffer[tail] = obj; tail = increment(tail); return true; }
/** * Removes the next object from the buffer * * @return the removed object * @throws BufferUnderflowException if this buffer is empty */ public Object remove() { if (isEmpty()) { throw new BufferUnderflowException("The buffer is already empty"); } Object element = buffer[head]; if (element != null) { buffer[head] = null; head = increment(head); } return element; }
/** * Removes the next object from the buffer * * @return the removed object * @throws BufferUnderflowException if this buffer is empty */ public Object remove() { if (isEmpty()) { throw new BufferUnderflowException("The buffer is already empty"); } Object element = buffer[head]; if (element != null) { buffer[head] = null; head = increment(head); } return element; }
/** * Removes the next object from the buffer * * @return the removed object * @throws BufferUnderflowException if this buffer is empty */ public Object remove() { if (isEmpty()) { throw new BufferUnderflowException("The buffer is already empty"); } Object element = buffer[head]; if (element != null) { buffer[head] = null; head = increment(head); } return element; }
/** * Removes the next object from the buffer * * @return the removed object * @throws BufferUnderflowException if this buffer is empty */ public Object remove() { if (isEmpty()) { throw new BufferUnderflowException("The buffer is already empty"); } Object element = buffer[head]; if (element != null) { buffer[head] = null; head = increment(head); } return element; }
/** * Removes the next object from the buffer * * @return the removed object * @throws BufferUnderflowException if this buffer is empty */ public Object remove() { if (isEmpty()) { throw new BufferUnderflowException("The buffer is already empty"); } Object element = buffer[head]; if (element != null) { buffer[head] = null; head = increment(head); } return element; }