Source of 13.8.java


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