Source of 2.41.java


  1:    // @author Frank M. Carrano, Timothy M. Henry
  2:    // @version 5.0
  3:    // Throws an exception if the client requests a capacity that is too large.
  4:    private void checkCapacity(int capacity)
  5:    {
  6:       if (capacity > MAX_CAPACITY)
  7:          throw new IllegalStateException("Attempt to create a bag whose " +
  8:                                          "capacity exeeds allowed " +
  9:                                          "maximum of " + MAX_CAPACITY);
 10:    } // end checkCapacity

 12:    // Doubles the size of the array bag.
 13:    // Precondition: checkIntegrity has been called.
 14:    private void doubleCapacity()
 15:    {
 16:       int newLength = 2 * bag.length;
 17:       checkCapacity(newLength);
 18:       bag = Arrays.copyOf(bag, newLength);
 19:    } // end doubleCapacity