import java.util.*; /** * Adapts a set to contain only shapes of type AShape. * @author Jeff Raab */ public class SetOfAShape { /** Set containing shapes. */ private JavaSet shapes = new JavaSet(); /** Constructs an empty set of shapes. */ public SetOfAShape() {} /** * Adds the given shape to this. * @param anAShape shape to be added */ public void add(AShape anAShape) { shapes.add(anAShape); } /** * Removes the given shape from this. * @param anAShape shape to be removed */ public void remove(AShape anAShape) { shapes.remove(anAShape); } /** * Sets this to its union with the given set. * @param aSet set with which to union */ public void union(SetOfAShape aSet) { shapes.union(aSet.shapes); } /** * Sets this to its intersection with the given set. * @param aSet set with which to intersect */ public void intersection(SetOfAShape aSet) { shapes.intersection(aSet.shapes); } /** Returns the number of shapes in this. */ public int size() { return shapes.size(); } /** * Returns whether or not this contains the given shape. * @param anAShape shape to compare with contents of this */ public boolean contains(AShape anAShape) { return shapes.contains(anAShape); } /** * Returns whether or not the given object equals this. * @param anObject object to compare with this */ public boolean equals(Object anObject) { return shapes.equals(anObject); } /** Returns an item in this. */ public AShape item() { return (AShape)shapes.item(); } /** Returns an enumeration of the contents of this. */ public Enumeration elements() { return shapes.elements(); } }