Source of BagInterface.java


  1: /** BagInterface.java
  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:     /**
  9:         Add a new entry to this bag.
 10:         @param newEntry The object to be added as a new entry.
 11:         @return true if the addition is successful, or false if not.
 12:     */
 13:     public boolean add(T newEntry);

 15:     /**
 16:         Retrieve, and place into an array, all entries that are in this bag.
 17:         @return A newly allocated array of all the entries in the bag.
 18:         Note: If the bag is empty, the returned array is empty.
 19:     */
 20:     public T[] toArray();

 22:     /**
 23:         Check whether this bag is empty.
 24:         @return true if the bag is empty, or false if not.
 25:     */
 26:     public boolean isEmpty();

 28:     /**
 29:         Get the current number of entries in this bag.
 30:         @return The integer number of entries currently in the bag.
 31:     */
 32:     public int getCurrentSize();

 34:     /**
 35:         Count 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:     */
 39:     public int getFrequencyOf(T anEntry);

 41:     /**
 42:         Test whether this bag contains a given entry.
 43:         @param anEntry The entry to locate.
 44:         @return true if the bag contains anEntry, or false if not.
 45:     */
 46:     public boolean contains(T anEntry);

 48:     /**
 49:         Remove all entries from this bag.
 50:     */
 51:     public void clear();

 53:     /**
 54:         Remove one unspecified entry from this bag, if possible.
 55:         @return Either the removed entry, if removal was successful, or null.
 56:     */
 57:     public T remove();

 59:     /**
 60:         Remove one occurrence of a given entry from this bag.
 61:         @param anEntry The entry to be removed.
 62:         @return true if the removal was successful, or false if not.
 63:     */
 64:     public boolean remove(T anEntry);
 65: }