import java.util.Arrays; import java.lang.UnsupportedOperationException; import edu.princeton.cs.algs4.Queue; // immutable "set" of objects of type T // (ignore the "extends Comparable"; it just is to be able to // sort the arrays public class MyCollection> { // immutable array of objects private final T[] objects; public MyCollection(T[] original) { // create defensive copy using Arrays.copyOf(T[] original, int newLength) // https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html#copyOf(T[],%20int) this.objects = Arrays.copyOf(original, original.length); // sort the array Arrays.sort(this.objects); } // compare this collection to another object y public boolean equals(Object y) { // *************************************************************** // STANDARD EQUALS STUFF // // *************************************************************** // CODE THAT IS SPECIFIC TO MyCollection's EQUALITY TESTING // throw new UnsupportedOperationException("not implemented yet"); } public static void main(String[] args) { // two equal collections MyCollection c1 = new MyCollection( new Integer[] { 1, 5, 3, 2 } ); MyCollection c2 = new MyCollection( new Integer[] { 5, 1, 2, 3 } ); // smaller collection MyCollection c3 = new MyCollection( new Integer[] { 5, 1, 2 } ); // null collection MyCollection c4 = null; // different collection MyCollection c5 = new MyCollection( new Integer[] { 5, 1, 4, 9 } ); // could use assert here System.out.println("c1 == c2?: " +c1.equals(c2)); System.out.println("c1 == c3?: " +c1.equals(c3)); System.out.println("c1 == c4?: " +c1.equals(c4)); System.out.println("c1 == c5?: " +c1.equals(c5)); } }