1: /**
2: A class of bags whose entries are stored in a fixed-size array.
3: INITIAL, INCOMPLETE DEFINITION; no security checks
4: @author Frank M. Carrano
5: @version 4.0
6: */
7: public final class ArrayBag<T> implements BagInterface<T>
8: {
9: private final T[] bag;
10: private int numberOfEntries;
11: private static final int DEFAULT_CAPACITY = 25;
12:
13: /** Creates an empty bag whose capacity is 25. */
14: public ArrayBag()
15: {
16: this(DEFAULT_CAPACITY);
17: } // end default constructor
18:
19: /** Creates an empty bag having a given capacity.
20: @param capacity The integer capacity desired. */
21: public ArrayBag(int capacity)
22: {
23: // The cast is safe because the new array contains null entries.
24: @SuppressWarnings("unchecked")
25: T[] tempBag = (T[])new Object[desiredCapacity]; // Unchecked cast
26: bag = tempBag;
27: numberOfEntries = 0;
28: } // end constructor
29:
30: /** Adds a new entry to this bag.
31: @param newEntry The object to be added as a new entry.
32: @return True if the addition is successful, or false if not. */
33: public boolean add(T newEntry)
34: {
35: // To be defined
36: } // end add
37:
38: /** Retrieves all entries that are in this bag.
39: @return A newly allocated array of all the entries in this bag. */
40: public T[] toArray()
41: {
42: // To be defined
43: } // end toArray
44:
45: // Returns true if the array bag is full, or false if not.
46: private boolean isArrayFull()
47: {
48: // To be defined
49: } // end isArrayFull
50:
51: /** Sees whether this bag is empty.
52: @return True if the bag is empty, or false if not. */
53: public boolean isEmpty()
54: {
55: // To be defined
56: } // end add
57:
58: /** Adds a new entry to this bag.
59: @param newEntry The object to be added as a new entry.
60: @return True if the addition is successful, or false if not. */
61: public boolean add(T newEntry)
62: {
63: // To be defined
64: } // end add
65:
66: /** Removes one unspecified entry from this bag, if possible.
67: @return Either the removed entry, if the removal.
68: was successful, or null. */
69: public T remove()
70: {
71: // To be defined
72: } // end remove
73:
74: /** Removes one occurrence of a given entry from this bag.
75: @param anEntry The entry to be removed.
76: @return True if the removal was successful, or false if not. */
77: public boolean remove(T anEntry)
78: {
79: // To be defined
80: } // end remove
81:
82: /** Removes all entries from this bag. */
83: public void clear()
84: {
85: // To be defined
86: } // end clear
87:
88: /** Counts the number of times a given entry appears in this bag.
89: @param anEntry The entry to be counted.
90: @return The number of times anEntry appears in the bag. */
91: public int getFrequencyOf(T anEntry)
92: {
93: // To be defined
94: } // end getFrequencyOf
95:
96: /** Tests whether this bag contains a given entry.
97: @param anEntry The entry to locate.
98: @return True if the bag contains anEntry, or false if not. */
99: public boolean contains(T anEntry)
100: {
101: // To be defined
102: } // end contains
103: } // end ArrayBag
104:
105:
106:
107: