Guest User

Untitled

a guest
Dec 10th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1.  
  2. import java.util.Iterator;
  3.  
  4. /**
  5.  * Specifies an abstract data type for a completely unordered collection of
  6.  * generic objects that is not permitted to contain any duplicated elements, as
  7.  * defined by the generic object's equals method.
  8.  *
  9.  * @author Lewis & Chase ISBN 0-321-24584-9 Ch03
  10.  * @version 2011-09-15 by D.P. Daugherty
  11.  *
  12.  */
  13. public interface SetADT<T> {
  14.  
  15.     /**
  16.      * Adds one element to the set, but only if an equal element is not already
  17.      * contained therein.
  18.      *
  19.      * @param element
  20.      *            the element to be added
  21.      */
  22.     public void add(T element);
  23.  
  24.     /**
  25.      * Removes and returns a randomly selected element from the set and adjusts
  26.      * the set size accordingly
  27.      *
  28.      * @return the element which has been removed from the set
  29.      * @throws EmptySetException
  30.      */
  31.     public T removeRandom();
  32.  
  33.     /**
  34.      * Removes the specified element if it is present in the set, otherwise
  35.      * makes no changes
  36.      *
  37.      * @param element
  38.      */
  39.     public void remove(T element);
  40.  
  41.     /**
  42.      * Combines the elements of two sets into a third new set with no duplicates
  43.      * permitted
  44.      *
  45.      * @param set
  46.      *            the set to be combined with this set
  47.      * @return a new set that contains the union of the two sets being combined
  48.      */
  49.     public SetADT<T> union(SetADT<T> set);
  50.  
  51.     /**
  52.      * Checks to see if an element is already contained in the set
  53.      *
  54.      * @param element
  55.      *            the element to be checked for containment
  56.      * @return true if element is contained in the set, false otherwise
  57.      */
  58.     public boolean contains(T element);
  59.  
  60.     /**
  61.      * Check to see if two sets are exactly equal, ignoring order of the
  62.      * elements
  63.      *
  64.      * @param set
  65.      *            the set to be checked for equality
  66.      * @return true if two sets contain exactly the same elements
  67.      */
  68.     public boolean equals(SetADT<T> set);
  69.  
  70.     /**
  71.      * Check to see if set contains no elements
  72.      *
  73.      * @return true if set has no elements, false otherwise
  74.      */
  75.     public boolean isEmpty();
  76.  
  77.     /**
  78.      * Returns the number of distinct elements in the set
  79.      *
  80.      * @return count of distinct elements
  81.      */
  82.     public int size();
  83.  
  84.     public Iterator<T> iterator();
  85.  
  86.     /**
  87.      * Returns a list of elements in the set separated by commas and enclosed in
  88.      * square brackets
  89.      *
  90.      * @return a string describing the contents of the set
  91.      */
  92.     public String toString();
  93. }
Add Comment
Please, Sign In to add comment