1: /** Adds a new entry to this bag.
2: @param newEntry The object to be added as a new entry.
3: @return True if the addition is successful, or false if not. */
4: public boolean add(T newEntry)
5: {
6: if (initialized)
7: {
8: boolean result = true;
9: if (isArrayFull())
10: {
11: result = false;
12: }
13: else
14: { // Assertion: result is true here
15: bag[numberOfEntries] = newEntry;
16: numberOfEntries++;
17: } // end if
18:
19: return result;
20: }
21: else
22: throw new SecurityException("ArrayBag object is not initialized " +
23: "properly.");
24: } // end add
25: //================================
26: // Throws an exception if this object is not initialized.
27: private void checkInitialization()
28: {
29: if (!initialized)
30: throw new SecurityException("ArrayBag object is not initialized " +
31: "properly.");
32: } // end checkInitialization
33:
34: /** Adds a new entry to this bag.
35: @param newEntry The object to be added as a new entry.
36: @return True if the addition is successful, or false if not. */
37: public boolean add(T newEntry)
38: {
39: checkInitialization();
40: boolean result = true;
41: if (isArrayFull())
42: {
43: result = false;
44: }
45: else
46: { // Assertion: result is true here
47: bag[numberOfEntries] = newEntry;
48: numberOfEntries++;
49: } // end if
50:
51: return result;
52: } // end add