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: /** Removes one unspecified entry from this bag, if possible. 21: @return Either the removed entry, if the removal. 22: was successful, or null. */ 23: public T remove(); 24: 25: /** Removes one occurrence of a given entry from this bag. 26: @param anEntry The entry to be removed. 27: @return True if the removal was successful, or false if not. */ 28: public boolean remove(T anEntry); 29: 30: /** Removes all entries from this bag. */ 31: public void clear(); 32: 33: /** Counts the number of times a given entry appears in this bag. 34: @param anEntry The entry to be counted. 35: @return The number of times anEntry appears in the bag. */ 36: public int getFrequencyOf(T anEntry); 37: 38: /** Tests whether this bag contains a given entry. 39: @param anEntry The entry to locate. 40: @return True if the bag contains anEntry, or false if not. */ 41: public boolean contains(T anEntry); 42: 43: /** Retrieves all entries that are in this bag. 44: @return A newly allocated array of all the entries in the bag. 45: Note: If the bag is empty, the returned array is empty. */ 46: public T[] toArray(); 47: } // end BagInterface