1 package JSX; 2 import java.io.StringWriter ; 3 import java.io.IOException ; 4 5 6 public class Util { 7 13 public static void main(String [] args) throws IOException { Object [] leaf = {"left-leaf", "right-leaf"}; 15 Object [] branch = {leaf, "middle-leaf", leaf}; 16 Object [] root = {null, "another one", branch, leaf}; 17 root[0] = root; 18 19 Object [] leaf1 = {"left-leaf", "right-leaf"}; 20 Object [] branch1 = {leaf1, "middle-leaf", leaf1}; 21 Object [] root1 = {null, "another one", branch1, leaf1}; 22 root1[0] = root1; 23 24 new ObjOut().writeObject(root); new ObjOut().writeObject(root1); 27 System.out.print("Are they equal? "+equals(root, root1)); 28 } 29 30 public static boolean equals(Object obj1, Object obj2) { 31 String a = getString(obj1); 32 String b = getString(obj2); 33 return a.equals(b); 34 } 35 private static String getString(Object obj) { 36 try { 37 StringWriter sout = new StringWriter (); 38 ObjOut out = new ObjOut(sout); 39 out.writeObject(obj); 40 return sout.toString(); 41 } catch (IOException stringProblem) { 42 stringProblem.printStackTrace(); return null; 44 } 45 } 46 private Util() {} } 48 | Popular Tags |