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