import edu.neu.ccs.gui.*; import edu.neu.ccs.jpf.*; import java.awt.*; import java.util.*; /** * Contains tests for the sets and filters exercise. * @author Jeff Raab */ public class SetsAndFiltersTests extends SetsAndFiltersBase { /** Starts the application. */ public static void main(String[] args) { new SetsAndFiltersTests(); }; /** Filter that removes half of the shapes from the set. */ AShapeFilter removeAboutHalf = new AShapeFilter() { public boolean filter(AShape aShape) { return (Math.random() < 0.5); } }; /** * Applies a filter to the set that removes * about half of the shapes from the set. */ public void RemoveAboutHalf() { setView.applyToModel(removeAboutHalf); } /** Filter that removes pie shapes from the set. */ AShapeFilter removePies = new AShapeFilter() { public boolean filter(AShape aShape) { return !(aShape instanceof Pie); } }; /** Applies a filter to the set that removes all pie shapes. */ public void RemovePies() { setView.applyToModel(removePies); } /** Filter that changes Colorable shapes randomly. */ AShapeFilter randomColorables = new AShapeFilter() { public boolean filter(AShape aShape) { if (aShape instanceof IColorable) { IColorable c = (IColorable)aShape; c.setColor(randomColor()); } return true; } }; /** * Applies a filter to the set that changes * Colorable shapes randomly. */ public void RandomColorables() { setView.applyToModel(randomColorables); } /** Filter that changes the color of all circles to white. */ AShapeFilter whiteCircles = new AShapeFilter() { public boolean filter(AShape aShape) { if (aShape instanceof Circle) { Circle c = (Circle)aShape; c.setColor(Color.white); } return true; } }; /** * Applies a filter to the set that changes * the color of all circles to white. */ public void WhiteCircles() { setView.applyToModel(whiteCircles); } /** Filter that changes all circles randomly. */ AShapeFilter changeCirclesRandom = new AShapeFilter() { public boolean filter(AShape aShape) { if (aShape instanceof Circle) { Circle c = (Circle)aShape; c.setColor(randomColor()); } return true; } }; /** * Applies a filter to the set that changes * the color of all possible shapes randomly. */ public void ChangeAllColors() { setView.applyToModel(randomColorables); setView.applyToModel(changeCirclesRandom); } }