Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Iterator;
- /**
- * Specifies an abstract data type for a completely unordered collection of
- * generic objects that is not permitted to contain any duplicated elements, as
- * defined by the generic object's equals method.
- *
- * @author Lewis & Chase ISBN 0-321-24584-9 Ch03
- * @version 2011-09-15 by D.P. Daugherty
- *
- */
- public interface SetADT<T> {
- /**
- * Adds one element to the set, but only if an equal element is not already
- * contained therein.
- *
- * @param element
- * the element to be added
- */
- public void add(T element);
- /**
- * Removes and returns a randomly selected element from the set and adjusts
- * the set size accordingly
- *
- * @return the element which has been removed from the set
- * @throws EmptySetException
- */
- public T removeRandom();
- /**
- * Removes the specified element if it is present in the set, otherwise
- * makes no changes
- *
- * @param element
- */
- public void remove(T element);
- /**
- * Combines the elements of two sets into a third new set with no duplicates
- * permitted
- *
- * @param set
- * the set to be combined with this set
- * @return a new set that contains the union of the two sets being combined
- */
- public SetADT<T> union(SetADT<T> set);
- /**
- * Checks to see if an element is already contained in the set
- *
- * @param element
- * the element to be checked for containment
- * @return true if element is contained in the set, false otherwise
- */
- public boolean contains(T element);
- /**
- * Check to see if two sets are exactly equal, ignoring order of the
- * elements
- *
- * @param set
- * the set to be checked for equality
- * @return true if two sets contain exactly the same elements
- */
- public boolean equals(SetADT<T> set);
- /**
- * Check to see if set contains no elements
- *
- * @return true if set has no elements, false otherwise
- */
- public boolean isEmpty();
- /**
- * Returns the number of distinct elements in the set
- *
- * @return count of distinct elements
- */
- public int size();
- public Iterator<T> iterator();
- /**
- * Returns a list of elements in the set separated by commas and enclosed in
- * square brackets
- *
- * @return a string describing the contents of the set
- */
- public String toString();
- }
Add Comment
Please, Sign In to add comment