// A start at the implementation of a Set. // (c) 1998, 2001 duane a. bailey package structure; import java.util.Iterator; //+interface /** * Methods common to an Implementation of a set of elements irrespective * of the underlying storage mechanism. * As with the mathematical object, the elements of the set are * not duplicated. No order is implied or enforced in this structure, but * simple set operations such as intersection, union, difference, and subset * are provided. *
* Example Usage: * Given a list of students who completed a computer science thesis in the * 2001-2002 academic year at Williams College and a list of graduating * computer science majors who are continuing on to graduate school, we could * determine which thesis students are planning to attend graduate school * as follows: *
*
* public static void main(String[] argv){ * //thesis students in the class of '02 * String[] thesis = new String[]{"Doug", "Evan", "Feng"}; * * //students continuing on to grad school * String[] grad = new String[]{"Doug", "Feng", "Lida"}; * * //instantiate our sets * Set thesisSet = new {@link structure.SetVector#SetVector()}, * gradSet = new {@link structure.SetVector#SetVector()}; * * //build sets up * for(int i = 0; i < thesis.length; i++) thesisSet.{@link #add(Object) add(thesis[i])}; * for(int i = 0; i < grad.length; i++) gradSet.{@link #add(Object) add(grad[i])}; * * //calculate the intersection of the two sets * thesisSet.{@link #retainAll(Structure) retainAll(gradSet)}; * System.out.println(thesisSet); * } ** * @version $Id: AbstractSet.java,v 1.2 2005/10/18 19:47:18 terescoj Exp $ * @author, 2001 duane a. bailey */ public abstract class AbstractSet