1: // Throws an exception if the client requests a capacity that is too large.
2: private void checkCapacity(int capacity)
3: {
4: if (capacity > MAX_CAPACITY)
5: throw new IllegalStateException("Attempt to create a bag whose " +
6: "capacity exeeds allowed " +
7: "maximum of " + MAX_CAPACITY);
8: } // end checkCapacity
9:
10: // Doubles the size of the array bag.
11: // Precondition: checkInitialization has been called.
12: private void doubleCapacity()
13: {
14: int newLength = 2 * bag.length;
15: checkCapacity(newLength);
16: bag = Arrays.copyOf(bag, newLength);
17: } // end doubleCapacity