fork download
  1. import java.util.*;
  2.  
  3.  
  4. class Node {
  5. public LinkedHashSet<String> s = new LinkedHashSet<String>();
  6. public Node(String s) {
  7. this.s.add(s);
  8. }
  9. }
  10.  
  11. class Main {
  12. public static void main(String[] args) {
  13. LinkedHashSet<Node> set1 = new LinkedHashSet<Node>();
  14. set1.add(new Node("waaa"));
  15. set1.add(new Node("wdad"));
  16.  
  17. LinkedHashSet<Node> set2 = new LinkedHashSet<Node>();
  18.  
  19.  
  20. LinkedHashSet<String> newset = new LinkedHashSet<String>();
  21. newset.add("test");
  22. newset.add("bogus");
  23. for(Node n : set2) {
  24. n.s = newset;
  25. break;
  26. }
  27.  
  28. if (compare(set1, set2)) {
  29. System.out.println("Equal");
  30. } else {
  31. System.out.println("Not Equal");
  32. }
  33.  
  34.  
  35. return;
  36. }
  37. private static boolean compare(LinkedHashSet<Node> h1, LinkedHashSet<Node> h2) {
  38. Iterator<Node> h1i = h1.iterator();
  39. Iterator<Node> h2i = h2.iterator();
  40. while (h1i.hasNext()) {
  41. Node n1 = h1i.next();
  42. Node n2 = h2i.next();
  43. if (n1.s.size() != n2.s.size()) {
  44. return false;
  45. } else {
  46. Iterator<String> it1 = n1.s.iterator();
  47. Iterator<String> it2 = n2.s.iterator();
  48. while (it1.hasNext()) {
  49. String t1 = it1.next();
  50. String t2 = it2.next();
  51. if(!t1.equals(t2)) {
  52. return false;
  53. }
  54. }
  55. }
  56. }
  57. return true;
  58. }
  59. }
Runtime error #stdin #stdout 0.07s 216512KB
stdin
Standard input is empty
stdout

Standard output is empty