1: /**
2: An interface that describes the operations of a bag of objects.
3: @author Frank M. Carrano
4: @author Timothy M. Henry
5: @version 5.0
6: */
7: public interface BagInterface<T>
8: {
9: /** Gets the current number of entries in this bag.
10: @return The integer number of entries currently in the bag. */
11: public int getCurrentSize();
12:
13: /** Sees whether this bag is empty.
14: @return True if the bag is empty, or false if not. */
15: public boolean isEmpty();
16:
17: /** Adds a new entry to this bag.
18: @param newEntry The object to be added as a new entry.
19: @return True if the addition is successful, or false if not. */
20: public boolean add(T newEntry);
22: /** Removes one unspecified entry from this bag, if possible.
23: @return Either the removed entry, if the removal.
24: was successful, or null. */
25: public T remove();
26:
27: /** Removes one occurrence of a given entry from this bag, if possible.
28: @param anEntry The entry to be removed.
29: @return True if the removal was successful, or false if not. */
30: public boolean remove(T anEntry);
31:
32: /** Removes all entries from this bag. */
33: public void clear();
34:
35: /** Counts the number of times a given entry appears in this bag.
36: @param anEntry The entry to be counted.
37: @return The number of times anEntry appears in the bag. */
38: public int getFrequencyOf(T anEntry);
39:
40: /** Tests whether this bag contains a given entry.
41: @param anEntry The entry to find.
42: @return True if the bag contains anEntry, or false if not. */
43: public boolean contains(T anEntry);
44:
45: /** Retrieves all entries that are in this bag.
46: @return A newly allocated array of all the entries in the bag.
47: Note: If the bag is empty, the returned array is empty. */
48: public T[] toArray();
49: } // end BagInterface