/**
  * @modifies this
  * @effects adds x to the tail of this, removing the head if necessary so that the number of
  *     elements in this is less than or equal to the maximum size. Returns the element removed, or
  *     null if none was removed.
  */
 public Object addLast(Object x) {
   initialize();
   Object ret = null;
   if (isFull()) ret = removeFirst();
   buf[tail] = x;
   tail = increment(tail);
   return ret;
 }
 /**
  * @modifies this
  * @effects adds x to the head of this, removing the tail if necessary so that the number of
  *     elements in this is less than or equal to the maximum size. Returns the element removed, or
  *     null if none was removed.
  */
 public Object addFirst(Object x) {
   initialize();
   Object ret = null;
   if (isFull()) ret = removeLast();
   head = decrement(head);
   buf[head] = x;
   return ret;
 }
 /*
  * @modifies this[i]
  * @effects If i<0 or i>=getSize(), throws IndexOutOfBoundsException
  *  and does not modify this.  Else this[i]=o.
  */
 public void set(int i, Object o) throws IndexOutOfBoundsException {
   initialize();
   buf[index(i)] = o;
 }
 /** If i<0 or i>=getSize(), throws IndexOutOfBoundsException. Else returns this[i] */
 public Object get(int i) throws IndexOutOfBoundsException {
   initialize();
   return buf[index(i)];
 }