Advertisement
Guest User

Untitled

a guest
Jan 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1. /**An interface for a bag of items
  2. *@author Mike Hueber
  3. *
  4. *@param<T> The type of items in the bag
  5. */
  6. public interface BagInterface<T>{
  7.     /**
  8.     *@return true if the bag is empty; false otherwise.
  9.     */
  10.     public boolean isEmpty();
  11.    
  12.     /**Returns the number of items in a bag
  13.     *@return the integer number of items in the bag
  14.     */
  15.     public int getCurrentSize();
  16.  
  17.     /**Adds an item to the bag if possible
  18.     *@param item The new item to be added
  19.     *@return true if adding succeeds and false if the bag is full
  20.     */
  21.     public boolean add(T item);
  22.  
  23.     /**Removes an unspecified item from the bag if possible
  24.     *@return the item that is removed or null if the bag is empty
  25.     */
  26.     public T remove();
  27.  
  28.     /**Searches for an item inside the bag
  29.     *@param item The item that we are searching for
  30.     *@return true if the item exists in the bag and false otherwise
  31.     */
  32.     public boolean contains(T item);
  33.  
  34.     /**Removes one copy of item from the bag
  35.     *@param item The item to remove from the bag
  36.     *@return true if the is removal is successful; false if the item does not exist in the  *bag
  37.     */
  38.     public boolean remove(T item);
  39.  
  40.     /**Returns the number of copies of item that exist in the bag
  41.     *@param item The item that we search for
  42.     *@return the integer number of copies of item in the bag
  43.     */
  44.     public int getFrequencyOf(T item);
  45.  
  46.     /**ReturnS an array that contains all the items in the bag
  47.     *@return a T[] of items in the bag
  48.     */
  49.     Public T[] toArray();
  50.  
  51.     /**Removes all items from the bag
  52.     *
  53.     */
  54.     public void clear();
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement