public boolean offer(T o) { if (o == null) return false; int incend = inc(end); if (incend == start) { setCapacity(elements.length * 2); incend = inc(end); } elements[end] = o; end = incend; return true; }
// Ensure that the array indexing starts at 0. public void cleanup() { if (start != 0) setCapacity(elements.length); }
/* For cap elements, need an array of length at least cap+1 */ private void ensureCapacity(int cap) { if (elements.length < cap + 1) { setCapacity(cap * 2); } }