Source of 11.8.java


  1: // @author Frank M. Carrano, Timothy M. Henry
  2: // @version 5.0
  3: public void add(int newPosition, T newEntry)
  4: {
  5:    checkIntegrity();
  6:    // Assertion: The array list has room for another entry.
  7:    if ((newPosition >= 1) && (newPosition <= numberOfEntries + 1))
  8:    {
  9:       if (newPosition <= numberOfEntries)
 10:          makeRoom(newPosition);
 11:       list[newPosition] = newEntry;
 12:       numberOfEntries++;
 13:       ensureCapacity(); // Ensure enough room for next add
 14:    }
 15:    else
 16:       throw new IndexOutOfBoundsException(
 17:                 "Given position of add's new entry is out of bounds.");
 18: } // end add