import java.util.*; import javax.swing.*; /****************************************************************** This is the test function for Assignment 1. It creates two collections of images, draws them, and determines which pairs of images are equal (using the method of hash signatures), and prints a table of the results. The hash signature values appear in the table. ******************************************************************/ public class A1 { public static void main(String args[]) { ImageCollection imageColl =new ImageCollection(); Random r=new Random(1); // create new images and add them to the collection for (int j=0; j<9; j++) imageColl.addImage(new Image(5,r)); Iterator itr0=imageColl.iterator(); // add the first image as the final collection element imageColl.addImage(itr0.next()); // draw the collection imageColl.draw(); System.out.println(); // test which images are equal to which others, // and print the result in a table, that also // shows the hash signature value. Iterator itr1=imageColl.iterator(); while (itr1.hasNext()) { Image im1=(Image) itr1.next(); System.out.print(im1.hashCode()); System.out.print(": "); Iterator itr2=imageColl.iterator(); while (itr2.hasNext()) if (im1.equals(itr2.next())) System.out.print("+ "); else System.out.print("- "); System.out.println(); } // repeat the above with a new collection ImageCollection imageColl2 =new ImageCollection(); for (int j=0; j<8; j++) imageColl2.addImage(new Image(6,r)); imageColl2.draw(); System.out.println(); Iterator itr3=imageColl2.iterator(); while (itr3.hasNext()) { Image im3=(Image) itr3.next(); System.out.print(im3.hashCode()); System.out.print(": "); Iterator itr4=imageColl2.iterator(); while (itr4.hasNext()) { if (im3.equals(itr4.next())) System.out.print("+ "); else System.out.print("- "); } System.out.println(); } } }