Example #1
0
 /**
  * @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;
 }
Example #2
0
 /**
  * @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;
 }
Example #3
0
 /*
  * @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;
 }
Example #4
0
 /** If i<0 or i>=getSize(), throws IndexOutOfBoundsException. Else returns this[i] */
 public Object get(int i) throws IndexOutOfBoundsException {
   initialize();
   return buf[index(i)];
 }