1: @author Frank M. Carrano, Timothy M. Henry
2: @version 5.0
3: public ArrayBag(int desiredCapacity)
4: {
5: if (desiredCapacity <= MAX_CAPACITY)
6: {
7: // The cast is safe because the new array contains null entries
8: @SuppressWarnings("unchecked")
9: T[] tempBag = (T[])new Object[capacity]; // Unchecked cast
10: bag = tempBag;
11: numberOfEntries = 0;
12: initialized = true;
13: }
14: else
15: throw new IllegalStateException("Attempt to create a bag whose " +
16: "capacity exceeds allowed maximum.");
17: } // end constructor