示例#1
0
  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;
  }
示例#2
0
 // Ensure that the array indexing starts at 0.
 public void cleanup() {
   if (start != 0) setCapacity(elements.length);
 }
示例#3
0
 /* 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);
   }
 }